Skip to content

Commit 013e0dc

Browse files
authored
Merge pull request #194 from WengLab-InformaticsResearch/trapi15
Trapi15
2 parents 17a0a14 + d43bf77 commit 013e0dc

3 files changed

Lines changed: 94 additions & 3 deletions

File tree

cohd/cohd_translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,4 @@ def omop_to_biolink(request):
299299

300300

301301
def api_version():
302-
return CohdTrapi140.tool_version, 200
302+
return CohdTrapi150.tool_version, 200

cohd/cohd_trapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TrapiStatusCode(Enum):
2626
UNSUPPORTED_CONSTRAINT = 'UnsupportedConstraint'
2727
UNSUPPORTED_ATTR_CONSTRAINT = 'UnsupportedAttributeConstraint'
2828
UNSUPPORTED_QUAL_CONSTRAINT = 'UnsupportedQualifierConstraint'
29+
UNSUPPORTED_SET_INTERPRETATION = 'UnsupportedSetInterpretation'
2930

3031

3132
class CohdTrapi(ABC):

cohd/cohd_trapi_15.py

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class CohdTrapi150(CohdTrapi):
2929
supported_edge_types = ['biolink:positively_correlated_with', 'biolink:negatively_correlated_with',
3030
'biolink:has_real_world_evidence_of_association_with']
3131

32+
# QNode set_interpretation values that COHD TRAPI does not support
33+
supported_set_interpretation = ['BATCH']
34+
unsupported_set_interpretation = list(set(['BATCH', 'ALL', 'MANY']) - set(supported_set_interpretation))
35+
3236
# Biolink predicates that request positive associations only
3337
edge_types_positive = ['biolink:positively_correlated_with']
3438
default_positive_predicate = edge_types_positive[0]
@@ -568,8 +572,18 @@ def _interpret_query(self):
568572
self._invalid_query_response = response, 200
569573
return self._valid_query, self._invalid_query_response
570574

