Skip to content

Commit

Permalink
Merge pull request #113 from biothings/node-expansion
Browse files Browse the repository at this point in the history
feat: perform node expansion
  • Loading branch information
tokebe authored Jan 4, 2023
2 parents add1e58 + 85d434a commit 98d9f10
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 112 deletions.
5 changes: 2 additions & 3 deletions data/templateGroups.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"categories":["biolink:ChemicalEntity"]
},
"creativeQueryObject": {
"categories":["biolink:Disease"]
"categories":["biolink:DiseaseOrPhenotypicFeature"]
}
},
"edges": {
Expand Down
30 changes: 0 additions & 30 deletions data/templates/Drug-treats-Disease/Chem-subclassDoP-DoP.json

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const LogEntry = require('./log_entry');
const { redisClient } = require('./redis-client');
const config = require('./config');
const fs = require('fs').promises;
const { getDescendants } = require('@biothings-explorer/node-expansion');
const { getTemplates, supportedLookups } = require('./inferred_mode/template_lookup');
const handleInferredMode = require('./inferred_mode/inferred_mode');
const id_resolver = require('biomedical_id_resolver');
Expand Down Expand Up @@ -81,6 +82,29 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler {
*/
setQueryGraph(queryGraph) {
this.queryGraph = queryGraph;
for (const nodeId in queryGraph.nodes) {
// perform node expansion
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]);

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;

//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());
}

}
}
}

_initializeResponse() {
Expand Down

0 comments on commit 98d9f10

Please sign in to comment.