Example #1
0
    def test_label_1(self):
        statement = 'g(HGNC:APOE, var(c.526C>T), var(c.388T>C)) labeled "APOE E2"'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SUBJECT: {
                FUNCTION:
                GENE,
                NAMESPACE:
                'HGNC',
                NAME:
                'APOE',
                VARIANTS: [{
                    KIND: HGVS,
                    IDENTIFIER: 'c.526C>T'
                }, {
                    KIND: HGVS,
                    IDENTIFIER: 'c.388T>C'
                }]
            },
            OBJECT: 'APOE E2'
        }
        self.assertEqual(expected_dict, result.asDict())

        expected_node = gene('HGNC',
                             'APOE',
                             variants=[hgvs('c.526C>T'),
                                       hgvs('c.388T>C')])
        self.assert_has_node(expected_node)

        self.assertTrue(self.parser.graph.has_node_description(expected_node))
        self.assertEqual('APOE E2',
                         self.parser.graph.get_node_description(expected_node))
Example #2
0
    def test_canonicalize_variant_dsl(self):
        """Use the __str__ functions in the DSL to create BEL instead of external pybel.canonicalize."""
        self.assertEqual('var("p.Val600Glu")', str(hgvs('p.Val600Glu')))
        self.assertEqual('var("p.Val600Glu")',
                         str(protein_substitution('Val', 600, 'Glu')))

        self.assertEqual('pmod(Ph)', str(pmod('Ph')))
        self.assertEqual('pmod(TEST:Ph)', str(pmod('Ph', namespace='TEST')))
        self.assertEqual('pmod(TEST:Ph, Ser)',
                         str(pmod('Ph', namespace='TEST', code='Ser')))
        self.assertEqual(
            'pmod(TEST:Ph, Ser, 5)',
            str(pmod('Ph', namespace='TEST', code='Ser', position=5)))
        self.assertEqual(
            'pmod(GO:"protein phosphorylation", Thr, 308)',
            str(
                pmod(name='protein phosphorylation',
                     namespace='GO',
                     code='Thr',
                     position=308)))

        self.assertEqual('frag("?")', str(fragment()))
        self.assertEqual('frag("672_713")', str(fragment(start=672, stop=713)))
        self.assertEqual('frag("?", "descr")',
                         str(fragment(description='descr')))
        self.assertEqual(
            'frag("672_713", "descr")',
            str(fragment(start=672, stop=713, description='descr')))

        self.assertEqual('gmod(Me)', str(gmod('Me')))
        self.assertEqual('gmod(TEST:Me)', str(gmod('Me', namespace='TEST')))
        self.assertEqual('gmod(GO:"DNA Methylation")',
                         str(gmod('DNA Methylation', namespace='GO')))
Example #3
0
    def test_equivalentTo(self):
        statement = 'g(dbSNP:"rs123456") eq g(HGNC:YFG, var(c.123G>A))'
        result = self.parser.relation.parseString(statement)

        expected_result = {
            SUBJECT: {
                FUNCTION: GENE,
                NAMESPACE: 'dbSNP',
                NAME: 'rs123456',
            },
            RELATION: EQUIVALENT_TO,
            OBJECT: {
                FUNCTION: GENE,
                NAMESPACE: 'HGNC',
                NAME: 'YFG',
                VARIANTS: [{
                    KIND: HGVS,
                    IDENTIFIER: 'c.123G>A'
                }]
            }
        }
        self.assertEqual(expected_result, result.asDict())

        sub = gene('dbSNP', 'rs123456')
        self.assert_has_node(sub)

        obj = gene('HGNC', 'YFG', variants=hgvs('c.123G>A'))
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, **{RELATION: EQUIVALENT_TO})
        self.assert_has_edge(obj, sub, **{RELATION: EQUIVALENT_TO})
    def test_trunc_2(self):
        """Test a truncation in which the amino acid is specified."""
        statement = 'trunc(Gly40)'
        result = self.parser.parseString(statement)

        expected = hgvs('p.Gly40*')
        self.assertEqual(expected, result.asDict())
