Skip to content

Commit 8ec6563

Browse files
authored
Merge pull request #391 from Knowledge-Graph-Hub/fix-madin-biolink-category-inferences
Add logic to infer phenotypic category from METPO classes sheet
2 parents caebb83 + c980bb4 commit 8ec6563

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

kg_microbe/transform_utils/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@
476476

477477
BACDIVE_MAPPING_FILE = "bacdive_mappings.tsv"
478478

479+
# not used anywhere except in DO_NOT_CHANGE_PREFIXES list below
480+
METPO_PREFIX = "METPO:"
479481

480482
DO_NOT_CHANGE_PREFIXES = [
481483
NCBITAXON_PREFIX,
@@ -492,6 +494,7 @@
492494
MEDIADIVE_MEDIUM_PREFIX,
493495
STRAIN_PREFIX,
494496
BIOSAFETY_LEVEL_PREFIX,
497+
METPO_PREFIX,
495498
]
496499

497500
HAS_PARTICIPANT_PREDICATE = "biolink:has_participant"

kg_microbe/transform_utils/madin_etal/madin_etal.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,8 @@ def run(self, data_file: Union[Optional[Path], Optional[str]] = None, show_statu
226226
)
227227
if metabolism:
228228
# create metabolism node and edge to tax_id
229-
# use `biolink equivalent` for 'category' and
230-
# for 'predicate', `biolink equivalent` from properties
231-
category = metabolism.get("biolink_equivalent", METABOLISM_CATEGORY)
229+
# use biolink_equivalent URL from METPO tree traversal or fallback to default
230+
category = metabolism.get("inferred_category", METABOLISM_CATEGORY)
232231
predicate_biolink = metabolism.get("predicate_biolink_equivalent", "")
233232
# fallback: if no biolink equivalent use `biolink:has_phenotype`
234233
if predicate_biolink:
@@ -267,9 +266,8 @@ def run(self, data_file: Union[Optional[Path], Optional[str]] = None, show_statu
267266
# print(f"Pathway: {pathway}, METPO mapping: {metpo_mapping}")
268267
if metpo_mapping:
269268
# create pathway node and edge to tax_id
270-
# use `biolink equivalent` for 'category' and
271-
# for 'predicate', `biolink equivalent` from properties
272-
category = metpo_mapping.get("biolink_equivalent", PATHWAY_CATEGORY)
269+
# use biolink_equivalent URL from METPO tree traversal or fallback to default
270+
category = metpo_mapping.get("inferred_category", PATHWAY_CATEGORY)
273271
predicate_biolink = metpo_mapping.get(
274272
"predicate_biolink_equivalent", ""
275273
)
@@ -365,10 +363,9 @@ def run(self, data_file: Union[Optional[Path], Optional[str]] = None, show_statu
365363
# print(f"Substrate: {substrate}, METPO mapping: {metpo_mapping}")
366364
if metpo_mapping:
367365
# create carbon substrate node and edge to tax_id
368-
# use `biolink equivalent` for 'category' and
369-
# for 'predicate', `biolink equivalent` from properties
366+
# use biolink_equivalent URL from METPO tree traversal or fallback to default
370367
category = metpo_mapping.get(
371-
"biolink_equivalent", CARBON_SUBSTRATE_CATEGORY
368+
"inferred_category", CARBON_SUBSTRATE_CATEGORY
372369
)
373370
predicate_biolink = metpo_mapping.get(
374371
"predicate_biolink_equivalent", ""
@@ -462,9 +459,8 @@ def run(self, data_file: Union[Optional[Path], Optional[str]] = None, show_statu
462459
# print(f"Cell shape: {cell_shape}, METPO mapping: {metpo_mapping}")
463460
if metpo_mapping:
464461
# create cell shape node and edge to tax_id
465-
# use `biolink equivalent` for 'category' and
466-
# for 'predicate', `biolink equivalent` from properties
467-
category = metpo_mapping.get("biolink_equivalent", PHENOTYPIC_CATEGORY)
462+
# use biolink_equivalent URL from METPO tree traversal or fallback to default
463+
category = metpo_mapping.get("inferred_category", PHENOTYPIC_CATEGORY)
468464
predicate_biolink = metpo_mapping.get(
469465
"predicate_biolink_equivalent", ""
470466
)

kg_microbe/utils/mapping_file_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,25 @@ def load_metpo_mappings(synonym_column: str) -> Dict[str, Dict[str, str]]:
278278
biolink_equivalent = row.get("biolink equivalent", "").strip()
279279

280280
if synonym and metpo_curie:
281-
# Find the appropriate predicate using the logic:
281+
# Find the appropriate predicate and category using tree traversal logic:
282282
# 1. find the closest parent with `biolink equivalent`
283283
# 2. use the parent's label to find matching RANGE in properties sheet
284284
# 3. get the predicate info for that RANGE
285+
# 4. use the parent's label as the category
285286
predicate_label = "has phenotype" # default
286287
predicate_biolink_equivalent = "" # default empty
288+
inferred_category = "" # default empty, will be inferred from parent
287289
if metpo_curie in nodes:
288290
node = nodes[metpo_curie]
289291
# find the parent node that has a `biolink equivalent`
290292
current = node
291293
while current is not None:
292294
if current.biolink_equivalent:
293-
# use the parent's label to look up in properties RANGE
295+
# use the parent's biolink_equivalent URL as the category
294296
parent_label = current.label
297+
inferred_category = (
298+
current.biolink_equivalent
299+
) # use parent's biolink_equivalent URL as category
295300
if parent_label in range_to_predicate:
296301
predicate_label = range_to_predicate[parent_label]["label"]
297302
predicate_biolink_equivalent = range_to_predicate[parent_label][
@@ -311,6 +316,7 @@ def load_metpo_mappings(synonym_column: str) -> Dict[str, Dict[str, str]]:
311316
"predicate": predicate_label,
312317
"predicate_biolink_equivalent": predicate_biolink_equivalent,
313318
"biolink_equivalent": biolink_equivalent,
319+
"inferred_category": inferred_category,
314320
}
315321

316322
return mappings

0 commit comments

Comments
 (0)