How to use the pybel.dsl.gene 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_transformations / test_collapse.py View on Github external
from pybel.testing.utils import n

HGNC = 'HGNC'
GO = 'GO'
CHEBI = 'CHEBI'

g1 = gene(HGNC, '1')
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_check_survivors_consistent(self):
        """Test the survivor mapping is consistent."""
        inconsistencies = surviors_are_inconsistent({
            1: {2},
github pybel / pybel / tests / test_parse / test_parse_bel_relations.py View on Github external
def test_orthologous(self):
        """
        3.3.1 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#_orthologous
        """
        statement = 'g(HGNC:AKT1) orthologous g(MGI:AKT1)'
        result = self.parser.relation.parseString(statement)
        expected_result = [
            [GENE, ['HGNC', 'AKT1']],
            ORTHOLOGOUS,
            [GENE, ['MGI', 'AKT1']],
        ]
        self.assertEqual(expected_result, result.asList())

        sub = gene('HGNC', 'AKT1')
        self.assert_has_node(sub)

        obj = gene('MGI', 'AKT1')
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=ORTHOLOGOUS)
        self.assert_has_edge(obj, sub, relation=ORTHOLOGOUS)
github pybel / pybel / tests / test_parse / test_parse_bel_relations.py View on Github external
NAME: 'YFG',
                },
                VARIANTS: [
                    {
                        KIND: HGVS,
                        HGVS: '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})
github pybel / pybel / tests / test_struct / test_transformations / test_collapse.py View on Github external
import unittest

from pybel import BELGraph
from pybel.constants import DIRECTLY_INCREASES
from pybel.dsl import gene, mirna, pathology, pmod, protein, rna
from pybel.struct.mutation.collapse import (
    collapse_all_variants, collapse_nodes, collapse_to_genes, surviors_are_inconsistent,
)
from pybel.testing.utils import n

HGNC = 'HGNC'
GO = 'GO'
CHEBI = 'CHEBI'

g1 = gene(HGNC, '1')
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')
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_gene_variant_chromosome(self):
        """2.2.2 chromosome"""
        statement = 'g(REF:"NC_000007.13", var(g.117199646_117199648delCTT))'
        result = self.parser.gene.parseString(statement)

        expected_result = [GENE, ['REF', 'NC_000007.13'], [HGVS, 'g.117199646_117199648delCTT']]
        self.assertEqual(expected_result, result.asList())

        gene_node = gene('REF', 'NC_000007.13', variants=hgvs('g.117199646_117199648delCTT'))
        self.assert_has_node(gene_node)

        parent = gene_node.get_parent()
        self.assert_has_node(parent)
        self.assert_has_edge(parent, gene_node, relation=HAS_VARIANT)
github pybel / pybel / tests / test_struct / test_transformations / test_collapse.py View on Github external
CHEBI = 'CHEBI'

g1 = gene(HGNC, '1')
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_check_survivors_consistent(self):
        """Test the survivor mapping is consistent."""
        inconsistencies = surviors_are_inconsistent({
            1: {2},
            3: {4},
        })
        self.assertEqual(0, len(inconsistencies))
        self.assertFalse(inconsistencies)
github pybel / pybel / tests / test_manager_graph.py View on Github external
def test_regex_lookup(self, mock):  # FIXME this test needs to be put somewhere else
        """Tests that regular expression nodes get love too"""
        graph = BELGraph(name='Regular Expression Test Graph', description='Help test regular expression namespaces',
                         version='1.0.0')
        dbsnp = 'dbSNP'
        DBSNP_PATTERN = 'rs[0-9]+'
        graph.namespace_pattern[dbsnp] = DBSNP_PATTERN

        rs1234 = gene(namespace=dbsnp, name='rs1234')
        rs1235 = gene(namespace=dbsnp, name='rs1235')

        rs1234_tuple = graph.add_node_from_data(rs1234)
        rs1235_tuple = graph.add_node_from_data(rs1235)

        rs1234_hash = hash_node(rs1234_tuple)
        rs1235_hash = hash_node(rs1235_tuple)

        self.manager.insert_graph(graph, store_parts=True)

        rs1234_lookup = self.manager.get_node_by_hash(rs1234_hash)
        self.assertIsNotNone(rs1234_lookup)
        self.assertEqual('Gene', rs1234_lookup.type)
        self.assertEqual('g(dbSNP:rs1234)', rs1234_lookup.bel)
        self.assertEqual(rs1234_hash, rs1234_lookup.sha512)
        self.assertIsNotNone(rs1234_lookup.namespace_entry)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
FUSION: {
                PARTNER_5P: {CONCEPT: {NAMESPACE: 'HGNC', NAME: 'TMPRSS2'}},
                PARTNER_3P: {CONCEPT: {NAMESPACE: 'HGNC', NAME: 'ERG'}},
                RANGE_5P: {
                    FUSION_MISSING: '?'
                },
                RANGE_3P: {
                    FUSION_REFERENCE: 'c',
                    FUSION_START: 312,
                    FUSION_STOP: 5034
                }
            }
        }
        self.assertEqual(expected_dict, result.asDict())

        expected_node = gene_fusion(gene('HGNC', 'TMPRSS2'), gene('HGNC', 'ERG'), range_3p=fusion_range('c', 312, 5034))
        self.assert_has_node(expected_node)

        self.assertEqual('g(fus(HGNC:TMPRSS2, "?", HGNC:ERG, "c.312_5034"))', self.graph.node_to_bel(expected_node))
github pybel / pybel / tests / test_struct / test_transformations / test_induction.py View on Github external
import unittest

from pybel import BELGraph
from pybel.constants import (
    CITATION_AUTHORS, CITATION_REFERENCE, CITATION_TYPE, CITATION_TYPE_PUBMED,
)
from pybel.dsl import BaseEntity, gene, protein, rna
from pybel.struct.mutation.expansion import expand_upstream_causal
from pybel.struct.mutation.induction import get_subgraph_by_annotation_value
from pybel.struct.mutation.induction.citation import get_subgraph_by_authors, get_subgraph_by_pubmed
from pybel.struct.mutation.induction.paths import get_nodes_in_all_shortest_paths, get_subgraph_by_all_shortest_paths
from pybel.struct.mutation.induction.upstream import get_upstream_causal_subgraph
from pybel.struct.mutation.induction.utils import get_subgraph_by_induction
from pybel.testing.utils import n

trem2_gene = gene(namespace='HGNC', name='TREM2')
trem2_rna = rna(namespace='HGNC', name='TREM2')
trem2_protein = protein(namespace='HGNC', name='TREM2')


class TestGraphMixin(unittest.TestCase):
    """A mixin to enable testing nodes and edge membership in the graph."""

    def assert_in_edge(self, source, target, graph):
        """Assert the edge is in the graph.

        :param source:
        :param target:
        :type graph: pybel.BELGraph
        :rtype: bool
        """
        self.assertIn(target, graph[source])
github pybel / pybel / tests / test_struct / test_transformations / test_collapse.py View on Github external
from pybel.dsl import gene, mirna, pathology, pmod, protein, rna
from pybel.struct.mutation.collapse import (
    collapse_all_variants, collapse_nodes, collapse_to_genes, surviors_are_inconsistent,
)
from pybel.testing.utils import n

HGNC = 'HGNC'
GO = 'GO'
CHEBI = 'CHEBI'

g1 = gene(HGNC, '1')
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."""