-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide query to frontend to retrieve path/graph data from neo4j #31
Comments
Can you give me an example neo4j query? Wouldn't it be faster if the frontend queries neo4j and handles the responses directly since the frontend is hosted on github but the search-api backend is hosted on AWS? The extra hop from frontend to search-api backend seems redundant to me. |
the backend will need to generate the query. The query will be like (generated mostly by this MATCH path = (n0:Compound)-[:BINDS_CbG]-(n1)-[:PARTICIPATES_GpPW]-(n2)-[:PARTICIPATES_GpPW]-(n3)-[:ASSOCIATES_DaG]-(n4:Disease)
USING JOIN ON n2
WHERE n0.identifier = 'DB01156' // Bupropion
AND n4.identifier = 'DOID:0050742' // nicotine dependency
AND n1 <> n3
WITH
[
size((n0)-[:BINDS_CbG]-()),
size(()-[:BINDS_CbG]-(n1)),
size((n1)-[:PARTICIPATES_GpPW]-()),
size(()-[:PARTICIPATES_GpPW]-(n2)),
size((n2)-[:PARTICIPATES_GpPW]-()),
size(()-[:PARTICIPATES_GpPW]-(n3)),
size((n3)-[:ASSOCIATES_DaG]-()),
size(()-[:ASSOCIATES_DaG]-(n4))
] AS degrees, path
WITH path, reduce(pdp = 1.0, d in degrees| pdp * d ^ -0.5) AS PDP
WITH collect({paths: path, PDPs: PDP}) AS data_maps, sum(PDP) AS DWPC
UNWIND data_maps AS data_map
WITH data_map.paths AS path, data_map.PDPs AS PDP, DWPC
RETURN
path,
substring(reduce(s = '', node IN nodes(path)| s + '–' + node.name), 1) AS str_path,
PDP,
100 * (PDP / DWPC) AS percent_of_DWPC
ORDER BY percent_of_DWPC DESC
LIMIT 10 That is for the CbGpPWpGaD metapath between Buproprion and epilepsy syndrome. Run this query at https://neo4j.het.io/browser/ to see what Neo4j will output. |
@dhimmel and I are working on Cypher to return data for the path table. Here are two lines to provide a list of neo4j node and relationship ids: extract(node IN nodes(path) | id(node)) AS node_ids,
extract(rel IN relationships(path) | id(rel)) AS rel_ids, |
Here is a template query for returning the data for a list of neo4j node ids:
And here is a template for the neo4j rel ids:
@vincerubinetti I think it's possible this node / rel lookup could happen entirely on the frontend. However, we could also do it on the backend and require a bit less post-processing. |
Refs greenelab/connectivity-search-backend#31 (comment) Also switchs to neo4j cypher list comprehension
Merge #36 Refs greenelab/connectivity-search-backend#31 (comment) Also switchs to neo4j cypher list comprehension
I'm thinking the paths backend endpoint will return something like: {
"query": {
"source": "DB01156",
"target": "DOID:0050742",
"metapath": "CbGiGaD",
"metapath_id": [
[
"Compound",
"Gene",
"binds",
"both"
],
[
"Gene",
"Gene",
"interacts",
"both"
],
[
"Gene",
"Disease",
"associates",
"both"
]
]
},
"paths": [
{
"metapath": "CbGiGaD",
"node_ids": [
43315,
32786,
41662,
1410
],
"rel_ids": [
1923805,
1615085,
309879
],
"PDP": 0.004682929057908469,
"percent_of_DWPC": 95.77866787048912
},
{
"metapath": "CbGiGaD",
"node_ids": [
43315,
44251,
28797,
1410
],
"rel_ids": [
309501,
95988,
159590
],
"PDP": 0.00020639459006779496,
"percent_of_DWPC": 4.221332129510869
}
]
} |
The front-end will need to query the neo4j database to get the data needed to draw a graph representation of metapaths/paths. Apparently this query is fairly complex and also would be more appropriately generated by the backend.
The backend could either give the frontend the query, or perhaps do the query and return the results to the frontend.
Info on the neo4j data format:
https://github.com/eisman/neo4jd3#neo4j-data-format
The text was updated successfully, but these errors were encountered: