Closed andrewsu closed 3 years ago
In TRAPI 1.1, message.query_graph
is of type QueryGraph
(link) which has properties for nodes (of type QNode
) and edges (of type QEdge
). Both QNode
s and QEdge
s allows the specification of a constraint
property (of type QueryConstraint
link). The constraint described above (filter for FDA-approved drugs) would look like this (taken from https://github.com/NCATSTranslator/minihackathons/blob/main/2021-12_demo/workflowA/EGFR_advanced.json and referenced in https://github.com/NCATSTranslator/minihackathons/issues/164):
{
"message": {
"query_graph": {
"nodes": {
"n0": {
"categories": [
"biolink:ChemicalSubstance"
],
"name": "Chemical Substance",
"constraints": [
{
"id": "biolink:highest_FDA_approval_status",
"name": "highest FDA approval status",
"operator": "==",
"value": "regular approval"
}
]
},
"n1": {
"name": "EGFR",
"ids": [
"NCBIGene:1956"
]
}
},
"edges": {
"e0": {
"subject": "n0",
"object": "n1",
"predicates": [
"biolink:decreases_abundance_of",
"biolink:decreases_activity_of",
"biolink:decreases_expression_of",
"biolink:decreases_synthesis_of",
"biolink:increases_degradation_of",
"biolink:disrupts",
"biolink:entity_negatively_regulates_entity"
]
}
}
}
}
}
Based on that, it appears we need to change bts:chembl_max_phase
to biolink:highest_FDA_approval_status
in our smartAPI mapping file?
update for TRAPI v1.2. I think the query constraints work the same as specified above. I updated the query below (maybe use SmallMolecule or ChemicalEntity?):
{
"message": {
"query_graph": {
"nodes": {
"n0": {
"categories": [
"biolink:ChemicalEntity"
],
"constraints": [
{
"id": "biolink:highest_FDA_approval_status",
"name": "highest FDA approval status",
"operator": "==",
"value": "regular approval"
}
]
},
"n1": {
"categories": [
"biolink:Gene"
],
"ids": [
"NCBIGene:1956"
]
}
},
"edges": {
"e0": {
"subject": "n0",
"object": "n1"
}
}
}
}
}
This is dependent on #302 and its PRs. I think it's addressed by this PR: https://github.com/biothings/bte_trapi_query_graph_handler/pull/45
@marcodarko some feedback on https://github.com/biothings/bte_trapi_query_graph_handler/pull/45:
I only took a quick look based on this query, which worked as-expected compared to its unconstrained version:
Also, there is some complicated and unclear behavior in the specification regarding the operators and values...I think this involves some discussion with @andrewsu...
For now, let's only deal with single-value constraints. We also need to deal with mismatch between chembl.max_phase
in mychem.info and FDA_approval_status_enum
at https://github.com/biolink/biolink-model/blob/master/biolink-model.yaml#L239. So instead of the example query posted immediately above, for now, test on this (replacing "regular approval" with "4"):
{
"message": {
"query_graph": {
"edges": {
"e01": {
"object": "n0",
"subject": "n1",
"predicates": [
"biolink:entity_regulates_entity",
"biolink:genetically_interacts_with"
]
},
"e02": {
"object": "n1",
"subject": "n2",
"predicates": [
"biolink:related_to"
]
}
},
"nodes": {
"n0": {
"ids": [
"NCBIGene:23221"
],
"categories": [
"biolink:Gene"
]
},
"n1": {
"categories": [
"biolink:Gene"
]
},
"n2": {
"categories": [
"biolink:SmallMolecule"
] ,
"constraints": [
{
"id": "biolink:highest_FDA_approval_status",
"name": "highest FDA approval status",
"operator": "==",
"value": "4"
}
]
}
}
}
}
}
Note that the following queries are working as-expected. However, I am currently using a local environ that excludes all pending biothings APIs except clinical risk kp api / multiomics wellness api...
With the removal of pending apis, we currently cannot do the following query (no metaKG edges to do the operation with negatively regulates...
@marcodarko note that we may want to change the node attribute name from biolink:"highest_FDA_approval_status" to "biolink:"drug_regulatory_status_world_wide".
@andrewsu please confirm whether we want to make this change or not...
@marcodarko also FYI the discussion here https://github.com/NCATSTranslator/ReasonerAPI/issues/298. It's difficult to know how to implement constraints when the node attribute's value is actually a list (not an int or string)....which is the case for most of the node attributes described above.
@marcodarko note that we may want to change the node attribute name from biolink:"highest_FDA_approval_status" to "biolink:"drug_regulatory_status_world_wide".
@andrewsu please confirm whether we want to make this change or not...
Yes, the mapping of chembl.max_phase
should now go to biolink:drug_regulatory_status_world_wide
Just tried again with a full api list and the following queries ran and looked like they worked compared to the queries without the constraint:
@colleenXu @andrewsu great thank you both, I'll update the PRs
Updating the queries to use biolink:drug_regulatory_status_world_wide
:
With the removal of pending apis, we currently cannot do the following query (no metaKG edges to do the operation with negatively regulates...
Closing because it's been deployed on prod.
Next steps are @andrewsu discussing whether the demo queries can use our node constraint modifications: https://github.com/biothings/BioThings_Explorer_TRAPI/issues/174#issuecomment-954972343
noting that only == was implemented (so I can't do <= or >=)... #380
I'm not sure if this is still working...the following query is hitting a TypeError:
Query:
{
"message": {
"query_graph": {
"nodes": {
"disease": {
"ids":["MONDO:0004975"],
"categories":["biolink:Disease"],
"names": "Alzheimers"
},
"nA": {
"categories":["biolink:PhenotypicFeature"]
},
"drug": {
"categories":["biolink:ChemicalEntity"],
"constraints": [
{
"id": "biolink:drug_regulatory_status_world_wide",
"name": "max phase",
"operator": "==",
"value": 2
}
]
}
},
"edges": {
"eA": {
"subject": "disease",
"object": "nA",
"predicates": ["biolink:has_phenotype"]
},
"eB": {
"subject": "nA",
"object": "drug",
"predicates": ["biolink:treated_by"]
}
}
}
}
}
Console logs:
bte:call-apis:query id annotation completes +3s
bte:call-apis:query qEdge queries complete in 6s +0ms
bte:biothings-explorer-trapi:batch_edge_query APIEdges are successfully queried.... +9s
bte:biothings-explorer-trapi:batch_edge_query Filtering out any "undefined" items in (1555) records +0ms
bte:biothings-explorer-trapi:batch_edge_query Total number of records is (1496) +0ms
bte:biothings-explorer-trapi:batch_edge_query Start to update nodes... +0ms
bte:biothings-explorer-trapi:batch_edge_query Update nodes completed! +0ms
bte:biothings-explorer-trapi:QueryExecutionEdge (6) Storing records... +9s
bte:biothings-explorer-trapi:QueryExecutionEdge (6) Applying Node Constraints to 1496 records. +0ms
bte:biothings-explorer-trapi:QueryExecutionEdge Node (object) constraints: [{"id":"biolink:drug_regulatory_status_world_wide","name":"max phase","operator":"==","value":2}] +0ms
bte:biothings-explorer-trapi:error_handler TypeError: Cannot read properties of undefined (reading '0')
bte:biothings-explorer-trapi:error_handler at QueryExecutionEdge.meetsConstraint (/Users/colleenxu/Desktop/bte-trapi-workspace/packages/@biothings-explorer/query_graph_handler/built/query_execution_edge.js:294:43)
bte:biothings-explorer-trapi:error_handler at QueryExecutionEdge.applyNodeConstraints (/Users/colleenxu/Desktop/bte-trapi-workspace/packages/@biothings-explorer/query_graph_handler/built/query_execution_edge.js:274:33)
bte:biothings-explorer-trapi:error_handler at QueryExecutionEdge.storeRecords (/Users/colleenxu/Desktop/bte-trapi-workspace/packages/@biothings-explorer/query_graph_handler/built/query_execution_edge.js:426:14)
bte:biothings-explorer-trapi:error_handler at TRAPIQueryHandler.query (/Users/colleenxu/Desktop/bte-trapi-workspace/packages/@biothings-explorer/query_graph_handler/built/index.js:245:27)
bte:biothings-explorer-trapi:error_handler at runMicrotasks (<anonymous>)
bte:biothings-explorer-trapi:error_handler at processTicksAndRejections (node:internal/process/task_queues:96:5)
bte:biothings-explorer-trapi:error_handler at async task (/Users/colleenxu/Desktop/bte-trapi-workspace/packages/@biothings-explorer/bte-trapi/src/routes/v1/query_v1.js:34:13)
bte:biothings-explorer-trapi:error_handler at async /Users/colleenxu/Desktop/bte-trapi-workspace/packages/@biothings-explorer/bte-trapi/src/controllers/threading/threadHandler.js:93:38 +3m
Node attributes on chemical compounds indicate drug approval status. Clearly we could filter based on these attributes post-query, and a helper tool to do this may be quite useful in the short term. But it would also be good to allow filtering on these node attributes as part of the query. Filters would presumably be based on EITHER the value of a certain attribute OR the existence of an attribute.
More details
This query gives all compounds related to SLC2A1 / GLUT1 (Updated to TRAPI v1.1 2021-06-08):
one of the results is pasted below -- several attributes seem to indicate FDA approval status, including
chembl_max_phase
,drugbank_groups
,fda_epc_pharmacology_class