I am using cytoscape pluggin (cypher queries) to visualize neo4j graph db. I am using following query to visualize it. The output shows the 37 nodes and connections but the nodes and connections do not have any labels.
I am using following cypher query:
match (g: Gene) where g.symbol = 'TMPRSS2' or g.symbol='ACE2'
with g
match path=(g)<-[:IS_VARIANT_OF_GENE|DISEASE_ASSOCIATES_GENE]-()
return path
How can I visualize the network with all the labels.
Any help is here highly appreciated
If you want the labels from everything in that path, you could so something like:
MATCH (g:Gene) where g.symbol = 'TMPRSS2' or g.symbol='ACE2'
WITH g
MATCH (g)<-[r:IS_VARIANT_OF_GENE|DISEASE_ASSOCIATES_GENE]-(n)
return g, r, n
That should return you the nodes, relationship, and their properties. I'm not familiar with Cytoscape but without knowing anything about it, that's how I would get the properties back.
Related
I have a highly interconnected graph where starting from a specific node
i want to find all nodes connected to it regardless of the relation type, direction or length. What i am trying to do is to filter out paths that include a node more than 1 times. But what i get is a
Neo.DatabaseError.General.UnknownError: key not found: UNNAMED27
I have managed to create a much simpler database
in neo4j sandbox and get the same message again using the following data:
CREATE (n1:Person { pid:1, name: 'User1'}),
(n2:Person { pid:2, name: 'User2'}),
(n3:Person { pid:3, name: 'User3'}),
(n4:Person { pid:4, name: 'User4'}),
(n5:Person { pid:5, name: 'User5'})
With the following relationships:
MATCH (n1{pid:1}),(n2{pid:2}),(n3{pid:3}),(n4{pid:4}),(n5{pid:5})
CREATE (n1)-[r1:RELATION]->(n2),
(n5)-[r2:RELATION]->(n2),
(n1)-[r3:RELATION]->(n3),
(n4)-[r4:RELATION]->(n3)
The Cypher Query that causes this issue in the above model is
MATCH p= (n:Person{pid:1})-[*0..]-(m)
WHERE ALL(c IN nodes(p) WHERE 1=size(filter(d in nodes(p) where c.pid = d.pid)) )
return m
Can anybody see what is wrong with this query?
The error seems like a bug to me. There is a closed neo4j issue that seems similar, but it was supposed to be fixed in version 3.2.1. You should probably create a new issue for it, since your comments state you are using 3.2.5.
Meanwhile, this query should get the results you seem to want:
MATCH p=(:Person{pid:1})-[*0..]-(m)
WITH m, NODES(p) AS ns
UNWIND ns AS n
WITH m, ns, COUNT(DISTINCT n) AS cns
WHERE SIZE(ns) = cns
return m
You should strongly consider putting a reasonable upper bound on your variable-length path search, though. If you do not do so, then with any reasonable DB size your query is likely to take a very long time and/or run out of memory.
When finding paths, Cypher will never visit the same node twice in a single path. So MATCH (a:Start)-[*]-(b) RETURN DISTINCT b will return all nodes connected to a. (DISTINCT here is redundant, but it can affect query performance. Use PROFILE on your version of Neo4j to see if it cares and which is better)
NOTE: This works starting with Neo4j 3.2 Cypher planner. For previous versions of
the Cypher planner, the only performant way to do this is with APOC, or add a -[:connected_to]-> relation from start node to all children so that path doesn't have to be explored.)
I am trying to query using Neo4j.
I would like to print result of obtaining information while AUTO-COMPLETE is ON in Neo4j.
For example, suppose query that creating 3 nodes as shown below.
create (david:Person {name: 'david'}), (mike:Person {name: 'mike'}), (book:Book {title:'book'}), (david)-[:KNOWS]->(mike), (david)-[:WRITE]->(book), (mike)-[:WRITE]->(book)
Here are 2 images:
Auto-complete on
Auto-complete off
Figure is shown after query, and I would like to obtain all relating node’s relationships based on starting node ('book' node).
I used this query as shown below.
match (book:Book)-[r]-(person) return book, r, person
Whether AUTO-COMPLETE is ON or OFF, I expect to obtain all node’s relationships including “David knows Mike”, but system says otherwise.
I studied a lot of Syntax structure at neo4j website, and somehow it is very difficult for me. So, I upload this post to acquire assistance for you.
You have to return all the data that you need yourself explicitly. It would be bad for Neo4j to automatically return all the relationships for a super node with thousands of relationships for example, as it would mean lots of I/O, possibly for nothing.
MATCH (book:Book)-[r]-(person)-[r2]-()
RETURN book, r, person, collect(r2) AS r2
Thanks to InverseFalcon, this is my query that works.
MATCH p = (book:Book)-[r]-(person:Person)
UNWIND nodes(p) as allnodes WITH COLLECT(ID(allnodes)) AS ALLID
MATCH (a)-[r2]-(b)
WHERE ID(a) IN ALLID AND ID(b) IN ALLID
WITH DISTINCT r2
RETURN startNode(r2), r2, endNode(r2)
I am a newbie to neo4j, and basically I am trying to produce a subgraph from the whole graph according to certain rules. However, my current output does not meet what I want.
Suppose I have four nodes on the graph, which are A, B, C, D, and they are connected as:
A -- B
B -- C
C -- D
Basically I want to acquire a subgraph (or I would say it is two traces), consisting 4 nodes, and two edges:
A -- B
C -- D
However, when I use a Cypher code to query through the neo4j web interface, I always got the whole graph.. That means, I always get a graph with 4 nodes and three edges.
The Cypher query is something like below:
MATCH (n)-[r]-(m) where n.id = "ID_A" and m.id = "ID_B"
UNION
MATCH (n)-[r]-(m) where n.id = "ID_C" and m.id = "ID_D"
To be more specific, for the above query, I wish I can a subgraph with two traces, however, all three edges are shown in the output, connecting these four nodes.
Am I clear? Could anyone give me some help on how to produce the subgraph? Thank you!
It looks like the auto-completion option works. Disable it in the browser interface.
[ http://neo4j.com/developer/guide-neo4j-browser/ ]
I have two datasets in Neo4J. I would like to find all nodes within these two datasets that have the same particular property. This is using Cypher code.
I am currently using:
MATCH n=node(*), m=node(*)
WHERE (n.name) AND (m.name) AND
n.name=m.name
RETURN n, m
In the hope to get a result showing all nodes with the same name.
I am aware of this old 2013 post here: neo4j find all nodes with matching properties
But the Cypher code has been significantly updated since this date.
Any help would be great thanks.
There are no tables in Neo4j
create index on :LabelA(propertyA);
create index on :LabelB(propertyB);
MATCH (a:LabelA)
MATCH (b:LabelB)
WHERE b.propertyB = a.propertyA
RETURN a,b;
What I'm trying to do is simply start at a node and search for all connected nodes that are a certain label. However I don't want to return the start node. How would I do this?
Example:
...<-[:parent]<-anode<-[created]-user-[created]->anode-[:parent]->anode-....->nodes...
What I would like to do is start at the user node and return all relationships but excluding the user node.
This will return you a list of all nodes connected via created relationships of a distance of up to 10.
MATCH user-[:created*1..10]->(anode:CertainLabel)
RETURN DISTINCT anode
Depending on your graph, you may be able to get rid of the 10, but if it's large and complex removing the max value could cause your query to run very slowly
This is along the lines of what I was looking for.
START u = node(26)
MATCH (u)-[rels*1..10]->(node) unwind rels as r
RETURN DISTINCT id(startNode(r)),endNode(r)