diff --git a/data/templateGroups.json b/data/templateGroups.json index 3df3fd2e..afb5409c 100644 --- a/data/templateGroups.json +++ b/data/templateGroups.json @@ -51,5 +51,58 @@ "Chem-physically_interacts-GeneThatDownregs-Gene.json", "Chem-physically_interacts-Gene.json" ] + }, + { + "name": "Pathfinder: Drug-Disease", + "pathfinder": true, + "subject": ["Drug", "SmallMolecule", + "ChemicalEntity", "ComplexMolecularMixture", "MolecularMixture" + ], + "predicate": ["related_to"], + "object": ["Disease", "PhenotypicFeature", + "DiseaseOrPhenotypicFeature" + ], + "templates": [ + "pf-drug-gene-disease.json", + "pf-drug-gene-cell-disease.json", + "pf-drug-gene-physioAndpath-disease.json" + ] + }, + { + "name": "Pathfinder: Chem-Gene", + "subject": ["Drug", "SmallMolecule", + "ChemicalEntity", "ComplexMolecularMixture", "MolecularMixture" + ], + "predicate": ["related_to"], + "object": ["Gene", "Protein"], + "templates": [ + + ] + }, + { + "name": "Pathfinder: Disease-Disease", + "pathfinder": true, + "subject": ["Disease", "PhenotypicFeature", + "DiseaseOrPhenotypicFeature" + ], + "predicate": ["related_to"], + "object": ["Disease", "PhenotypicFeature", + "DiseaseOrPhenotypicFeature" + ], + "templates": [ + + ] + }, + { + "name": "Pathfinder: Gene-Disease", + "pathfinder": true, + "subject": ["Gene", "Protein"], + "predicate": ["related_to"], + "object": ["Disease", "PhenotypicFeature", + "DiseaseOrPhenotypicFeature" + ], + "templates": [ + + ] } ] diff --git a/data/templates/Drug-treats-Disease/Chem-treats-DoP.json b/data/templates/Drug-treats-Disease/Chem-treats-DoP.json index 1bdf23ad..663d467b 100644 --- a/data/templates/Drug-treats-Disease/Chem-treats-DoP.json +++ b/data/templates/Drug-treats-Disease/Chem-treats-DoP.json @@ -13,7 +13,7 @@ "eA": { "subject": "creativeQuerySubject", "object": "creativeQueryObject", - "predicates": ["biolink:treats"] + "predicates": ["biolink:treats_or_applied_or_studied_to_treat"] } } } diff --git a/data/templates/Drug-treats-Disease/Chem-treats-PhenoOfDisease.json b/data/templates/Drug-treats-Disease/Chem-treats-PhenoOfDisease.json index a8f23fc1..e54787f1 100644 --- a/data/templates/Drug-treats-Disease/Chem-treats-PhenoOfDisease.json +++ b/data/templates/Drug-treats-Disease/Chem-treats-PhenoOfDisease.json @@ -17,7 +17,7 @@ "eA": { "subject": "creativeQuerySubject", "object": "nA", - "predicates": ["biolink:treats"] + "predicates": ["biolink:treats_or_applied_or_studied_to_treat"] }, "eB": { "subject": "creativeQueryObject", diff --git a/data/templates/Pathfinder/pf-drug-gene-cell-disease.json b/data/templates/Pathfinder/pf-drug-gene-cell-disease.json new file mode 100644 index 00000000..c54e10d0 --- /dev/null +++ b/data/templates/Pathfinder/pf-drug-gene-cell-disease.json @@ -0,0 +1,46 @@ +{ + "message": { + "query_graph": { + "nodes": { + "creativeQuerySubject": { + "categories":["biolink:ChemicalEntity"] + }, + "nA": { + "categories":["biolink:Gene"] + }, + "nB": { + "categories":["biolink:Cell"] + }, + "creativeQueryObject": { + "categories":["biolink:DiseaseOrPhenotypicFeature"] + } + }, + "edges": { + "eA": { + "subject": "creativeQuerySubject", + "object": "nA", + "predicates": [ + "biolink:regulates", + "biolink:affects", + "biolink:interacts_with", + "biolink:associated_with" + ] + }, + "eB": { + "subject": "nA", + "object": "nB", + "predicates": [ + "biolink:related_to_at_instance_level" + ] + }, + "eC": { + "subject": "nB", + "object": "creativeQueryObject", + "predicates": [ + "biolink:related_to_at_instance_level" + ] + } + } + } + } +} \ No newline at end of file diff --git a/data/templates/Pathfinder/pf-drug-gene-disease.json b/data/templates/Pathfinder/pf-drug-gene-disease.json new file mode 100644 index 00000000..e5032697 --- /dev/null +++ b/data/templates/Pathfinder/pf-drug-gene-disease.json @@ -0,0 +1,40 @@ +{ + "message": { + "query_graph": { + "nodes": { + "creativeQuerySubject": { + "categories":["biolink:ChemicalEntity"] + }, + "nA": { + "categories":["biolink:Gene"] + }, + "creativeQueryObject": { + "categories":["biolink:DiseaseOrPhenotypicFeature"] + } + }, + "edges": { + "eA": { + "subject": "creativeQuerySubject", + "object": "nA", + "predicates": [ + "biolink:regulates", + "biolink:affects", + "biolink:interacts_with", + "biolink:associated_with" + ] + }, + "eB": { + "subject": "nA", + "object": "creativeQueryObject", + "predicates": [ + "biolink:gene_associated_with_condition", + "biolink:biomarker_for", + "biolink:affects", + "biolink:causes", + "biolink:contributes_to" + ] + } + } + } + } +} \ No newline at end of file diff --git a/data/templates/Pathfinder/pf-drug-gene-physioAndpath-disease.json b/data/templates/Pathfinder/pf-drug-gene-physioAndpath-disease.json new file mode 100644 index 00000000..5e738321 --- /dev/null +++ b/data/templates/Pathfinder/pf-drug-gene-physioAndpath-disease.json @@ -0,0 +1,49 @@ +{ + "message": { + "query_graph": { + "nodes": { + "creativeQuerySubject": { + "categories":["biolink:ChemicalEntity"] + }, + "nA": { + "categories":["biolink:Gene"] + }, + "nB": { + "categories":["biolink:PhysiologicalProcess", "biolink:Pathway"] + }, + "creativeQueryObject": { + "categories":["biolink:DiseaseOrPhenotypicFeature"] + } + }, + "edges": { + "eA": { + "subject": "creativeQuerySubject", + "object": "nA", + "predicates": [ + "biolink:regulates", + "biolink:affects", + "biolink:interacts_with", + "biolink:associated_with" + ] + }, + "eB": { + "subject": "nA", + "object": "nB", + "predicates": [ + "biolink:affects", + "biolink:contributes_to" + ] + }, + "eC": { + "subject": "nB", + "object": "creativeQueryObject", + "predicates": [ + "biolink:affects", + "biolink:affected_by", + "biolink:occurs_in" + ] + } + } + } + } +} \ No newline at end of file diff --git a/src/edge_manager.ts b/src/edge_manager.ts index 145e415c..d62db752 100644 --- a/src/edge_manager.ts +++ b/src/edge_manager.ts @@ -231,7 +231,7 @@ export default class QueryEdgeManager { return keep; } - collectRecords(): void { + collectRecords(): boolean { //go through edges and collect records organized by edge let recordsByQEdgeID: RecordsByQEdgeID = {}; //all res merged @@ -268,12 +268,10 @@ export default class QueryEdgeManager { new LogEntry( 'WARNING', null, - `qEdges ${JSON.stringify(brokenEdges)} ` + `resulted in (0) records. No complete paths can be formed.`, + `qEdges ${brokenEdges} resulted in (0) records. No complete paths can be formed.`, ).getLog(), ); - debug( - `(12) qEdges ${JSON.stringify(brokenEdges)} ` + `resulted in (0) records. No complete paths can be formed.`, - ); + debug(`(12) qEdges ${brokenEdges} resulted in (0) records. No complete paths can be formed.`); } //Organized by edge: update query records this._organizedRecords = recordsByQEdgeID; @@ -289,8 +287,12 @@ export default class QueryEdgeManager { // console.log(err); // } // }); - debug(`(12) Collected (${this._records.length}) records!`); - this.logs.push(new LogEntry('DEBUG', null, `Edge manager collected (${this._records.length}) records!`).getLog()); + if (!brokenChain) { + debug(`(12) Collected (${this._records.length}) records!`); + this.logs.push(new LogEntry('DEBUG', null, `Edge manager collected (${this._records.length}) records!`).getLog()); + } + + return !brokenChain; } updateEdgeRecords(currentQEdge: QEdge): void { @@ -474,7 +476,13 @@ export default class QueryEdgeManager { } this._logSkippedQueries(unavailableAPIs); // collect and organize records - this.collectRecords(); + if (!this.collectRecords()) { + debug(`(X) Terminating...No complete paths.`); + this.logs.push( + new LogEntry('WARNING', null, `No complete paths could be formed. Your query terminates.`).getLog(), + ); + return; + } // dump records if set to do so if (process.env.DUMP_RECORDS) { await this.dumpRecords(this.getRecords()); diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index 8911990f..6b05d583 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -110,11 +110,9 @@ export default class InferredQueryHandler { return false; } - const tooManyIDs = - 1 < - Object.values(this.queryGraph.nodes).reduce((sum, node) => { - return typeof node.ids !== 'undefined' ? sum + node.ids.length : sum; - }, 0); + const tooManyIDs = Object.values(this.queryGraph.nodes).some((node) => { + return typeof node.ids !== 'undefined' && node.ids.length > 1; + }); if (tooManyIDs && !this.pathfinder) { const message = 'Inferred Mode queries with multiple IDs are not supported. Your query terminates.'; this.logs.push(new LogEntry('WARNING', null, message).getLog());