Skip to content

Commit

Permalink
Merge branch 'pathfinder-templates' into pathfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Mar 28, 2024
2 parents bd77b6d + f52c0f8 commit d12742e
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 15 deletions.
53 changes: 53 additions & 0 deletions data/templateGroups.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [

]
}
]
2 changes: 1 addition & 1 deletion data/templates/Drug-treats-Disease/Chem-treats-DoP.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"eA": {
"subject": "creativeQuerySubject",
"object": "creativeQueryObject",
"predicates": ["biolink:treats"]
"predicates": ["biolink:treats_or_applied_or_studied_to_treat"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"eA": {
"subject": "creativeQuerySubject",
"object": "nA",
"predicates": ["biolink:treats"]
"predicates": ["biolink:treats_or_applied_or_studied_to_treat"]
},
"eB": {
"subject": "creativeQueryObject",
Expand Down
46 changes: 46 additions & 0 deletions data/templates/Pathfinder/pf-drug-gene-cell-disease.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}
}
40 changes: 40 additions & 0 deletions data/templates/Pathfinder/pf-drug-gene-disease.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}
}
49 changes: 49 additions & 0 deletions data/templates/Pathfinder/pf-drug-gene-physioAndpath-disease.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}
}
24 changes: 16 additions & 8 deletions src/edge_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 3 additions & 5 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit d12742e

Please sign in to comment.