How to use the pybel.dsl.hgvs function in pybel

To help you get started, we’ve selected a few pybel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pybel / pybel / tests / test_struct / test_filters / test_node_predicates.py View on Github external
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,
    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):
        """Test permissive node predicate with graph and tuple."""
        g = BELGraph()
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_gene_with_hgvs(self):
        """Test parsing a gene with a variant."""
        statement = 'g(HGNC:AKT1, var(p.Phe508del))'
        result = self.parser.gene.parseString(statement)

        expected_result = {
            FUNCTION: GENE,
            CONCEPT: {
                NAMESPACE: 'HGNC',
                NAME: 'AKT1',
            },
            VARIANTS: [hgvs(TEST_PROTEIN_VARIANT)],
        }
        self.assertEqual(expected_result, result.asDict())

        expected_node = gene('HGNC', 'AKT1', variants=hgvs(TEST_PROTEIN_VARIANT))
        self.assert_has_node(expected_node)
        self.assertEqual('g(HGNC:AKT1, var("p.Phe508del"))', self.graph.node_to_bel(expected_node))

        parent = gene('HGNC', 'AKT1')
        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def _help_test_protein_trunc_1(self, statement):
        result = self.parser.protein.parseString(statement)

        expected_node = protein('HGNC', 'AKT1', variants=hgvs('p.40*'))
        self.assert_has_node(expected_node)

        canonical_bel = self.graph.node_to_bel(expected_node)
        self.assertEqual('p(HGNC:AKT1, var("p.40*"))', canonical_bel)

        protein_node = expected_node.get_parent()
        self.assert_has_node(protein_node)
        self.assert_has_edge(protein_node, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_protein_variant_substitution(self):
        """2.2.2 Test substitution"""
        statement = 'p(HGNC:CFTR, var(p.Gly576Ala))'
        result = self.parser.protein.parseString(statement)
        expected_result = [PROTEIN, ['HGNC', 'CFTR'], [HGVS, 'p.Gly576Ala']]
        self.assertEqual(expected_result, result.asList())

        expected_node = protein('HGNC', 'CFTR', variants=hgvs('p.Gly576Ala'))
        self.assert_has_node(expected_node)
        self.assertEqual('p(HGNC:CFTR, var("p.Gly576Ala"))', self.graph.node_to_bel(expected_node))

        parent = expected_node.get_parent()
        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
expected_result = {
            FUNCTION: GENE,
            CONCEPT: {
                NAMESPACE: 'HGNC',
                NAME: 'AKT1',
            },
            VARIANTS: [
                hgvs(TEST_PROTEIN_VARIANT),
                hgvs(TEST_GENE_VARIANT),
                hgvs('c.1521_1523delCTT'),
            ],
        }
        self.assertEqual(expected_result, result.asDict())

        expected_node = gene('HGNC', 'AKT1', variants=[
            hgvs('c.1521_1523delCTT'), hgvs(TEST_GENE_VARIANT), hgvs(TEST_PROTEIN_VARIANT)
        ])
        self.assert_has_node(expected_node)
        self.assertEqual(
            'g(HGNC:AKT1, var("c.1521_1523delCTT"), var("c.308G>A"), var("p.Phe508del"))',
            self.graph.node_to_bel(expected_node),
        )

        parent = gene('HGNC', 'AKT1')
        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_gene_with_hgvs(self):
        """Test parsing a gene with a variant."""
        statement = 'g(HGNC:AKT1, var(p.Phe508del))'
        result = self.parser.gene.parseString(statement)

        expected_result = {
            FUNCTION: GENE,
            CONCEPT: {
                NAMESPACE: 'HGNC',
                NAME: 'AKT1',
            },
            VARIANTS: [hgvs(TEST_PROTEIN_VARIANT)],
        }
        self.assertEqual(expected_result, result.asDict())

        expected_node = gene('HGNC', 'AKT1', variants=hgvs(TEST_PROTEIN_VARIANT))
        self.assert_has_node(expected_node)
        self.assertEqual('g(HGNC:AKT1, var("p.Phe508del"))', self.graph.node_to_bel(expected_node))

        parent = gene('HGNC', 'AKT1')
        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
NAME: 'AKT1',
            },
            VARIANTS: [
                {
                    KIND: HGVS,
                    HGVS: TEST_GENE_VARIANT,
                },
            ],
            LOCATION: {
                NAMESPACE: 'GO',
                NAME: 'intracellular',
            },
        }
        self.assertEqual(expected_result, result.asDict())

        expected_node = gene('HGNC', 'AKT1', variants=hgvs("c.308G>A"))
        self.assert_has_node(expected_node)
        self.assertEqual('g(HGNC:AKT1, var("c.308G>A"))', self.graph.node_to_bel(expected_node))

        parent = gene('HGNC', 'AKT1')
        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_protein_trunc_3(self):
        statement = 'p(HGNC:AKT1, var(p.Arg1851*))'
        result = self.parser.protein.parseString(statement)

        expected_result = [PROTEIN, ['HGNC', 'AKT1'], [HGVS, 'p.Arg1851*']]
        self.assertEqual(expected_result, result.asList())

        parent = protein('HGNC', 'AKT1')
        expected_node = parent.with_variants(hgvs('p.Arg1851*'))
        self.assert_has_node(expected_node)
        self.assertEqual('p(HGNC:AKT1, var("p.Arg1851*"))', self.graph.node_to_bel(expected_node))

        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_gene_with_substitution(self):
        """Test BEL 1.0 gene substitution"""
        statement = 'g(HGNC:AKT1,sub(G,308,A))'
        result = self.parser.gene.parseString(statement)

        expected_result = gene(
            name='AKT1',
            namespace='HGNC',
            variants=[hgvs(TEST_GENE_VARIANT)],
        )
        self.assertEqual(dict(expected_result), result.asDict())

        expected_node = gene('HGNC', 'AKT1', variants=hgvs("c.308G>A"))
        self.assert_has_node(expected_node)
        self.assertEqual('g(HGNC:AKT1, var("c.308G>A"))', self.graph.node_to_bel(expected_node))

        parent = gene('HGNC', 'AKT1')
        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
"""2.2.2 RNA coding reference sequence"""
        statement = 'r(HGNC:CFTR, var(r.1521_1523delcuu))'
        result = self.parser.rna.parseString(statement)

        expected_dict = {
            FUNCTION: RNA,
            CONCEPT: {
                NAMESPACE: 'HGNC',
                NAME: 'CFTR',
            },
            VARIANTS: [hgvs('r.1521_1523delcuu')],
        }
        self.assertEqual(expected_dict, result.asDict())

        parent = rna('HGNC', 'CFTR')
        expected_node = parent.with_variants(hgvs('r.1521_1523delcuu'))
        self.assert_has_node(expected_node)

        self.assertEqual('r(HGNC:CFTR, var("r.1521_1523delcuu"))', self.graph.node_to_bel(expected_node))
        self.assert_has_node(parent)
        self.assert_has_edge(parent, expected_node, relation=HAS_VARIANT)