Skip to content

Commit 9ee278d

Browse files
committed
HPO checks ignore the HPO terms that are not present in the current ontology.
1 parent b9941d6 commit 9ee278d

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

phenosentry/auditor/phenopacket.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ def audit(
136136
):
137137
pf_pad = notepad.add_subsection("phenotypic_features")
138138
for i, phenotype in enumerate(item.phenotypic_features):
139-
term = self._hpo.get_term(phenotype.type.id)
140-
if term is not None and (term.is_obsolete or term.identifier.value != phenotype.type.id):
141-
_, _, id_pad = pf_pad.add_subsections(i, "type", "id")
142-
id_pad.add_error(f"`{phenotype.type.id}` has been deprecated")
139+
if phenotype.type.id in self._hpo:
140+
term = self._hpo.get_term(phenotype.type.id)
141+
assert term is not None, "We checked term's presence in the ontology"
142+
if term.is_obsolete or term.identifier.value != phenotype.type.id:
143+
_, _, id_pad = pf_pad.add_subsections(i, "type", "id")
144+
id_pad.add_error(f"`{phenotype.type.id}` has been deprecated")
143145

144146
def __str__(self) -> str:
145147
return repr(self)
@@ -202,7 +204,7 @@ def audit(
202204
):
203205
pfs_pad = notepad.add_subsection("phenotypic_features")
204206
for i, pf in enumerate(item.phenotypic_features):
205-
if pf.type.id.startswith("HP:"):
207+
if pf.type.id.startswith("HP:") and pf.type.id in self._hpo:
206208
if not self._hpo.graph.is_ancestor_of_or_equal_to(PHENOTYPIC_ABNORMALITY, pf.type.id):
207209
_, pf_pad = pfs_pad.add_subsections(i, "type")
208210
pf_pad.add_error(
@@ -235,13 +237,14 @@ def audit(
235237
TermId.from_curie(pf.type.id): i for i, pf in enumerate(item.phenotypic_features) if not pf.excluded
236238
}
237239
for pf in present2idx:
238-
for anc in self._hpo.graph.get_ancestors(pf):
239-
if anc in present2idx:
240-
term_label = self._hpo.get_term_name(pf)
241-
anc_label = self._hpo.get_term_name(anc)
242-
pfs_pad.add_error(
243-
f"annotation to {anc_label} [{anc.value}] (#{present2idx[anc]}) is redundant due to annotation to {term_label} [{pf.value}] (#{present2idx[pf]})"
244-
)
240+
if pf in self._hpo:
241+
for anc in self._hpo.graph.get_ancestors(pf):
242+
if anc in present2idx:
243+
term_label = self._hpo.get_term_name(pf)
244+
anc_label = self._hpo.get_term_name(anc)
245+
pfs_pad.add_error(
246+
f"annotation to {anc_label} [{anc.value}] (#{present2idx[anc]}) is redundant due to annotation to {term_label} [{pf.value}] (#{present2idx[pf]})"
247+
)
245248

246249

247250
class ExcludedAnnotationPropagationAuditor(PhenopacketAuditor):
@@ -270,13 +273,14 @@ def audit(
270273

271274
pfs_pad = notepad.add_subsection("phenotypic_features")
272275
for pf in excluded2idx:
273-
for anc in self._hpo.graph.get_ancestors(pf):
274-
if anc in excluded2idx:
275-
term_label = self._hpo.get_term_name(pf)
276-
anc_label = self._hpo.get_term_name(anc)
277-
pfs_pad.add_error(
278-
f"exclusion of {term_label} [{pf.value}] (#{excluded2idx[pf]}) is redundant due to exclusion of its ancestor {anc_label} [{anc.value}] (#{excluded2idx[anc]})"
279-
)
276+
if pf in self._hpo:
277+
for anc in self._hpo.graph.get_ancestors(pf):
278+
if anc in excluded2idx:
279+
term_label = self._hpo.get_term_name(pf)
280+
anc_label = self._hpo.get_term_name(anc)
281+
pfs_pad.add_error(
282+
f"exclusion of {term_label} [{pf.value}] (#{excluded2idx[pf]}) is redundant due to exclusion of its ancestor {anc_label} [{anc.value}] (#{excluded2idx[anc]})"
283+
)
280284

281285

282286
class AnnotationInconsistencyAuditor(PhenopacketAuditor):
@@ -309,10 +313,11 @@ def audit(
309313

310314
pfs_pad = notepad.add_subsection("phenotypic_features")
311315
for pf in present2idx:
312-
for anc in self._hpo.graph.get_ancestors(pf):
313-
if anc in excluded2idx:
314-
term_label = self._hpo.get_term_name(pf)
315-
anc_label = self._hpo.get_term_name(anc)
316-
pfs_pad.add_error(
317-
f"presence of {term_label} [{pf.value}] (#{present2idx[pf]}) is logically inconsistent with exclusion of {anc_label} [{anc.value}] (#{excluded2idx[anc]})"
318-
)
316+
if pf in self._hpo:
317+
for anc in self._hpo.graph.get_ancestors(pf):
318+
if anc in excluded2idx:
319+
term_label = self._hpo.get_term_name(pf)
320+
anc_label = self._hpo.get_term_name(anc)
321+
pfs_pad.add_error(
322+
f"presence of {term_label} [{pf.value}] (#{present2idx[pf]}) is logically inconsistent with exclusion of {anc_label} [{anc.value}] (#{excluded2idx[anc]})"
323+
)

0 commit comments

Comments
 (0)