Exemplo n.º 1
0
    def test_has_pathology(self):
        """Test for checking edges that have a causal pathology."""
        graph = BELGraph()

        a, b, c = protein(n(), n()), pathology(n(), n()), pathology(n(), n())

        key = graph.add_increases(a, b, n(), n())
        self.assertFalse(has_pathology_causal(graph, a, b, key))

        key = graph.add_increases(b, a, n(), n())
        self.assertTrue(has_pathology_causal(graph, b, a, key))

        key = graph.add_association(b, a, n(), n())
        self.assertFalse(has_pathology_causal(graph, b, a, key))

        key = graph.add_increases(a, c, n(), n())
        self.assertFalse(has_pathology_causal(graph, a, c, key))
Exemplo n.º 2
0
    def test_count_pathologies(self):
        """Test counting pathologies in the graph."""
        graph = BELGraph()
        a, b, c, d = protein(n(), n()), protein(n(), n()), pathology(n(), n()), pathology(n(), n())

        graph.add_association(a, c, n(), n())
        graph.add_association(a, d, n(), n())
        graph.add_association(b, d, n(), n())

        pathology_counter = count_pathologies(graph)
        self.assertIn(c, pathology_counter)
        self.assertIn(d, pathology_counter)
        self.assertEqual(1, pathology_counter[c])
        self.assertEqual(2, pathology_counter[d])

        top_pathology_counter = get_top_pathologies(graph, count=1)
        self.assertEqual(1, len(top_pathology_counter))
        node, count = top_pathology_counter[0]
        self.assertEqual(d, node)
        self.assertEqual(2, count)
Exemplo n.º 3
0
    def test_get_top_hubs(self):
        """Test counting pathologies in the graph."""
        graph = BELGraph()
        a, b, c = protein(n(), n()), protein(n(), n()), pathology(n(), n())

        graph.add_association(a, b, citation=n(), evidence=n())
        graph.add_association(a, c, citation=n(), evidence=n())

        top_hubs = get_top_hubs(graph, n=1)
        self.assertEqual(1, len(top_hubs))
        node, degree = top_hubs[0]
        self.assertEqual(a, node)
        self.assertEqual(2, degree)
Exemplo n.º 4
0
    def bel_isolated_reconstituted(self, graph: BELGraph):
        """Run the isolated node test."""
        self.assertIsNotNone(graph)
        self.assertIsInstance(graph, BELGraph)

        adgrb1 = protein(namespace='HGNC', name='ADGRB1')
        adgrb2 = protein(namespace='HGNC', name='ADGRB2')
        adgrb_complex = complex_abundance([adgrb1, adgrb2])
        achlorhydria = pathology(namespace='MESHD', name='Achlorhydria')

        for node in graph:
            self.assertIsInstance(node, BaseEntity)

        self.assertIn(adgrb1, graph)
        self.assertIn(adgrb2, graph)
        self.assertIn(adgrb_complex, graph)
        self.assertIn(achlorhydria, graph)

        assert_has_edge(self, adgrb_complex, adgrb1, graph)
        assert_has_edge(self, adgrb_complex, adgrb2, graph)
Exemplo n.º 5
0
    def test_count_pathologies(self):
        """Test counting pathologies in the graph."""
        graph = BELGraph()
        a, b = (protein(namespace='HGNC', name=n()) for _ in range(2))
        c, d = (pathology(namespace='DOID', name=n()) for _ in range(2))

        graph.add_association(a, c, citation=n(), evidence=n())
        graph.add_association(a, d, citation=n(), evidence=n())
        graph.add_association(b, d, citation=n(), evidence=n())

        pathology_counter = count_pathologies(graph)
        self.assertIn(c, pathology_counter)
        self.assertIn(d, pathology_counter)
        self.assertEqual(1, pathology_counter[c])
        self.assertEqual(2, pathology_counter[d])

        top_pathology_counter = get_top_pathologies(graph, n=1)
        self.assertEqual(1, len(top_pathology_counter))
        node, count = top_pathology_counter[0]
        self.assertEqual(d, node)
        self.assertEqual(2, count)
Exemplo n.º 6
0
    def test_remove_pathologies(self):
        """Test removal of pathologies."""
        g = BELGraph()

        p1, p2, p3 = (Protein(namespace='HGNC', name=n()) for _ in range(3))
        d1, d2 = (pathology(namespace='MESH', name=n()) for _ in range(2))

        g.add_increases(p1, p2, citation=n(), evidence=n())
        g.add_increases(p2, p3, citation=n(), evidence=n())
        g.add_positive_correlation(p1, d1, citation=n(), evidence=n())
        g.add_positive_correlation(p2, d1, citation=n(), evidence=n())
        g.add_association(p2, d1, citation=n(), evidence=n())
        g.add_positive_correlation(d1, d2, citation=n(), evidence=n())
        g.add_positive_correlation(d1, d2, citation=n(), evidence=n())

        self.assertEqual(5, g.number_of_nodes())
        self.assertEqual(7, g.number_of_edges())
        self.assertEqual(2, len(g[p2][d1]))

        remove_associations(g)

        relations = list(g[p2][d1].values())
        self.assertEqual(1, len(relations))
        self.assertEqual(POSITIVE_CORRELATION, relations[0][RELATION])

        self.assertEqual(5, g.number_of_nodes())
        self.assertEqual(6, g.number_of_edges())
        self.assertEqual(5, g.number_of_nodes())

        remove_pathologies(g)

        self.assertTrue(p1, g)
        self.assertTrue(p2, g)
        self.assertTrue(p3, g)
        self.assertEqual(3, g.number_of_nodes())
        self.assertEqual(2, g.number_of_edges())
