How to use the pybel.dsl.rna 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_io / test_spia.py View on Github external
def test_update_matrix_expression(self):
        """Test updating the matrix with RNA expression."""
        sub = protein(namespace='HGNC', name='A', identifier='1')
        obj = rna(namespace='HGNC', name='B', identifier='2')

        index = {'A', 'B'}

        test_dict = {}

        test_matrix = DataFrame(0, index=index, columns=index)

        test_dict["expression"] = test_matrix

        update_spia_matrices(test_dict, sub, obj, {'relation': 'increases'})

        self.assertEqual(test_dict["expression"]['A']['B'], 1)
        self.assertEqual(test_dict["expression"]['A']['A'], 0)
        self.assertEqual(test_dict["expression"]['B']['A'], 0)
        self.assertEqual(test_dict["expression"]['B']['B'], 0)
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
RANGE_5P: {
                    FUSION_REFERENCE: 'r',
                    FUSION_START: 1,
                    FUSION_STOP: 79,
                },
                RANGE_3P: {
                    FUSION_REFERENCE: 'r',
                    FUSION_START: 312,
                    FUSION_STOP: 5034,
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        expected_node = rna_fusion(
            rna('HGNC', 'TMPRSS2'),
            rna('HGNC', 'ERG'),
            fusion_range('r', 1, 79),
            fusion_range('r', 312, 5034)
        )
        self.assert_has_node(expected_node)

        self.assertEqual('r(fus(HGNC:TMPRSS2, "r.1_79", HGNC:ERG, "r.312_5034"))',
                         self.graph.node_to_bel(expected_node))
github pybel / pybel / tests / test_struct / test_transformations / test_infererence_central_dogma.py View on Github external
# -*- coding: utf-8 -*-

"""Tests for inference of central dogma."""

import unittest

from pybel import BELGraph
from pybel.constants import FUNCTION, PROTEIN
from pybel.dsl import gene, hgvs, protein, protein_fusion, rna, rna_fusion
from pybel.struct.mutation import infer_central_dogma, prune_central_dogma
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 TestProcessing(unittest.TestCase):
    """Test inference of the central dogma."""

    def assertInGraph(self, node, graph):
        """Assert the node is in the graph.

        :type node: pybel.dsl.BaseEntity
        :type graph: pybel.BELGraph
        :rtype: bool
        """
        self.assertTrue(graph.has_node_with_data(node))

    def assertNotInGraph(self, node, graph):
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
FUSION_REFERENCE: 'r',
                    FUSION_START: '?',
                    FUSION_STOP: 1875,
                },
                RANGE_3P: {
                    FUSION_REFERENCE: 'r',
                    FUSION_START: 2626,
                    FUSION_STOP: '?',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        expected_node = rna_fusion(
            rna('HGNC', 'BCR'),
            rna('HGNC', 'JAK2'),
            fusion_range('r', '?', 1875),
            fusion_range('r', 2626, '?'),
        )
        self.assert_has_node(expected_node)
        self.assertEqual('r(fus(HGNC:BCR, "r.?_1875", HGNC:JAK2, "r.2626_?"))', self.graph.node_to_bel(expected_node))
github pybel / pybel / tests / test_struct / test_transformations / test_collapse.py View on Github external
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},
            3: {4},
github pybel / pybel / tests / test_struct / test_transformations / test_infererence_central_dogma.py View on Github external
def test_no_infer_rna_fusion(self):
        """Test that no RNA nor gene is inferred from a protein fusion node."""
        partner5p = rna(n(), n())
        partner3p = rna(n(), n())

        p = rna_fusion(partner_3p=partner3p, partner_5p=partner5p)

        graph = BELGraph()
        graph.add_node_from_data(p)

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

        infer_central_dogma(graph)

        self.assertEqual(1, graph.number_of_nodes())
        self.assertEqual(0, graph.number_of_edges())
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
RANGE_5P: {
                    FUSION_REFERENCE: 'r',
                    FUSION_START: '?',
                    FUSION_STOP: 1875,
                },
                RANGE_3P: {
                    FUSION_REFERENCE: 'r',
                    FUSION_START: 2626,
                    FUSION_STOP: '?',
                },
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        expected_node = rna_fusion(
            rna('HGNC', 'BCR'),
            rna('HGNC', 'JAK2'),
            fusion_range('r', '?', 1875),
            fusion_range('r', 2626, '?'),
        )
        self.assert_has_node(expected_node)
        self.assertEqual('r(fus(HGNC:BCR, "r.?_1875", HGNC:JAK2, "r.2626_?"))', self.graph.node_to_bel(expected_node))
github pybel / pybel / tests / test_parse / test_parse_bel.py View on Github external
def test_rna_variant_codingReference(self):
        """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)
github pybel / pybel / tests / test_parse / test_parse_bel_relations.py View on Github external
}
            },
            RELATION: TRANSLATED_TO,
            TARGET: {
                FUNCTION: PROTEIN,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'AKT1',
                },
            },
        }
        self.assertEqual(expected_result, result.asDict())

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

        source = rna(name='AKT1', namespace='HGNC')
        self.assertIn(source, self.graph)

        target = protein(name='AKT1', namespace='HGNC')
        self.assertIn(target, self.graph)

        self.assertEqual(1, self.graph.number_of_edges())
        self.assertTrue(self.graph.has_edge(source, target))

        key_data = self.parser.graph[source][target]
        self.assertEqual(1, len(key_data))

        key = list(key_data)[0]
        data = key_data[key]

        self.assertIn(RELATION, data)
        self.assertEqual(TRANSLATED_TO, data[RELATION])
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_MISSING: '?',
                }
            }
        }
        self.assertEqual(expected_dict, result.asDict())

        expected_node = rna_fusion(
            rna('HGNC', 'TMPRSS2'),
            rna('HGNC', 'ERG'),
        )
        self.assert_has_node(expected_node)
        self.assertEqual('r(fus(HGNC:TMPRSS2, "?", HGNC:ERG, "?"))', self.graph.node_to_bel(expected_node))