def test_json(self):
        g = Decipher(diseaseid=1, name='Foo')

        self.assertEqual(g.toJSON(), {'id': 1, 'name': 'Foo'})

        self.assertEqual(g.toJSON(verbose=True), {
            'id': 1,
            'name': 'Foo',
            'hpo': set()
        })
示例#2
0
def make_ontology_with_annotation() -> pyhpo.ontology.OntologyClass:
    """
    Generates the following Ontology
    - HP:0001
        - HP:0011
            - HP:0021               <- Gene/Disease 0 / Negative Disease 2
                - HP:0031(*)
        - HP:0012                   <- Gene/Disease 1
            - HP:0031(*)
                - HP:0041
        - HP:0013

    """

    Gene.clear()
    Omim.clear()
    Orpha.clear()
    Decipher.clear()

    items = make_terms()

    terms = Ontology(from_obo_file=False)
    for item in items:
        terms._append(item)

    terms._connect_all()

    genes = make_genes(2)
    genes[0].hpo.add(21)
    genes[1].hpo.add(12)

    omim = make_omim(3)
    omim[0].hpo.add(21)
    omim[1].hpo.add(12)
    omim[2].negative_hpo.add(21)

    decipher = make_decipher(3)
    decipher[0].hpo.add(21)
    decipher[1].hpo.add(12)
    decipher[2].negative_hpo.add(21)

    orpha = make_orpha(3)
    orpha[0].hpo.add(21)
    orpha[1].hpo.add(12)
    orpha[2].negative_hpo.add(21)

    ds._add_omim_to_ontology(terms)
    ds._add_decipher_to_ontology(terms)
    ds._add_orpha_to_ontology(terms)
    _add_genes_to_ontology(terms)

    return terms
    def test_indexing(self):
        def subindex_length(x):
            return (
                len(x.keys()),
                len(x._indicies.keys()),
            )

        self.assertEqual(subindex_length(Decipher), (0, 0))
        _ = Decipher(diseaseid=1, name='Gaucher')
        self.assertEqual(subindex_length(Decipher), (1, 1))
        _ = Decipher(diseaseid=2, name='Fabry')
        self.assertEqual(subindex_length(Decipher), (2, 2))
        Decipher.clear()
        self.assertEqual(subindex_length(Decipher), (0, 0))
    def test_singleton_handling(self):
        d1a = Decipher(diseaseid=1, name='Gaucher')
        # ID present, will be used
        d1b = Decipher(diseaseid=1, name='Fabry')
        # No name present, ID will be used as well
        d1c = Decipher(diseaseid=1, name=None)

        # New ID, new Name => New Disease
        d2a = Decipher(diseaseid=2, name='Fabry')
        # ID present, Matching by ID
        d2b = Decipher(diseaseid=2, name='Gaucher')
        # ID present, Matching by ID
        d2c = Decipher(diseaseid=2, name=None)

        # New ID but existing name => New disease
        d3a = Decipher(diseaseid=3, name='Gaucher')

        self.assertIs(d1a, d1b)
        self.assertIs(d1a, d1c)

        self.assertIsNot(d1a, d2a)
        self.assertIs(d2a, d2b)
        self.assertIs(d2a, d2c)

        self.assertIsNot(d1a, d3a)
        self.assertIsNot(d2a, d3a)
    def test_get_decipher(self):
        d1 = Decipher(diseaseid=1, name='Gaucher')
        d2 = Decipher(diseaseid=2, name='Fabry')

        self.assertEqual(Decipher.get(1), d1)
        self.assertEqual(Decipher.get(2), d2)
        self.assertEqual(Decipher.get('1'), d1)

        self.assertRaises(ValueError, lambda: Decipher.get('Fabry'))
        self.assertRaises(KeyError, lambda: Decipher.get(12))
示例#6
0
    def test_set_with_one_annotation(self):
        ci = HPOSet([self.ontology[11], self.ontology[13], self.ontology[31]])

        assert len(ci.all_genes()) == 1
        assert len(ci.omim_diseases()) == 1
        assert len(ci.orpha_diseases()) == 1
        assert len(ci.decipher_diseases()) == 1

        assert ci.all_genes() == set([Gene.get(0)])
        assert ci.omim_diseases() == set([Omim.get(0)])
        assert ci.orpha_diseases() == set([Orpha.get(0)])
        assert ci.decipher_diseases() == set([Decipher.get(0)])
 def setUp(self):
     Decipher.clear()
     self.ontology = make_ontology()
     self.decipher_diseases = make_decipher(5)
 def test_string_representation(self):
     d = Decipher(diseaseid=1, name='Foo')
     self.assertEqual(str(d), 'Foo')
 def test_equality(self):
     g = Decipher(diseaseid=1, name='Foo')
     self.assertEqual(g, 1)
     self.assertEqual(g, 'Foo')
示例#10
0
 def test_decipher_disease_building(self):
     a = Decipher(diseaseid=1, name='Gaucher type I')
     self.assertEqual(a.name, 'Gaucher type I')
     self.assertEqual(a.id, 1)
     self.assertEqual(a.hpo, set())
示例#11
0
 def tearDown(self):
     Decipher.clear()
示例#12
0
 def setUp(self):
     Decipher.clear()
示例#13
0
def tearDown():
    Gene.clear()
    Omim.clear()
    Orpha.clear()
    Decipher.clear()
示例#14
0
def make_decipher(n) -> List[pyhpo.annotations.DiseaseSingleton]:
    Decipher.clear()
    return [
        Decipher(diseaseid=i, name='Decipher{}'.format(i)) for i in range(n)
    ]
示例#15
0
def all_decipher_diseases() -> Set['DecipherDisease']:
    return set(Decipher.keys())