Skip to content

Commit

Permalink
Attribute mapping from node to dug element (#203)
Browse files Browse the repository at this point in the history
* Release/2.8.0 (#198)

* Bumping version

* support for extracting dug elements from graph (#197)

* support for extracting dug elements from graph

* adding flag for enabling dug element extraction from graph

* adding new config for node_to dug element parsing

* adding more parameters to crawler to able configuration to element extraction logic

* add tests

* add tests for crawler

Co-authored-by: Yaphetkg <[email protected]>

* Update _version.py

* Update _version.py

updating version for final push to master

* Update factory.py

Adding more comments

Co-authored-by: Carl Schreep <[email protected]>
Co-authored-by: Yaphetkg <[email protected]>

* Release/v2.9.0 (#201)

* Bumping version

* support for extracting dug elements from graph (#197)

* support for extracting dug elements from graph

* adding flag for enabling dug element extraction from graph

* adding new config for node_to dug element parsing

* adding more parameters to crawler to able configuration to element extraction logic

* add tests

* add tests for crawler

Co-authored-by: Yaphetkg <[email protected]>

* Display es scores (#199)

* Include ES scores in variable results

* Round ES score to 6

* Update _version.py (#200)

* Update _version.py

Co-authored-by: Carl Schreep <[email protected]>
Co-authored-by: Yaphetkg <[email protected]>
Co-authored-by: Ginnie Hench <[email protected]>

* adding more config options for node extraction

* some refactoring

Co-authored-by: Carl Schreep <[email protected]>
Co-authored-by: Yaphetkg <[email protected]>
Co-authored-by: Ginnie Hench <[email protected]>
  • Loading branch information
4 people authored Apr 1, 2022
1 parent 4c9dbc3 commit 256d1e0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
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

0 comments on commit 256d1e0

Please sign in to comment.