Example #1
0
 def test_no_correlation(self):
     """Test the ``noCorrelation`` relation."""
     statement = 'r(HGNC:X) noCorrelation r(HGNC:Y)'
     self.parser.relation.parseString(statement)
     source = Rna('HGNC', 'X')
     target = Rna('HGNC', 'Y')
     self.assert_has_two_way_edge(source, target, NO_CORRELATION)
 def test_rna_fusion_specified(self):
     node = RnaFusion(partner_5p=Rna(namespace='HGNC', name='TMPRSS2'),
                      range_5p=EnumeratedFusionRange('r', 1, 79),
                      partner_3p=Rna(namespace='HGNC', name='ERG'),
                      range_3p=EnumeratedFusionRange('r', 312, 5034))
     self.assertEqual(
         'r(fus(HGNC:TMPRSS2, "r.1_79", HGNC:ERG, "r.312_5034"))',
         str(node))
Example #3
0
    def test_overlay(self):
        """Test overlaying data in a BEL graph."""
        g = BELGraph()

        g1 = Gene(HGNC, 'a')
        g2 = Gene(HGNC, 'b')
        g3 = Gene(HGNC, 'c')
        g4 = Gene(HGNC, 'd')
        r1 = Rna(HGNC, 'e')
        p1 = Protein(HGNC, 'f')

        g.add_node_from_data(g1)
        g.add_node_from_data(g2)
        g.add_node_from_data(g3)
        g.add_node_from_data(g4)
        g.add_node_from_data(r1)
        g.add_node_from_data(p1)

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

        label = 'dgxp'

        overlay_type_data(g, {
            'a': 1,
            'b': 2,
            'c': -1
        },
                          Gene,
                          HGNC,
                          label=label,
                          impute=0)

        for node in g1, g2, g3, g4:
            self.assertIn(label, g.nodes[node])

        for node in r1, p1:
            self.assertNotIn(label, g.nodes[node])

        self.assertEqual(1, g.nodes[g1][label])
        self.assertEqual(2, g.nodes[g2][label])
        self.assertEqual(-1, g.nodes[g3][label])
        self.assertEqual(0, g.nodes[g4][label])
Example #4
0
    def test_get_tf_pairs(self):
        """Test iterating over transcription factor pairs."""
        graph = BELGraph()
        p1, p2, p3 = (Protein('test', str(i)) for i in range(1, 4))
        r4, r5, r6 = (Rna('test', str(j)) for j in range(4, 7))

        g4 = r4.get_gene()
        self.assertIsNotNone(g4)
        g5 = r5.get_gene()
        self.assertIsNotNone(g5)

        c14, c25 = ComplexAbundance([p1, g4]), ComplexAbundance([p2, g5])
        _tf_up(graph, p1, r4)
        _tf_down(graph, p2, r5)
        graph.add_correlation(p3, r6, citation=n(), evidence=n())

        self.assertEqual({p1, p2, p3, r4, r5, r6, g4, g5, c14, c25},
                         set(graph))

        expected_edges = [
            (c14, r4),
            (p1, c14),
            (g4, c14),
            (c25, r5),
            (p2, c25),
            (g5, c25),
            (p3, r6),
            (r6, p3),
        ]
        sorted_expected_edges = sorted(expected_edges, key=_bel_pair_key)
        sorted_actual_edges = sorted(graph.edges(), key=_bel_pair_key)

        self.assertEqual(sorted_expected_edges, sorted_actual_edges)

        pairs = set(get_tf_pairs(graph))
        expected_pairs = {(p1, r4, +1), (p2, r5, -1)}
        self.assertEqual(expected_pairs, pairs)
Example #5
0
# -*- coding: utf-8 -*-
"""Tests for PyNPA."""

import unittest

import pandas as pd

from pybel import BELGraph
from pybel.dsl import ComplexAbundance, Gene, Protein, Rna
from pybel.io.pynpa import to_npa_dfs, to_npa_layers
from pybel.struct.getters import get_tf_pairs
from pybel.testing.utils import n

g1 = Gene('hgnc', '1')
r1 = Rna('hgnc', '1')
p1 = Protein('hgnc', '1')
g2 = Gene('hgnc', '2')
r2 = Rna('hgnc', '2')
p2 = Protein('hgnc', '2')
g3 = Gene('hgnc', '3')
p3 = Protein('hgnc', '3')


class TestPyNPA(unittest.TestCase):
    """Tests for PyNPA."""
    def setUp(self) -> None:
        """Set up a small test graph."""
        self.graph = BELGraph()
        self.graph.add_increases(ComplexAbundance([p1, g2]),
                                 r2,
                                 citation=n(),
 def test_rna_fusion_unspecified(self):
     node = RnaFusion(
         partner_5p=Rna(namespace='HGNC', name='TMPRSS2'),
         partner_3p=Rna(namespace='HGNC', name='ERG'),
     )
     self.assertEqual('r(fus(HGNC:TMPRSS2, "?", HGNC:ERG, "?"))', str(node))
Example #7
0
import unittest

from pybel import BELGraph
from pybel.constants import (
    ASSOCIATION, DECREASES, DIRECTLY_INCREASES, INCREASES, POSITIVE_CORRELATION,
)
from pybel.dsl import Abundance, Gene, MicroRna, Pathology, Protein, Rna
from pybel.testing.utils import n
from pybel_tools.mutation.collapse import collapse_to_protein_interactions

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

g1 = Gene(namespace=HGNC, name='1')
r1 = Rna(namespace=HGNC, name='1')
p1 = Protein(HGNC, name='1')

g2 = Gene(HGNC, name='2')
r2 = Rna(HGNC, name='2')
p2 = Protein(HGNC, name='2')

g3 = Gene(namespace=HGNC, name='3')
r3 = Rna(namespace=HGNC, name='3')
p3 = Protein(namespace=HGNC, name='3')

g4 = Gene(namespace=HGNC, name='4')
m4 = MicroRna(namespace=HGNC, name='4')

a5 = Abundance(namespace=CHEBI, name='5')
p5 = Pathology(namespace=GO, name='5')
Example #8
0
)