575+
# If client specifies unsupported set_interpretation (ALL or MANY), respond with error code
576+
if concept_1_qnode.get('set_interpretation') in CohdTrapi150.unsupported_set_interpretation or \
577+
concept_2_qnode.get('set_interpretation') in CohdTrapi150.unsupported_set_interpretation:
578+
self._valid_query = False
579+
description = f'{CohdTrapi._SERVICE_NAME} only supports QNode set_interpretation of {CohdTrapi150.supported_set_interpretation}'
580+
self.log(description, TrapiStatusCode.UNSUPPORTED_SET_INTERPRETATION, logging.ERROR)
581+
response = self._trapi_mini_response(TrapiStatusCode.UNSUPPORTED_SET_INTERPRETATION, description)
582+
self._invalid_query_response = response, 200
583+
return self._valid_query, self._invalid_query_response
584+
571585
# Check to see if cohd doesn't recognize any properties
572-
qnode_properties = {'ids','categories', 'is_set', 'constraints'}
586+
qnode_properties = {'ids','categories', 'set_interpretation', 'constraints'}
573587
qedge_properties = {'knowledge_type', 'predicates', 'subject', 'object', 'attribute_constraints',
574588
'qualifier_constraints'}
575589
sep = ', '
@@ -1254,6 +1268,9 @@ def _make_kg_node(name: Optional[str] = None, categories: Optional[List[str]] =
12541268
if categories is None:
12551269
categories = list()
12561270

1271+
if attributes is None:
1272+
attributes = list()
1273+
12571274
return {
12581275
'name': name,
12591276
'categories': categories,
@@ -1393,6 +1410,18 @@ def _add_kg_edge(self, node_1, node_2, cohd_result):
13931410
'value_type_id': 'EDAM:data_1048', # Database ID
13941411
'attribute_source': CohdTrapi._INFORES_ID,
13951412
'description': f'Dataset ID within {CohdTrapi._SERVICE_NAME}'
1413+
},
1414+
# Knowledge Level
1415+
{
1416+
'attribute_type_id': 'biolink:knowledge_level',
1417+
'value': 'statistical_association',
1418+
'attribute_source': CohdTrapi._INFORES_ID
1419+
},
1420+
# Agent Type
1421+
{
1422+
'attribute_type_id': 'biolink:agent_type',
1423+
'value': 'computational_model',
1424+
'attribute_source': CohdTrapi._INFORES_ID
13961425
}
13971426
]
13981427
},
@@ -1430,6 +1459,18 @@ def _add_kg_edge(self, node_1, node_2, cohd_result):
14301459
'value_type_id': 'EDAM:data_1048', # Database ID
14311460
'attribute_source': CohdTrapi._INFORES_ID,
14321461
'description': f'Dataset ID within {CohdTrapi._SERVICE_NAME}'
1462+
},
1463+
# Knowledge Level
1464+
{
1465+
'attribute_type_id': 'biolink:knowledge_level',
1466+
'value': 'statistical_association',
1467+
'attribute_source': CohdTrapi._INFORES_ID
1468+
},
1469+
# Agent Type
1470+
{
1471+
'attribute_type_id': 'biolink:agent_type',
1472+
'value': 'computational_model',
1473+
'attribute_source': CohdTrapi._INFORES_ID
14331474
}
14341475
]
14351476
},
@@ -1474,6 +1515,18 @@ def _add_kg_edge(self, node_1, node_2, cohd_result):
14741515
'value_type_id': 'EDAM:data_1048', # Database ID
14751516
'attribute_source': CohdTrapi._INFORES_ID,
14761517
'description': f'Dataset ID within {CohdTrapi._SERVICE_NAME}'
1518+
},
1519+
# Knowledge Level
1520+
{
1521+
'attribute_type_id': 'biolink:knowledge_level',
1522+
'value': 'statistical_association',
1523+
'attribute_source': CohdTrapi._INFORES_ID
1524+
},
1525+
# Agent Type
1526+
{
1527+
'attribute_type_id': 'biolink:agent_type',
1528+
'value': 'computational_model',
1529+
'attribute_source': CohdTrapi._INFORES_ID
14771530
}
14781531
]
14791532
},
@@ -1525,6 +1578,18 @@ def _add_kg_edge(self, node_1, node_2, cohd_result):
15251578
'value_type_id': 'EDAM:data_1048', # Database ID
15261579
'attribute_source': CohdTrapi._INFORES_ID,
15271580
'description': f'Dataset ID within {CohdTrapi._SERVICE_NAME}'
1581+
},
1582+
# Knowledge Level
1583+
{
1584+
'attribute_type_id': 'biolink:knowledge_level',
1585+
'value': 'statistical_association',
1586+
'attribute_source': CohdTrapi._INFORES_ID
1587+
},
1588+
# Agent Type
1589+
{
1590+
'attribute_type_id': 'biolink:agent_type',
1591+
'value': 'computational_model',
1592+
'attribute_source': CohdTrapi._INFORES_ID
15281593
}
15291594
]
15301595
},
@@ -1568,8 +1633,32 @@ def _add_kg_edge(self, node_1, node_2, cohd_result):
15681633
'value_type_id': 'EDAM:data_1048', # Database ID
15691634
'attribute_source': CohdTrapi._INFORES_ID,
15701635
'description': f'Dataset ID within {CohdTrapi._SERVICE_NAME}'
1636+
},
1637+
# Knowledge Level
1638+
{
1639+
'attribute_type_id': 'biolink:knowledge_level',
1640+
'value': 'statistical_association',
1641+
'attribute_source': CohdTrapi._INFORES_ID
1642+
},
1643+
# Agent Type
1644+
{
1645+
'attribute_type_id': 'biolink:agent_type',
1646+
'value': 'computational_model',
1647+
'attribute_source': CohdTrapi._INFORES_ID
15711648
}
15721649
]
1650+
},
1651+
# Knowledge Level
1652+
{
1653+
'attribute_type_id': 'biolink:knowledge_level',
1654+
'value': 'statistical_association',
1655+
'attribute_source': CohdTrapi._INFORES_ID
1656+
},
1657+
# Agent Type
1658+
{
1659+
'attribute_type_id': 'biolink:agent_type',
1660+
'value': 'computational_model',
1661+
'attribute_source': CohdTrapi._INFORES_ID
15731662
}
15741663
]
15751664
# From calculation of chi_square
@@ -1647,7 +1736,8 @@ def _add_kg_edge_subclass_of(self, descendant_node_id, ancestor_node_id):
16471736
'resource_role': 'aggregator_knowledge_source',
16481737
'upstream_resource_ids': [Ubergraph.INFORES_ID]
16491738
},
1650-
]
1739+
],
1740+
'attributes': []
16511741
}
16521742

16531743
def _initialize_trapi_response(self):

0 commit comments

Comments
 (0)