From a0dee66227de876d4a5050fe23d013eefcc382ef Mon Sep 17 00:00:00 2001 From: Eric Zhou Date: Thu, 21 Jul 2022 11:10:26 -0700 Subject: [PATCH 1/5] feat: perform node expansion --- package.json | 1 + src/index.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/package.json b/package.json index 6db6d533..79354994 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ }, "dependencies": { "@biothings-explorer/call-apis": "^1.24.0", + "@biothings-explorer/node-expansion": "^1.0.0", "@biothings-explorer/smartapi-kg": "^4.0.0", "async": "^3.2.1", "biolink-model": "^0.4.0", diff --git a/src/index.js b/src/index.js index 225374e9..79916d63 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ const { getTemplates } = require('./template_lookup'); const utils = require('./utils'); const async = require('async'); const biolink = require('./biolink'); +const { getDescendants } = require('@biothings-explorer/node-expansion'); exports.InvalidQueryGraphError = InvalidQueryGraphError; exports.redisClient = redisClient; @@ -72,6 +73,13 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { } } } + // perform node expansion + if (queryGraph.nodes[nodeId].ids) { + let expanded = Object.values(getDescendants(queryGraph.nodes[nodeId].ids)).flat(); + expanded = _.uniq([...queryGraph.nodes[nodeId].ids, ...expanded]); + debug(`Expanded ids for node ${nodeId}: (${queryGraph.nodes[nodeId].ids.length} ids -> ${expanded.length} ids)`); + queryGraph.nodes[nodeId].ids = expanded; + } } this.queryGraph = queryGraph; } From 8312315579fcb55778c12a6134f2ab628d2eb3f8 Mon Sep 17 00:00:00 2001 From: Eric Zhou Date: Thu, 22 Sep 2022 22:15:10 -0700 Subject: [PATCH 2/5] fix: disable node expansion in creative mode --- src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 79916d63..3cad2120 100644 --- a/src/index.js +++ b/src/index.js @@ -60,6 +60,7 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { * @param {object} queryGraph - TRAPI Query Graph Object */ setQueryGraph(queryGraph) { + this.queryGraph = queryGraph; for (const nodeId in queryGraph.nodes) { if (Object.hasOwnProperty.call(queryGraph.nodes, nodeId)) { const currentNode = queryGraph.nodes[nodeId]; @@ -74,10 +75,13 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { } } // perform node expansion - if (queryGraph.nodes[nodeId].ids) { + if (queryGraph.nodes[nodeId].ids && !this._queryUsesInferredMode()) { let expanded = Object.values(getDescendants(queryGraph.nodes[nodeId].ids)).flat(); + console.log(expanded.length); expanded = _.uniq([...queryGraph.nodes[nodeId].ids, ...expanded]); - debug(`Expanded ids for node ${nodeId}: (${queryGraph.nodes[nodeId].ids.length} ids -> ${expanded.length} ids)`); + let log_msg = `Expanded ids for node ${nodeId}: (${queryGraph.nodes[nodeId].ids.length} ids -> ${expanded.length} ids)`; + debug(log_msg); + this.logs.push(new LogEntry('INFO', null, log_msg).getLog()); queryGraph.nodes[nodeId].ids = expanded; } } From 2e9b52871c5799a490a28d44a1ba935e3d546abb Mon Sep 17 00:00:00 2001 From: Colleen Xu Date: Fri, 4 Nov 2022 22:25:13 -0700 Subject: [PATCH 3/5] adjust templates for automatic ID-expansion --- data/templateGroups.json | 5 +-- .../Chem-DoP.json} | 2 +- .../Chem-subclassDoP-DoP.json | 30 -------------- .../m7-Chem-Pheno-subclassDoP-DoP.json | 39 ------------------- .../m2-Disease-subclassDoP-Gene-Chem.json | 39 ------------------- 5 files changed, 3 insertions(+), 112 deletions(-) rename data/templates/{less-promising/straightforward.json => Drug-treats-Disease/Chem-DoP.json} (87%) delete mode 100644 data/templates/Drug-treats-Disease/Chem-subclassDoP-DoP.json delete mode 100644 data/templates/Drug-treats-Disease/m7-Chem-Pheno-subclassDoP-DoP.json delete mode 100644 data/templates/less-promising/m2-Disease-subclassDoP-Gene-Chem.json diff --git a/data/templateGroups.json b/data/templateGroups.json index 2fb6747a..25b14e8c 100644 --- a/data/templateGroups.json +++ b/data/templateGroups.json @@ -9,10 +9,9 @@ "DiseaseOrPhenotypicFeature" ], "templates": [ - "Chem-subclassDoP-DoP.json", - "m1-Chem-Pheno-DoP.json", + "Chem-DoP.json", "m4-Chem-Gene-DoP.json", - "m7-Chem-Pheno-subclassDoP-DoP.json" + "m1-Chem-Pheno-DoP.json" ] } ] diff --git a/data/templates/less-promising/straightforward.json b/data/templates/Drug-treats-Disease/Chem-DoP.json similarity index 87% rename from data/templates/less-promising/straightforward.json rename to data/templates/Drug-treats-Disease/Chem-DoP.json index 7ed0991e..1bdf23ad 100644 --- a/data/templates/less-promising/straightforward.json +++ b/data/templates/Drug-treats-Disease/Chem-DoP.json @@ -6,7 +6,7 @@ "categories":["biolink:ChemicalEntity"] }, "creativeQueryObject": { - "categories":["biolink:Disease"] + "categories":["biolink:DiseaseOrPhenotypicFeature"] } }, "edges": { diff --git a/data/templates/Drug-treats-Disease/Chem-subclassDoP-DoP.json b/data/templates/Drug-treats-Disease/Chem-subclassDoP-DoP.json deleted file mode 100644 index 276caeae..00000000 --- a/data/templates/Drug-treats-Disease/Chem-subclassDoP-DoP.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "message": { - "query_graph": { - "nodes": { - "creativeQuerySubject": { - "categories":["biolink:ChemicalEntity"] - }, - "nA": { - "categories":["biolink:DiseaseOrPhenotypicFeature"], - "is_set": true - }, - "creativeQueryObject": { - "categories":["biolink:DiseaseOrPhenotypicFeature"] - } - }, - "edges": { - "eA": { - "subject": "creativeQuerySubject", - "object": "nA", - "predicates": ["biolink:treats"] - }, - "eB": { - "subject": "nA", - "object": "creativeQueryObject", - "predicates": ["biolink:subclass_of"] - } - } - } - } -} \ No newline at end of file diff --git a/data/templates/Drug-treats-Disease/m7-Chem-Pheno-subclassDoP-DoP.json b/data/templates/Drug-treats-Disease/m7-Chem-Pheno-subclassDoP-DoP.json deleted file mode 100644 index 261274f2..00000000 --- a/data/templates/Drug-treats-Disease/m7-Chem-Pheno-subclassDoP-DoP.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "message": { - "query_graph": { - "nodes": { - "creativeQuerySubject": { - "categories":["biolink:ChemicalEntity"] - }, - "nA": { - "categories":["biolink:PhenotypicFeature"], - "is_set": true - }, - "nB": { - "categories":["biolink:DiseaseOrPhenotypicFeature"], - "is_set": true - }, - "creativeQueryObject": { - "categories":["biolink:DiseaseOrPhenotypicFeature"] - } - }, - "edges": { - "eA": { - "subject": "creativeQuerySubject", - "object": "nA", - "predicates": ["biolink:treats"] - }, - "eB": { - "subject": "nB", - "object": "nA", - "predicates": ["biolink:has_phenotype"] - }, - "eC": { - "subject": "nB", - "object": "creativeQueryObject", - "predicates": ["biolink:subclass_of"] - } - } - } - } -} \ No newline at end of file diff --git a/data/templates/less-promising/m2-Disease-subclassDoP-Gene-Chem.json b/data/templates/less-promising/m2-Disease-subclassDoP-Gene-Chem.json deleted file mode 100644 index 484c5408..00000000 --- a/data/templates/less-promising/m2-Disease-subclassDoP-Gene-Chem.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "message": { - "query_graph": { - "nodes": { - "creativeQueryObject": { - "categories":["biolink:Disease"] - }, - "nA": { - "categories":["biolink:DiseaseOrPhenotypicFeature"], - "is_set": true - }, - "nB": { - "categories":["biolink:Gene"], - "is_set": true - }, - "creativeQuerySubject": { - "categories":["biolink:ChemicalEntity"] - } - }, - "edges": { - "eA": { - "subject": "creativeQueryObject", - "object": "nA", - "predicates": ["biolink:superclass_of"] - }, - "eB": { - "subject": "nA", - "object": "nB", - "predicates": ["biolink:caused_by"] - }, - "eC": { - "subject": "nB", - "object": "creativeQuerySubject", - "predicates": ["biolink:entity_regulated_by_entity"] - } - } - } - } -} \ No newline at end of file From b800caec930883db84a8b98854d13c3c88c63887 Mon Sep 17 00:00:00 2001 From: Eric Zhou Date: Sat, 12 Nov 2022 22:26:31 -0800 Subject: [PATCH 4/5] fix: add is_set property to each expanded node --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index cbecac0f..18afec44 100644 --- a/src/index.js +++ b/src/index.js @@ -88,10 +88,14 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { let expanded = Object.values(getDescendants(queryGraph.nodes[nodeId].ids)).flat(); console.log(expanded.length); expanded = _.uniq([...queryGraph.nodes[nodeId].ids, ...expanded]); + queryGraph.nodes[nodeId].ids = expanded; + let log_msg = `Expanded ids for node ${nodeId}: (${queryGraph.nodes[nodeId].ids.length} ids -> ${expanded.length} ids)`; debug(log_msg); this.logs.push(new LogEntry('INFO', null, log_msg).getLog()); - queryGraph.nodes[nodeId].ids = expanded; + + queryGraph.nodes[nodeId].is_set = true; + } } } From a5431b3daf60c2a1368936a718e01eab746535f8 Mon Sep 17 00:00:00 2001 From: Eric Zhou Date: Sat, 12 Nov 2022 22:41:41 -0800 Subject: [PATCH 5/5] fix: add logs for node expansion is_set --- src/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 18afec44..b21d7a0d 100644 --- a/src/index.js +++ b/src/index.js @@ -88,13 +88,20 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler { let expanded = Object.values(getDescendants(queryGraph.nodes[nodeId].ids)).flat(); console.log(expanded.length); expanded = _.uniq([...queryGraph.nodes[nodeId].ids, ...expanded]); - queryGraph.nodes[nodeId].ids = expanded; let log_msg = `Expanded ids for node ${nodeId}: (${queryGraph.nodes[nodeId].ids.length} ids -> ${expanded.length} ids)`; debug(log_msg); this.logs.push(new LogEntry('INFO', null, log_msg).getLog()); + + queryGraph.nodes[nodeId].ids = expanded; - queryGraph.nodes[nodeId].is_set = true; + //make sure is_set is true + if (!queryGraph.nodes[nodeId].hasOwnProperty('is_set') || !queryGraph.nodes[nodeId].is_set) { + queryGraph.nodes[nodeId].is_set = true; + log_msg = `Added is_set:true to node ${nodeId}`; + debug(log_msg); + this.logs.push(new LogEntry('INFO', null, log_msg).getLog()); + } } }