Exemplo n.º 7
0
    def test_remove_pathologies(self):
        """Test removal of pathologies."""
        g = BELGraph()

        p1, p2, p3 = (protein(namespace='HGNC', name=n()) for _ in range(3))
        d1, d2 = (pathology(namespace='MESH', name=n()) for _ in range(2))

        g.add_increases(p1, p2, n(), n())
        g.add_increases(p2, p3, n(), n())
        g.add_qualified_edge(p1, d1, POSITIVE_CORRELATION, n(), n())
        g.add_qualified_edge(p2, d1, POSITIVE_CORRELATION, n(), n())
        g.add_association(p2, d1, n(), n())
        g.add_qualified_edge(d1, d2, POSITIVE_CORRELATION, n(), n())
        g.add_qualified_edge(d1, d2, POSITIVE_CORRELATION, n(), n())

        self.assertEqual(5, g.number_of_nodes())
        self.assertEqual(7, g.number_of_edges())
        self.assertEqual(2, len(g[p2.as_tuple()][d1.as_tuple()]))

        remove_associations(g)

        relations = list(g[p2.as_tuple()][d1.as_tuple()].values())
        self.assertEqual(1, len(relations))
        self.assertEqual(POSITIVE_CORRELATION, relations[0][RELATION])

        self.assertEqual(5, g.number_of_nodes())
        self.assertEqual(6, g.number_of_edges())
        self.assertEqual(5, g.number_of_nodes())

        remove_pathologies(g)

        self.assertTrue(g.has_node_with_data(p1))
        self.assertTrue(g.has_node_with_data(p2))
        self.assertTrue(g.has_node_with_data(p3))
        self.assertEqual(3, g.number_of_nodes())
        self.assertEqual(2, g.number_of_edges())
Exemplo n.º 8
0
g(HGNC:MTHFR,sub(A,1298,C)) =| p(HGNC:MTHFR)
g(HGNC:MTHFR,sub(C,677,T)) neg a(CHEBI:"folic acid")
g(HGNC:MTHFR,sub(C,677,T)) pos path(MESH:"Alzheimer Disease")
"""

c2 = '21119889'
e2 = "Two common MTHFR polymorphisms, namely 677C>T (Ala222Val) and 1298A>C (Glu429Ala), are known to reduce MTHFR activity. \
It has been shown that the MTHFR 677T allele is associated with increased total plasma Hcy levels (tHcy) and decreased serum folate levels, mainly in 677TT homozygous subjects.\
the MTHFR 677C>T polymorphism as a candidate AD risk factor"
e2 = str(hash(e2))

mthfr = protein('HGNC', 'MTHFR')
mthfr_c677t = protein('HGNC', 'MTHFR', variants=[protein_substitution('Ala', 222, 'Val')])
mthfr_a1298c = protein('HGNC', 'MTHFR', variants=[protein_substitution('Glu', 429, 'Ala')])
folic_acid = abundance('CHEBI', 'folic acid')
alzheimer_disease = pathology('MESH', 'Alzheimer Disease')

example_graph.add_decreases(mthfr_c677t, mthfr, citation=c2, evidence=e2, object_modifier=activity())
example_graph.add_decreases(mthfr_a1298c, mthfr, citation=c2, evidence=e2, object_modifier=activity())
example_graph.add_negative_correlation(mthfr_c677t, folic_acid, citation=c2, evidence=e2)
example_graph.add_positive_correlation(mthfr_c677t, alzheimer_disease, citation=c2, evidence=e2)

c3 = '17948130'
e3 = 'A polymorphism in the NDUFB6 promoter region that creates a possible DNA methylation site (rs629566, A/G) was ' \
     'associated with a decline in muscle NDUFB6 expression with age. Although young subjects with the rs629566 G/G ' \
     'genotype exhibited higher muscle NDUFB6 expression, this genotype was associated with reduced expression in' \
     ' elderly subjects. This was subsequently explained by the finding of increased DNA methylation in the promoter ' \
     'of elderly, but not young, subjects carrying the rs629566 G/G genotype. Furthermore, the degree of DNA' \
     ' methylation correlated negatively with muscle NDUFB6 expression, which in turn was associated with insulin ' \
     'sensitivity.'
e3 = str(hash(e3))
Exemplo n.º 9
0
r1 = rna(HGNC, '1')
p1 = protein(HGNC, '1')
p1_phosphorylated = protein(HGNC, '1', variants=[pmod('Ph')])

g2 = gene(HGNC, '2')
r2 = rna(HGNC, '2')
p2 = protein(HGNC, '2')

g3 = gene(HGNC, '3')
r3 = rna(HGNC, '3')
p3 = protein(HGNC, '3')

g4 = gene(HGNC, '4')
m4 = mirna(HGNC, '4')

p5 = pathology(GO, '5')


class TestCollapse(unittest.TestCase):
    """Tests for collapse functions."""
    def test_collapse_by_dict(self):
        """Test collapsing nodes by a dictionary."""
        graph = BELGraph()
        graph.add_node_from_data(p1)
        graph.add_node_from_data(p2)
        graph.add_node_from_data(p3)

        graph.add_increases(p1, p3, citation=n(), evidence=n())
        graph.add_qualified_edge(p2,
                                 p3,
                                 relation=DIRECTLY_INCREASES,
Exemplo n.º 10
0
 def test_pathology(self):
     node = pathology(namespace='DO', name='Alzheimer disease')
     self.assertEqual('path(DO:"Alzheimer disease")', str(node))