bcr_jak2_protein_fusion = ProteinFusion(
    partner_5p=Protein('HGNC', 'BCR'),
    range_5p=EnumeratedFusionRange('p', '?', 1875),
    partner_3p=Protein('HGNC', 'JAK2'),
    range_3p=EnumeratedFusionRange('p', 2626, '?')
)

chchd4_aifm1_protein_fusion = ProteinFusion(
    Protein('HGNC', 'CHCHD4'),
    Protein('HGNC', 'AIFM1')
)

bcr_jak2_rna_fusion = RnaFusion(
    partner_5p=Rna('HGNC', 'BCR'),
    range_5p=EnumeratedFusionRange('r', '?', 1875),
    partner_3p=Rna('HGNC', 'JAK2'),
    range_3p=EnumeratedFusionRange('r', 2626, '?')
)

chchd4_aifm1_rna_fusion = RnaFusion(
    partner_5p=Rna('HGNC', 'CHCHD4'),
    partner_3p=Rna('HGNC', 'AIFM1')
)

tmprss2_erg_rna_fusion = RnaFusion(
    partner_5p=Rna('HGNC', 'TMPRSS2'),
    range_5p=EnumeratedFusionRange('r', 1, 79),
    partner_3p=Rna('HGNC', 'ERG'),
    range_3p=EnumeratedFusionRange('r', 312, 5034)
Example #9
0
def _rela(x, y=None):
    return {RELATION: x, OBJECT: activity(y)}


def _assoc(y):
    return {RELATION: ASSOCIATION, 'association_type': y}


a1 = Abundance('CHEBI', '1')
p1 = Protein('HGNC', '1')
pf1 = Protein('INTERPRO', '1')
d1 = Pathology('MESH', '1')
b1 = BiologicalProcess('GO', '1')
b2 = BiologicalProcess('GO', '2')
m1 = MicroRna('MIRBASE', '1')
r1 = Rna('HGNC', '1')
r2 = Rna('HGNC', '2')
nca1 = NamedComplexAbundance('FPLX', '1')
pop1 = Population('taxonomy', '1')

p2 = Protein('HGNC', identifier='9236')
p3 = Protein('HGNC', identifier='9212')
r3 = p3.get_rna()
g3 = r3.get_gene()

c1 = ComplexAbundance([p2, g3])
c2 = ComplexAbundance([p1, p2])
c3 = ComplexAbundance([a1, p2])

converters_true_list = [
    (PartOfNamedComplexConverter, p1, nca1, _rel(PART_OF), ('HGNC:1', 'partOf',
Example #10
0
tmprss2_erg_protein_fusion = ProteinFusion(
    partner_5p=Protein('HGNC', 'TMPRSS2'),
    range_5p=EnumeratedFusionRange('p', 1, 79),
    partner_3p=Protein('HGNC', 'ERG'),
    range_3p=EnumeratedFusionRange('p', 312, 5034))

bcr_jak2_protein_fusion = ProteinFusion(
    partner_5p=Protein('HGNC', 'BCR'),
    range_5p=EnumeratedFusionRange('p', '?', 1875),
    partner_3p=Protein('HGNC', 'JAK2'),
    range_3p=EnumeratedFusionRange('p', 2626, '?'))

chchd4_aifm1_protein_fusion = ProteinFusion(Protein('HGNC', 'CHCHD4'),
                                            Protein('HGNC', 'AIFM1'))

bcr_jak2_rna_fusion = RnaFusion(partner_5p=Rna('HGNC', 'BCR'),
                                range_5p=EnumeratedFusionRange('r', '?', 1875),
                                partner_3p=Rna('HGNC', 'JAK2'),
                                range_3p=EnumeratedFusionRange('r', 2626, '?'))

chchd4_aifm1_rna_fusion = RnaFusion(partner_5p=Rna('HGNC', 'CHCHD4'),
                                    partner_3p=Rna('HGNC', 'AIFM1'))

tmprss2_erg_rna_fusion = RnaFusion(partner_5p=Rna('HGNC', 'TMPRSS2'),
                                   range_5p=EnumeratedFusionRange('r', 1, 79),
                                   partner_3p=Rna('HGNC', 'ERG'),
                                   range_3p=EnumeratedFusionRange(
                                       'r', 312, 5034))
tmprss2_erg_rna_fusion_unspecified = RnaFusion(partner_5p=Rna(
    'HGNC', 'TMPRSS2'),
                                               partner_3p=Rna('HGNC', 'ERG'))