Example #5
0
def test_modification_with_mutation():
    braf = Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')],
                 db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt = Phosphorylation(braf, mek, 'S', '218')
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    # Adds in the base protein nodes as well as the variants (so 4 nodes)
    assert belgraph.number_of_nodes() == 4, belgraph.number_of_nodes()
    braf_mut_dsl = braf_dsl.with_variants(hgvs('p.Val600Glu'))
    assert braf_mut_dsl in belgraph
def test_modification_with_mutation():
    braf = Agent('BRAF', mutations=[MutCondition('600', 'V', 'E')],
                 db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt = Phosphorylation(braf, mek, 'S', '218')
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    # Adds in the base protein nodes as well as the variants (so 4 nodes)
    assert len(belgraph.nodes()) == 4
    braf_mut_dsl = braf_dsl.with_variants(hgvs('p.Val600Glu'))
    assert braf_mut_dsl in belgraph
Example #7
0
    def test_add_node_with_variant(self):
        """Test that the identifier is carried through to the child."""
        graph = BELGraph()
        namespace, name, identifier, variant_name = n(), n(), n(), n()
        node = protein(namespace=namespace,
                       name=name,
                       identifier=identifier,
                       variants=hgvs(variant_name))
        parent = node.get_parent()

        graph.add_node_from_data(node)

        self.assertEqual(2, graph.number_of_nodes())
Example #8
0
    def test_no_infer_on_rna_variants(self):
        """Test that expansion doesn't occur on RNA variants."""
        r = rna('HGNC', n(), variants=[hgvs(n())])

        graph = BELGraph()
        graph.add_node_from_data(r)

        self.assertEqual(2, graph.number_of_nodes())
        self.assertEqual(1, graph.number_of_edges())

        enrich_protein_and_rna_origins(graph)

        self.assertEqual(3, graph.number_of_nodes())
        self.assertEqual(2, graph.number_of_edges())
Example #9
0
    def test_cnc_with_subject_variant(self):
        """Test a causesNoChange relationship with a variant in the subject.

        See also: 3.1.6 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#Xcnc
        """
        statement = 'g(HGNC:APP,sub(G,275341,C)) cnc path(MESH:"Alzheimer Disease")'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SOURCE: {
                FUNCTION: GENE,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'APP',
                },
                VARIANTS: [
                    {
                        KIND: HGVS,
                        HGVS: 'c.275341G>C'
                    },
                ],
            },
            RELATION: CAUSES_NO_CHANGE,
            TARGET: {
                FUNCTION: PATHOLOGY,
                CONCEPT: {
                    NAMESPACE: 'MESH',
                    NAME: 'Alzheimer Disease',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        app_gene = gene(namespace='HGNC', name='APP')
        self.assert_has_node(app_gene)
        sub = app_gene.with_variants(hgvs('c.275341G>C'))
        self.assert_has_node(sub)

        obj = Pathology('MESH', 'Alzheimer Disease')
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=expected_dict[RELATION])
Example #10
0
    def test_gsub(self):
        statement = 'sub(G,308,A)'
        result = self.parser.parseString(statement)

        expected_dict = hgvs('c.308G>A')
        self.assertEqual(expected_dict, result.asDict())
Example #11
0
 def test_protein_trunc_legacy(self):
     statement = 'var(p.65*)'
     result = self.parser.parseString(statement)
     expected = hgvs('p.65*')
     self.assertEqual(expected, result.asDict())
Example #12
0
    is_degraded,
    is_gene,
    is_pathology,
    is_protein,
    is_translocated,
    keep_node_permissive,
    node_exclusion_predicate_builder,
    node_inclusion_predicate_builder,
    not_pathology,
)
from pybel.testing.utils import n

p1 = protein(name='BRAF', namespace='HGNC')
p2 = protein(name='BRAF',
             namespace='HGNC',
             variants=[hgvs('p.Val600Glu'), pmod('Ph')])
p3 = protein(name='APP',
             namespace='HGNC',
             variants=fragment(start=672, stop=713))
p4 = protein(name='2', namespace='HGNC')

