Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute mapping from node to dug element #203

Merged
merged 6 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/dug/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ class Config:
# Dug element type to cast the query kg nodes to
"cde": {
# Parse nodes matching criteria in kg
"node_type": "biolink:Publication"
"node_type": "biolink:Publication",
"curie_prefix": "HEALCDE",
"attribute_mapping": {
# "DugElement Attribute" : "KG Node attribute"
"name": "name",
"desc": "summary",
"collection_name": "cde_category",
"collection_id": "cde_category"
}
}
})

Expand Down
22 changes: 12 additions & 10 deletions src/dug/core/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def expand_to_dug_element(self,
elements = []
# using node_type as the primary criteria for matching nodes to element type.
target_node_type = casting_config["node_type"]
curie_filter = casting_config["curie_prefix"]
attribute_mapping = casting_config["attribute_mapping"]
target_node_type_snake_case = biolink_snake_case(target_node_type.replace("biolink:", ""))
for ident_id, identifier in concept.identifiers.items():

Expand Down Expand Up @@ -244,14 +246,14 @@ def expand_to_dug_element(self,
# and return the variables.
for node_id, node in answer.nodes.items():
if target_node_type in node["category"]:
# @TODO make element creation more generic
# @TODO need to encode more data into the graph nodes, to parse them properly
element = DugElement(
elem_id=node_id,
name=node.get('name', ""),
desc=node.get('summary', ""),
elem_type=dug_element_type
)
element.add_concept(concept)
elements.append(element)
if node['id'].startswith(curie_filter):
element_attribute_args = {"elem_id": node_id, "elem_type": dug_element_type}
element_attribute_args.update({key: node.get(attribute_mapping[key], "")
for key in attribute_mapping
})
element = DugElement(
**element_attribute_args
)
element.add_concept(concept)
elements.append(element)
return elements
4 changes: 3 additions & 1 deletion src/dug/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def build_element_extraction_parameters(self, source=None):
{
"output_dug_type": dug_type,
"casting_config": {
"node_type": queries[dug_type]['node_type']
"node_type": queries[dug_type]["node_type"],
"curie_prefix": queries[dug_type]["curie_prefix"],
"attribute_mapping": queries[dug_type]["attribute_mapping"]
# CDE's are only ones
# but if we had two biolink:Publication nodes we want to conditionally
# cast to other output_dug_type, we could extend this config
Expand Down
36 changes: 30 additions & 6 deletions tests/unit/mocks/data/tranql_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
}
},
"nodes": {
"publication": {
"category": "biolink:Publication"
},
"disease": {
"category": "biolink:Disease",
"id": [
"MONDO:0008187"
]
},
"publication": {
"category": "biolink:Publication"
}
}
},
Expand All @@ -25,11 +25,11 @@
"name": "panic disorder 1",
"category": [
"biolink:Disease",
"biolink:Entity",
"biolink:DiseaseOrPhenotypicFeature",
"biolink:ThingWithTaxon",
"biolink:BiologicalEntity",
"biolink:NamedThing",
"biolink:DiseaseOrPhenotypicFeature"
"biolink:Entity",
"biolink:NamedThing"
],
"attributes": [
{
Expand Down Expand Up @@ -72,6 +72,30 @@
"value": "Filename: Photosensitivity_PAQ_CDE_v1.0.json; File path: Supplemental Questionnaires/Sensory/Photosensitivity Assessment Questionnaire (PAQ); Photosensitivity Assessment Questionnaire",
"name": "summary"
},
{
"type": "NA",
"value": [
"Supplemental Questionnaires",
"Sensory",
"Photosensitivity Assessment Questionnaire (PAQ)"
],
"name": "cde_categories"
},
{
"type": "NA",
"value": [
"Supplemental Questionnaires",
"Adult/Pediatric",
"Acute/Chronic Pain",
"Photosensitivity Assessment Questionnaire (PAQ)"
],
"name": "cde_category_extended"
},
{
"type": "NA",
"value": "Supplemental Questionnaires",
"name": "cde_category"
},
{
"type": "NA",
"value": [
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/test_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ def test_expand_to_dug_element(crawler):
concept.add_identifier(identifier)
new_elements = crawler.expand_to_dug_element(
concept=concept,
casting_config={"node_type": "biolink:Publication"},
casting_config={
"node_type": "biolink:Publication",
"curie_prefix": "HEALCDE",
"attribute_mapping": {
"name": "name",
"desc": "summary",
"collection_name": "cde_category",
"collection_id": "cde_category"
}
},
dug_element_type="test-element",
tranql_source="test:graph"
)
Expand Down