Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-25-2022 10:14 AM
Application visualizes drug-drug interactions. Drug names are in node Names. Some drugs are members of classes (one and only one). Class is in node DrugClass, related to the drugs in Names by relationship DRUG_CLASS. Interactions between drugs are in relationship INTERACTION, between two nodes in Names. Not really much to the database structure, although a few million rows of drug-drug interactions, and a few thousand drugs.
This query works just the way it should, retrieving a graph of interactions of Levothyroxine with the drugs in the list of classes:
Solved! Go to Solution.
09-26-2022 06:18 PM
I think this should give you the drugs that interact with the Levothyroxine and are in the specified drug classes. Do you really need d1, rd, and ri (in your original query)?
WITH ['CCBnonDihydropyridines','Statins','AngiotensinIIreceptorBlockers'] as drugClasses
MATCH (n2:Names{name: 'Levothyroxine'})
MATCH (d1:DrugClass)-[rd:DRUG_CLASS]->(n1:Names)
WHERE d1.drugClass IN drugClasses
WITH n1, n2, {DrugClass: d1, DRUG_CLASS: rd} as drugClassInfo
WHERE EXISTS ((n1)<-[:INTERACTION]-(n2))
RETURN n1, drugClassInfo
This modified version, should give you the opposite, which is the drugs that do not interact with Levothyroxine and are in the specified drug classes:
WITH ['CCBnonDihydropyridines','Statins','AngiotensinIIreceptorBlockers'] as drugClasses
MATCH (n2:Names{name: 'Levothyroxine'})
MATCH (d1:DrugClass)-[rd:DRUG_CLASS]->(n1:Names)
WHERE d1.drugClass IN drugClasses
WITH n1, n2, {DrugClass: d1, DRUG_CLASS: rd} as drugClassInfo
WHERE NOT EXISTS ((n1)<-[:INTERACTION]-(n2))
RETURN n1, drugClassInfo
09-25-2022 10:36 PM
Try this:
//Collect all drugs in the selected drug classes.....
MATCH (d1:DrugClass)-[rd:DRUG_CLASS]->(n1:Names)
WHERE d1.drugClass IN ['CCBnonDihydropyridines','Statins','AngiotensinIIreceptorBlockers']
WITH d1, COLLECT(distinct n1.name) as drugs
//Get the drugs that interact with Levothyroxine....
MATCH (n1:Names)<-[ri:INTERACTION]-(n2:Names)
WHERE n1.name in drugs AND n2.name='Levothyroxine'
//Get the drugs that do not inteact with Levothyroxine....
MATCH (n1:Names)<-[ri:INTERACTION]-(n2:Names)
WHERE n1.name in drugs AND n2.name <>'Levothyroxine'
//Result........
RETURN distinct n1.name
09-26-2022 10:45 AM
Hi ameyasoft, thank you very much for your time and effort. I think your method is not quite correct. The 'get drugs not interacting with' returns all the interactions amongst all the 'drugs', which is a superset based on 'drugs'. Your method is an improvement over my attempts.
I think your first step is on target, returning all the drugs in the named classes. Next should be your correct second step. But the correct third step would be the (list) difference between what was returned by the first and second step. So you are 2/3 of the way there. I can handle that via python (py2neo) and I am sure there is a way in native neo4j (for instance, APOC provides for list differences). My particular problem is that I don't see how to 'remember' the returns from steps 1 and 2 unless I use python. Have you got the time to help me with this?
09-26-2022 04:03 PM - edited 09-26-2022 04:05 PM
Try this:
//Get the drugs that interact with Levothyroxine....
MATCH (n1:Names)<-[ri:INTERACTION]-(n2:Names)
WHERE n1.name in drugs AND n2.name='Levothyroxine'
WITH drugs, COLLECT(distinct n1.name) as levo
// Subtract the drugs interacted with levo......get non-interacting drugs....
WITH drug, apoc.coll.subtract(drug, levo) as nolevo
RETURN drug, nolevo, size(nolevo) as cnt
09-27-2022 12:52 PM
My sincere thanks. I think the glilienfield solution is simpler.
I am delighted to see the neo4j community respond with such help.
09-26-2022 06:18 PM
I think this should give you the drugs that interact with the Levothyroxine and are in the specified drug classes. Do you really need d1, rd, and ri (in your original query)?
WITH ['CCBnonDihydropyridines','Statins','AngiotensinIIreceptorBlockers'] as drugClasses
MATCH (n2:Names{name: 'Levothyroxine'})
MATCH (d1:DrugClass)-[rd:DRUG_CLASS]->(n1:Names)
WHERE d1.drugClass IN drugClasses
WITH n1, n2, {DrugClass: d1, DRUG_CLASS: rd} as drugClassInfo
WHERE EXISTS ((n1)<-[:INTERACTION]-(n2))
RETURN n1, drugClassInfo
This modified version, should give you the opposite, which is the drugs that do not interact with Levothyroxine and are in the specified drug classes:
WITH ['CCBnonDihydropyridines','Statins','AngiotensinIIreceptorBlockers'] as drugClasses
MATCH (n2:Names{name: 'Levothyroxine'})
MATCH (d1:DrugClass)-[rd:DRUG_CLASS]->(n1:Names)
WHERE d1.drugClass IN drugClasses
WITH n1, n2, {DrugClass: d1, DRUG_CLASS: rd} as drugClassInfo
WHERE NOT EXISTS ((n1)<-[:INTERACTION]-(n2))
RETURN n1, drugClassInfo
09-27-2022 12:54 PM
I never even thought of starting with WITH! A real eye-opener.
Thank you very much.
All the sessions of the conference are now available online