g1 = gene(name='BRAF', namespace='HGNC', variants=gmod('Me'))


class TestNodePredicates(unittest.TestCase):
    """Tests for node predicates."""
    def test_none_data(self):
        """Test permissive node predicate with a node data dictionary."""
        self.assertTrue(keep_node_permissive(p1))

    def test_none(self):
Example #13
0
 def test_protein_del_quoted(self):
     statement = 'variant("p.Phe508del")'
     expected = hgvs('p.Phe508del')
     result = self.parser.parseString(statement)
     self.assertEqual(expected, result.asDict())
Example #14
0
 def test_protein_mut(self):
     statement = 'var(p.Gly576Ala)'
     expected = hgvs('p.Gly576Ala')
     result = self.parser.parseString(statement)
     self.assertEqual(expected, result.asDict())
Example #15
0
    def test_trunc_1(self):
        statement = 'trunc(40)'
        result = self.parser.parseString(statement)

        expected = hgvs('p.40*')
        self.assertEqual(expected, result.asDict())
Example #16
0
 def test_frameshift(self):
     statement = 'variant(p.Thr1220Lysfs)'
     expected = hgvs('p.Thr1220Lysfs')
     result = self.parser.parseString(statement)
     self.assertEqual(expected, result.asDict())
Example #17
0
 def test_unspecified(self):
     statement = 'var(=)'
     expected = hgvs('=')
     result = self.parser.parseString(statement)
     self.assertEqual(expected, result.asDict())
Example #18
0
 def test_chromosome_1(self):
     statement = 'variant(g.117199646_117199648delCTT)'
     expected = hgvs('g.117199646_117199648delCTT')
     result = self.parser.parseString(statement)
     self.assertEqual(expected, result.asDict())
Example #19
0
from pybel.struct.filters import false_node_predicate, true_node_predicate
from pybel.struct.filters.edge_predicate_builders import build_relation_predicate
from pybel.struct.filters.edge_predicates import (
    edge_has_activity, edge_has_annotation, edge_has_degradation,
    edge_has_translocation, has_authors, has_polarity, has_provenance, has_pubmed, is_associative_relation,
    is_causal_relation, is_direct_causal_relation,
)
from pybel.struct.filters.node_predicates import (
    has_activity, has_causal_in_edges, has_causal_out_edges, has_fragment, has_gene_modification, has_hgvs,
    has_protein_modification, has_variant, is_abundance, is_causal_central, is_causal_sink, is_causal_source,
    is_degraded, is_gene, is_pathology, is_protein, is_translocated, none_of, not_pathology, one_of,
)
from pybel.testing.utils import n

p1 = protein(name='BRAF', namespace='HGNC')
p2 = protein(name='BRAF', namespace='HGNC', variants=[hgvs('p.Val600Glu'), pmod('Ph')])
p3 = protein(name='APP', namespace='HGNC', variants=fragment(start=672, stop=713))
p4 = protein(name='2', namespace='HGNC')

g1 = gene(name='BRAF', namespace='HGNC', variants=gmod('Me'))


class TestNodePredicates(unittest.TestCase):
    """Tests for node predicates."""

    def test_none_data(self):
        """Test permissive node predicate with a node data dictionary."""
        self.assertTrue(true_node_predicate(p1))
        self.assertFalse(false_node_predicate(p1))

    def test_none(self):
Example #20
0
    def test_psub_2(self):
        statement = 'sub(Ala, 127, Tyr)'
        result = self.parser.parseString(statement)

        expected_list = hgvs('p.Ala127Tyr')
        self.assertEqual(expected_list, result.asDict())
Example #21
0
 def test_rna_del(self):
     statement = 'var(r.1653_1655delcuu)'
     expected = hgvs('r.1653_1655delcuu')
     result = self.parser.parseString(statement)
     self.assertEqual(expected, result.asDict())
Example #22
0
 def test_chromosome_2(self):
     statement = 'var(c.1521_1523delCTT)'
     expected = hgvs('c.1521_1523delCTT')
     result = self.parser.parseString(statement)
     self.assertEqual(expected, result.asDict())