monarch-initiative / pyphetools

Python Phenopacket Tools
https://monarch-initiative.github.io/pyphetools/
MIT License
9 stars 1 forks source link

test_flag_redundant_terms #61

Closed pnrobinson closed 5 months ago

pnrobinson commented 7 months ago

Refactoring the OntologyQC/Validation to be done on a set of Individuals. Need to move the unit test somewhere else or adapt it.

def test_flag_redundant_terms(self):
        metadata = MetaData(created_by="ORCID:0000-0002-0736-9199")
        metadata.default_versions_with_hpo(version="2022-05-05")
        age_of_last_examination = "P4Y11M"
        sex = "female"
        encoder = CaseEncoder(hpo_cr=self._hpo_cr,
                                  individual_id="A",
                                  pmid="PMID:123",
                                  age_at_last_exam=age_of_last_examination,
                                  sex=sex,
                                  metadata=metadata.to_ga4gh())
        vignette1 = "He had conductive hearing impairment."
        # Conductive hearing impairment HP:0000405
        results = encoder.add_vignette(vignette=vignette1)
        self.assertEqual(1, len(results))
        tid = results.loc[(results['id'] == 'HP:0000405')]['id'].values[0]
        self.assertEqual("HP:0000405", tid)
        label = results.loc[(results['id'] == 'HP:0000405')]['label'].values[0]
        self.assertEqual("Conductive hearing impairment", label)
        # Hearing impairment HP:0000365
        # REDUNDANT!
        vignette2 = "He had hearing impairment."
        results = encoder.add_vignette(vignette=vignette2)
        self.assertEqual(1, len(results))
        tid = results.loc[(results['id'] == 'HP:0000365')]['id'].values[0]
        self.assertEqual("HP:0000365", tid)
        label = results.loc[(results['id'] == 'HP:0000365')]['label'].values[0]
        self.assertEqual("Hearing impairment", label)
        # THe QC should pick up the redundancy
        individual = encoder.get_individual()
        self.assertTrue(encoder.has_errors())
pnrobinson commented 5 months ago

working