Exemple #1
0
    def test_update_matrix_pmods(self):
        """Test updating the matrix with multiple protein modifications."""
        sub = protein(namespace='HGNC', name='A', identifier='1')
        obj = protein(namespace='HGNC',
                      name='B',
                      identifier='2',
                      variants=[pmod('Ub'), pmod('Ph')])

        index = {'A', 'B'}

        test_dict = {}

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

        test_dict["activation_ubiquination"] = test_matrix
        test_dict["activation_phosphorylation"] = test_matrix

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

        self.assertEqual(test_dict["activation_ubiquination"]['A']['B'], 1)
        self.assertEqual(test_dict["activation_ubiquination"]['A']['A'], 0)
        self.assertEqual(test_dict["activation_ubiquination"]['B']['A'], 0)
        self.assertEqual(test_dict["activation_ubiquination"]['B']['B'], 0)

        self.assertEqual(test_dict["activation_phosphorylation"]['A']['B'], 1)
        self.assertEqual(test_dict["activation_phosphorylation"]['A']['A'], 0)
        self.assertEqual(test_dict["activation_phosphorylation"]['B']['A'], 0)
        self.assertEqual(test_dict["activation_phosphorylation"]['B']['B'], 0)
Exemple #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')))
Exemple #3
0
    def _help_test_negative_correlation_with_object_variant(self, x):
        statement = f'kin(p(FPLX:GSK3)) neg p(HGNC:MAPT,pmod({x}))'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SOURCE: {
                MODIFIER: ACTIVITY,
                EFFECT: activity_mapping['kin'],
                FUNCTION: PROTEIN,
                CONCEPT: {
                    NAMESPACE: 'FPLX',
                    NAME: 'GSK3',
                },
            },
            RELATION: NEGATIVE_CORRELATION,
            TARGET: {
                FUNCTION: PROTEIN,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'MAPT',
                },
                VARIANTS: [pmod('Ph')]
            }
        }
        self.assertEqual(expected_dict, result.asDict())

        sub = protein('FPLX', 'GSK3')
        self.assert_has_node(sub)

        obj = protein('HGNC', 'MAPT', variants=pmod('Ph'))
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=expected_dict[RELATION])
        self.assert_has_edge(obj, sub, relation=expected_dict[RELATION])
Exemple #4
0
    def test_positiveCorrelation_withSelfReferential(self):
        """
        3.2.2 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#XposCor
        Self-referential relationships"""
        statement = 'p(HGNC:GSK3B, pmod(P, S, 9)) pos act(p(HGNC:GSK3B), ma(kin))'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SUBJECT: {
                FUNCTION: PROTEIN,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'GSK3B',
                },
                VARIANTS: [pmod('Ph', position=9, code='Ser')]
            },
            RELATION: POSITIVE_CORRELATION,
            OBJECT: {
                MODIFIER: ACTIVITY,
                TARGET: {
                    FUNCTION: PROTEIN,
                    CONCEPT: {
                        NAMESPACE: 'HGNC',
                        NAME: 'GSK3B',
                    },
                },
                EFFECT: {
                    NAME: 'kin',
                    NAMESPACE: BEL_DEFAULT_NAMESPACE
                }
            },
        }
        self.assertEqual(expected_dict, result.asDict())

        subject_node = protein('HGNC',
                               'GSK3B',
                               variants=pmod('Ph', code='Ser', position=9))
        self.assert_has_node(subject_node)

        object_node = protein('HGNC', 'GSK3B')
        self.assert_has_node(object_node)

        self.assert_has_edge(subject_node,
                             object_node,
                             relation=expected_dict[RELATION])
        self.assert_has_edge(object_node,
                             subject_node,
                             relation=expected_dict[RELATION])
Exemple #5
0
def test_transphosphorylation():
    egfr = Agent('EGFR', db_refs={'HGNC': id('EGFR')})
    egfr_dimer = Agent('EGFR',
                       bound_conditions=[BoundCondition(egfr)],
                       db_refs={'HGNC': id('EGFR')})
    stmt = Transphosphorylation(egfr_dimer, 'Y', '1173')
    stmt_hash = stmt.get_hash(refresh=True)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert belgraph.number_of_nodes() == 3
    assert belgraph.number_of_edges() == 3

    egfr_dimer_node = complex_abundance([egfr_dsl, egfr_dsl])
    egfr_phos_node = egfr_dsl.with_variants(pmod('Ph', 'Tyr', 1173))
    edge_data = get_edge_data(belgraph, egfr_dimer_node, egfr_phos_node)
    assert edge_data == {
        pc.RELATION: pc.DIRECTLY_INCREASES,
        pc.ANNOTATIONS: {
            'stmt_hash': {
                stmt_hash: True
            },
            'uuid': {
                stmt.uuid: True
            },
            'belief': {
                stmt.belief: True
            },
        },
    }, edge_data
Exemple #6
0
    def test_update_matrix_inhibition_ubiquination(self):
        """Test updating the matrix with an inhibition ubiquitination."""
        sub = protein(namespace='HGNC', name='A', identifier='1')
        obj = protein(namespace='HGNC',
                      name='B',
                      identifier='2',
                      variants=[pmod('Ub')])

        index = {'A', 'B'}

        test_dict = {}

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

        # Initialize matrix correctly
        self.assertEqual(test_matrix.values.all(), 0)

        test_dict["inhibition_ubiquination"] = test_matrix

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

        self.assertEqual(test_dict["inhibition_ubiquination"]['A']['B'], 1)
        self.assertEqual(test_dict["inhibition_ubiquination"]['A']['A'], 0)
        self.assertEqual(test_dict["inhibition_ubiquination"]['B']['A'], 0)
        self.assertEqual(test_dict["inhibition_ubiquination"]['B']['B'], 0)
def test_gef():
    gef = Agent('SOS1',
                mods=[ModCondition('phosphorylation')],
                db_refs={'HGNC': '11187'})
    ras = Agent('KRAS', db_refs={'HGNC': '6407'})
    stmt = Gef(gef, ras)
    stmt_hash = stmt.get_hash(refresh=True)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph) == 3
    assert belgraph.number_of_edges() == 2

    gef_reference_node = protein(namespace='HGNC',
                                 name='SOS1',
                                 identifier='11187')
    gef_node = gef_reference_node.with_variants(pmod('Ph'))
    assert gef_reference_node in belgraph
    assert gef_node in belgraph
    assert kras_node in belgraph

    edge_data = get_edge_data(belgraph, gef_node, kras_node)
    edge = {
        pc.RELATION: pc.DIRECTLY_INCREASES,
        pc.SUBJECT: activity('gef'),
        pc.OBJECT: activity('gtp'),
        pc.ANNOTATIONS: {
            'stmt_hash': stmt_hash,
            'uuid': stmt.uuid,
            'belief': stmt.belief,
        },
    }
    assert edge_data == edge, edge_data
def test_complex_with_complex():
    grb2 = Agent('GRB2', db_refs={'HGNC': id('GRB2')})
    egfr_grb2 = Agent('EGFR', db_refs={'HGNC': id('EGFR')},
                      bound_conditions=[BoundCondition(grb2)])
    sos1_phos = Agent('SOS1',
                      mods=[ModCondition('phosphorylation', 'Y', '100')],
                      db_refs={'HGNC': id('SOS1')})
    stmt = Complex([sos1_phos, egfr_grb2])
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph) == 6
    assert belgraph.number_of_edges() == 5

    egfr_grb2_complex = complex_abundance([egfr_dsl, grb2_dsl])
    egfr_grb2_complex_sos1_phos_complex = complex_abundance([
        egfr_grb2_complex,
        sos1_dsl.with_variants(pmod('Ph', 'Tyr', 100))
    ])

    assert egfr_grb2_complex in belgraph
    for member in egfr_grb2_complex.members:
        assert member in belgraph

    assert egfr_grb2_complex_sos1_phos_complex in belgraph
    for member in egfr_grb2_complex_sos1_phos_complex.members:
        assert member in belgraph
Exemple #9
0
def test_gap():
    gap = Agent('RASA1', mods=[ModCondition('phosphorylation')],
                db_refs={'HGNC': '9871'})
    ras = Agent('KRAS', db_refs={'HGNC': '6407'})
    stmt = Gap(gap, ras)
    stmt_hash = stmt.get_hash(refresh=True)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph) == 3
    assert belgraph.number_of_edges() == 2

    gap_reference_node = protein(
        namespace='HGNC', name='RASA1', identifier='9871')
    gap_node = gap_reference_node.with_variants(pmod('Ph'))
    ras_node = protein(namespace='HGNC', name='KRAS', identifier='6407')

    assert gap_reference_node in belgraph
    assert gap_node in belgraph
    assert ras_node in belgraph
    edge_data = get_edge_data(belgraph, gap_node, ras_node)
    edge = {
        pc.RELATION: pc.DIRECTLY_DECREASES,
        pc.SUBJECT: activity('gap'),
        pc.OBJECT: activity('gtp'),
        pc.ANNOTATIONS: {
            'stmt_hash': {stmt_hash: True},
            'uuid': {stmt.uuid: True},
            'belief': {stmt.belief: True},
        },
    }
    assert edge_data == edge, edge_data
Exemple #10
0
def test_complex_with_complex():
    grb2 = Agent('GRB2', db_refs={'HGNC': id('GRB2')})
    egfr_grb2 = Agent('EGFR', db_refs={'HGNC': id('EGFR')},
                      bound_conditions=[BoundCondition(grb2)])
    sos1_phos = Agent('SOS1',
                      mods=[ModCondition('phosphorylation', 'Y', '100')],
                      db_refs={'HGNC': id('SOS1')})
    stmt = Complex([sos1_phos, egfr_grb2])
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph) == 6
    assert belgraph.number_of_edges() == 5

    egfr_grb2_complex = complex_abundance([egfr_dsl, grb2_dsl])
    egfr_grb2_complex_sos1_phos_complex = complex_abundance([
        egfr_grb2_complex,
        sos1_dsl.with_variants(pmod('Ph', 'Tyr', 100))
    ])

    assert egfr_grb2_complex in belgraph
    for member in egfr_grb2_complex.members:
        assert member in belgraph

    assert egfr_grb2_complex_sos1_phos_complex in belgraph
    for member in egfr_grb2_complex_sos1_phos_complex.members:
        assert member in belgraph
Exemple #11
0
 def as_bel(self) -> protein:
     parent = self.protein.as_bel()
     variant = pmod(
         name=self.modification_type.name,
         position=self.position,
         code=amino_acid_dict[self.residue.upper()],
     )
     return parent.with_variants(variant)
    def test_negativeCorrelation_withObjectVariant(self):
        """
        3.2.1 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#XnegCor
        Test phosphoralation tag"""
        statement = 'kin(p(FPLX:GSK3)) neg p(HGNC:MAPT,pmod(P))'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SUBJECT: {
                MODIFIER: ACTIVITY,
                EFFECT: {
                    NAME: 'kin',
                    NAMESPACE: BEL_DEFAULT_NAMESPACE
                },
                TARGET: {
                    FUNCTION: PROTEIN,
                    CONCEPT: {
                        NAMESPACE: 'FPLX',
                        NAME: 'GSK3',
                    },
                },
            },
            RELATION: NEGATIVE_CORRELATION,
            OBJECT: {
                FUNCTION: PROTEIN,
                CONCEPT: {
                    NAMESPACE: 'HGNC',
                    NAME: 'MAPT',
                },
                VARIANTS: [pmod('Ph')]
            }
        }
        self.assertEqual(expected_dict, result.asDict())

        sub = protein('FPLX', 'GSK3')
        self.assert_has_node(sub)

        obj = protein('HGNC', 'MAPT', variants=pmod('Ph'))
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=expected_dict[RELATION])
        self.assert_has_edge(obj, sub, relation=expected_dict[RELATION])
Exemple #13
0
    def _help_test_pmod_simple(self, statement):
        result = self.parser.parseString(statement)

        expected = {
            KIND: PMOD,
            IDENTIFIER: {
                NAMESPACE: BEL_DEFAULT_NAMESPACE,
                NAME: 'Ph',
            },
        }
        self.assertEqual(expected, pmod('Ph'))
        self.assertEqual(expected, result.asDict())
Exemple #14
0
    def _help_test_non_standard_namespace(self, statement):
        result = self.parser.parseString(statement)

        expected = {
            KIND: PMOD,
            IDENTIFIER: entity('MOD', 'PhosRes'),
            PMOD_CODE: 'Ser',
            PMOD_POSITION: 473
        }

        self.assertEqual(expected, pmod(name='PhosRes', namespace='MOD', code='Ser', position=473))
        self.assertEqual(expected, result.asDict())
Exemple #15
0
    def _help_test_pmod_with_residue(self, statement):
        result = self.parser.parseString(statement)

        expected = {
            KIND: PMOD,
            IDENTIFIER: {
                NAMESPACE: BEL_DEFAULT_NAMESPACE,
                NAME: 'Ph',
            },
            PMOD_CODE: 'Ser',
        }
        self.assertEqual(expected, pmod('Ph', code='Ser'))
        self.assertEqual(expected, result.asDict())
def test_transphosphorylation():
    egfr = Agent('EGFR', db_refs={'HGNC': id('EGFR')})
    egfr_dimer = Agent('EGFR', bound_conditions=[BoundCondition(egfr)],
                       db_refs={'HGNC': id('EGFR')})
    stmt = Transphosphorylation(egfr_dimer, 'Y', '1173')
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert belgraph.number_of_nodes() == 3
    assert belgraph.number_of_edges() == 3

    egfr_dimer_node = complex_abundance([egfr_dsl, egfr_dsl])
    egfr_phos_node = egfr_dsl.with_variants(pmod('Ph', 'Tyr', 1173))
    edge_data = get_edge_data(belgraph, egfr_dimer_node, egfr_phos_node)
    assert edge_data == {pc.RELATION: pc.DIRECTLY_INCREASES}
Exemple #17
0
    def _help_test_pmod_full(self, statement):
        result = self.parser.parseString(statement)

        expected = {
            KIND: PMOD,
            IDENTIFIER: {
                NAMESPACE: BEL_DEFAULT_NAMESPACE,
                NAME: 'Ph',
            },
            PMOD_CODE: 'Ser',
            PMOD_POSITION: 473
        }

        self.assertEqual(expected, pmod('Ph', code='Ser', position=473))
        self.assertEqual(expected, result.asDict())
Exemple #18
0
    def test_update_matrix_inhibition_phosphorylation(self):
        """Test updating the matrix with an inhibition phosphorylation."""
        sub = protein(namespace='HGNC', name='A', identifier='1')
        obj = protein(namespace='HGNC', name='B', identifier='2', variants=[pmod('Ph')])

        index = {'A', 'B'}

        test_dict = {}

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

        test_dict["inhibition_phosphorylation"] = test_matrix

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

        self.assertEqual(test_dict["inhibition_phosphorylation"]['A']['B'], 1)
        self.assertEqual(test_dict["inhibition_phosphorylation"]['A']['A'], 0)
        self.assertEqual(test_dict["inhibition_phosphorylation"]['B']['A'], 0)
        self.assertEqual(test_dict["inhibition_phosphorylation"]['B']['B'], 0)
Exemple #19
0
def test_complex_with_pmod():
    sos1_phos = Agent('SOS1',
                      mods=[ModCondition('phosphorylation', 'Y', '100')],
                      db_refs={'HGNC': id('SOS1')})
    grb2 = Agent('GRB2', db_refs={'HGNC': id('GRB2')})
    egfr = Agent('EGFR', db_refs={'HGNC': id('EGFR')})
    stmt = Complex([sos1_phos, grb2, egfr])
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert belgraph.number_of_nodes() == 5
    assert belgraph.number_of_edges() == 4

    egfr_grb2_sos_phos_tyr_100 = complex_abundance(
        [egfr_dsl, grb2_dsl,
         sos1_dsl.with_variants(pmod('Ph', 'Tyr', 100))])

    assert sos1_dsl in belgraph
    assert egfr_grb2_sos_phos_tyr_100 in belgraph
    for member in egfr_grb2_sos_phos_tyr_100.members:
        assert member in belgraph
def test_complex_with_pmod():
    sos1_phos = Agent('SOS1',
                      mods=[ModCondition('phosphorylation', 'Y', '100')],
                      db_refs={'HGNC': id('SOS1')})
    grb2 = Agent('GRB2', db_refs={'HGNC': id('GRB2')})
    egfr = Agent('EGFR', db_refs={'HGNC': id('EGFR')})
    stmt = Complex([sos1_phos, grb2, egfr])
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert belgraph.number_of_nodes() == 5
    assert belgraph.number_of_edges() == 4

    egfr_grb2_sos_phos_tyr_100 = complex_abundance([
        egfr_dsl,
        grb2_dsl,
        sos1_dsl.with_variants(pmod('Ph', 'Tyr', 100))
    ])

    assert sos1_dsl in belgraph
    assert egfr_grb2_sos_phos_tyr_100 in belgraph
    for member in egfr_grb2_sos_phos_tyr_100.members:
        assert member in belgraph
Exemple #21
0
    def test_negativeCorrelation_withObjectVariant(self):
        """
        3.2.1 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#XnegCor
        Test phosphoralation tag"""
        statement = 'kin(p(SFAM:"GSK3 Family")) neg p(HGNC:MAPT,pmod(P))'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SUBJECT: {
                MODIFIER: ACTIVITY,
                EFFECT: {
                    NAME: 'kin',
                    NAMESPACE: BEL_DEFAULT_NAMESPACE
                },
                TARGET: {
                    FUNCTION: PROTEIN,
                    NAMESPACE: 'SFAM',
                    NAME: 'GSK3 Family'
                }
            },
            RELATION: NEGATIVE_CORRELATION,
            OBJECT: {
                FUNCTION: PROTEIN,
                NAMESPACE: 'HGNC',
                NAME: 'MAPT',
                VARIANTS: [pmod('Ph')]
            }
        }
        self.assertEqual(expected_dict, result.asDict())

        sub = PROTEIN, 'SFAM', 'GSK3 Family'
        self.assertHasNode(sub)

        obj = PROTEIN, 'HGNC', 'MAPT', (PMOD, (BEL_DEFAULT_NAMESPACE, 'Ph'))
        self.assertHasNode(obj)

        self.assertHasEdge(sub, obj, relation=expected_dict[RELATION])
        self.assertHasEdge(obj, sub, relation=expected_dict[RELATION])
def test_gef():
    gef = Agent('SOS1', mods=[ModCondition('phosphorylation')],
                db_refs={'HGNC': '11187'})
    ras = Agent('KRAS', db_refs={'HGNC': '6407'})
    stmt = Gef(gef, ras)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph) == 3
    assert belgraph.number_of_edges() == 2

    gef_reference_node = protein(namespace='HGNC', name='SOS1')
    gef_node = gef_reference_node.with_variants(pmod('Ph'))
    assert gef_reference_node in belgraph
    assert gef_node in belgraph
    assert kras_node in belgraph

    edge_data = get_edge_data(belgraph, gef_node, kras_node)
    edge = {
        pc.RELATION: pc.DIRECTLY_INCREASES,
        pc.SUBJECT: activity('gef'),
        pc.OBJECT: activity('gtp')
    }
    assert edge_data == edge
def test_gap():
    gap = Agent('RASA1', mods=[ModCondition('phosphorylation')],
                db_refs={'HGNC': '9871'})
    ras = Agent('KRAS', db_refs={'HGNC': '6407'})
    stmt = Gap(gap, ras)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph) == 3
    assert belgraph.number_of_edges() == 2

    gap_reference_node = protein(namespace='HGNC', name='RASA1')
    gap_node = gap_reference_node.with_variants(pmod('Ph'))
    ras_node = protein(namespace='HGNC', name='KRAS')

    assert gap_reference_node in belgraph
    assert gap_node in belgraph
    assert ras_node in belgraph
    edge_data = get_edge_data(belgraph, gap_node, ras_node)
    edge = {
        pc.RELATION: pc.DIRECTLY_DECREASES,
        pc.SUBJECT: activity('gap'),
        pc.OBJECT: activity('gtp')
    }
    assert edge_data == edge
Exemple #24
0
 def test_protein_pmod(self):
     node = protein(name='PLCG1',
                    namespace='HGNC',
                    variants=[pmod(name='Ph', code='Tyr')])
     self.assertEqual('p(HGNC:PLCG1, pmod(Ph, Tyr))', str(node))
Exemple #25
0
from pybel import BELGraph
from pybel.constants import CITATION_REFERENCE, CITATION_TYPE, CITATION_TYPE_OTHER, HAS_VARIANT
from pybel.dsl import (
    abundance, activity, bioprocess, complex_abundance, gene, gmod, named_complex_abundance, pathology, pmod, protein,
    protein_fusion, protein_substitution, reaction, rna,
)

example_graph = BELGraph()

example_graph.namespace_url['HGNC'] = ''
example_graph.namespace_pattern['DBSNP'] = r'^rs\d+$'
example_graph.annotation_url['Species'] = ''
example_graph.annotation_pattern['Number'] = r'^\d+$'
example_graph.annotation_list['Confidence'] = {'High', 'Low'}

ptk2 = protein(namespace='HGNC', name='PTK2', variants=[pmod('Ph', 'Tyr', 925)])
mapk1 = protein(namespace='HGNC', name='MAPK1')
mapk3 = protein(namespace='HGNC', name='MAPK3')
grb2 = protein(namespace='HGNC', name='GRB2')
sos1 = protein(namespace='HGNC', name='SOS1')
ptk2_rgb2_sos1 = complex_abundance([mapk1, grb2, sos1])

ras_family = protein(namespace='SFAM', name='RAS Family')
pi3k_complex = named_complex_abundance(namespace='SFAM', name='p85/p110 PI3Kinase Complex')

kinase_activity = activity('kin')
catalytic_activity = activity('cat')
gtp_activity = activity('gtp')

c1 = '10446041'
e1 = "FAK also combines with, and may activate, phosphoinositide 3-OH kinase (PI 3-kinase), either directly or " \
from pybel.testing.utils import n
from pybel_tools.assembler.reified_graph.assembler import (
    ACTIVATES,
    DEGRADATES,
    FRAGMENTS,
    INCREASES_ABUNDANCE,
    PHOSPHORYLATES,
    PROMOTES_TRANSLATION,
    REIF_OBJECT,
    REIF_SUBJECT,
    reify_bel_graph,
)

cdk5 = protein('HGNC', 'CDK5', '1774')
gsk3b = protein('HGNC', 'GSK3B', '4617')
p_tau = protein('HGNC', 'MAPT', '6893', variants=pmod('Ph'))

# act(p(HGNC:FAS), ma(cat)) increases act(p(HGNC:CASP8), ma(cat))
fas = protein('HGNC', 'FAS', '11920')
casp8 = protein('HGNC', 'CASP8', '1509')

# a(CHEBI:oxaliplatin) increases a(MESHC:"Reactive Oxygen Species")
oxaliplatin = abundance('CHEBI', 'oxaliplatin', '31941')
reactive_o_species = abundance('MESH', 'Reactive Oxygen Species', 'D017382')

# p(HGNC:MYC) decreases r(HGNC:CCNB1)


@unittest.skip('Seems like tests were not working well at first')
class TestAssembleReifiedGraph(unittest.TestCase):
    """Test assembly of reified graphs."""
Exemple #27
0
    bioprocess,
    gene,
    gmod,
    named_complex_abundance,
    pathology,
    pmod,
    protein_fusion,
    protein_substitution,
    reaction,
    rna,
)
from pybel.utils import citation_dict

example_graph = BELGraph()

ptk2 = Protein(namespace='hgnc', name='PTK2', variants=pmod('Ph', 'Tyr', 925))
mapk1 = Protein(namespace='hgnc', name='MAPK1')
mapk3 = Protein(namespace='hgnc', name='MAPK3')
grb2 = Protein(namespace='hgnc', name='GRB2')
sos1 = Protein(namespace='hgnc', name='SOS1')
ptk2_rgb2_sos1 = ComplexAbundance([mapk1, grb2, sos1])

ras_family = Protein(namespace='fplx', name='RAS')
pi3k_complex = named_complex_abundance(namespace='fplx',
                                       name='p85/p110 PI3Kinase Complex')

kinase_activity = activity('kin')
catalytic_activity = activity('cat')
gtp_activity = activity('gtp')

c1 = '10446041'
Exemple #28
0
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
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')

Exemple #29
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):
Exemple #30
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):
Exemple #31
0
def add_simple_edge(graph, u, v, relation_type):
    """Add corresponding edge type to BEL graph.

    :param pybel.BELGraph graph: BEL Graph
    :param u: source node
    :param v: target node
    :param list relation_type: source ID, target ID and relation types
    """
    # Check if multiple relation subtypes present
    if isinstance(relation_type, list):

        # Check if protein modification is a relation subtype
        if relation_type[1] in {
                'phosphorylation', 'glycosylation', 'ubiquitination',
                'methylation'
        }:

            # If the object is a gene, miRNA, RNA, or protein, add protein modification
            if isinstance(v, CentralDogma):
                v = v.with_variants(pmod(KEGG_MODIFICATIONS[relation_type[1]]))

            # Add increases edge if pmod subtype is coupled with activation subtype
            if relation_type[0] == 'activation':
                graph.add_increases(
                    u,
                    v,
                    citation=KEGG_CITATION,
                    evidence='Extracted from KEGG',
                    subject_modifier=activity() if isinstance(
                        u, ACTIVITY_ALLOWED_MODIFIERS) else None,
                    # Add the activity function if subject is one of the following nodes (BEL 2.0 specifications)
                    annotations={},
                )
                return

            # Add decreases edge if pmod subtype is coupled with inhibition subtype
            elif relation_type[0] == 'inhibition':
                graph.add_decreases(
                    u,
                    v,
                    citation=KEGG_CITATION,
                    evidence='Extracted from KEGG',
                    subject_modifier=activity() if isinstance(
                        u, ACTIVITY_ALLOWED_MODIFIERS) else None,
                    # Add the activity function if subject is one of the following nodes (BEL 2.0 specifications)
                    annotations={},
                )
                return

            # Found multiple relationship which cannot be combined into one logic
            # (e.g., ['inhibition', 'indirect effect'])
            else:
                # Create all relationships in the list
                for relation in relation_type:
                    add_simple_edge(graph, u, v, relation)

                return

        # Found multiple relationship which cannot be combined into one logic (e.g., ['inhibition', 'indirect effect'])
        else:
            # Create all relationships in the list
            for relation in relation_type:
                add_simple_edge(graph, u, v, relation)

            return
    """Handle differently the relationships"""
    # If only one pmod relation subtype
    if relation_type in {
            'phosphorylation', 'glycosylation', 'ubiquitination', 'methylation'
    }:

        # If the object is a gene, miRNA, RNA, or protein, add protein modification
        if isinstance(v, CentralDogma):
            v = v.with_variants(pmod(KEGG_MODIFICATIONS[relation_type]))
        graph.add_increases(
            u,
            v,
            citation=KEGG_CITATION,
            evidence='Extracted from KEGG',
            subject_modifier=activity() if isinstance(
                u, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )
        return

    # Subject activity decreases protein modification (i.e. dephosphorylation) of object
    elif relation_type == 'dephosphorylation':

        # If the object is a gene, miRNA, RNA, or protein, add protein modification
        if isinstance(v, CentralDogma):
            v = v.with_variants(pmod('Ph'))
        graph.add_decreases(
            u,
            v,
            citation=KEGG_CITATION,
            evidence='Extracted from KEGG',
            subject_modifier=activity() if isinstance(
                u, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )
        return

    # Subject increases activity of object
    elif relation_type == 'activation':
        graph.add_increases(
            u,
            v,
            citation=KEGG_CITATION,
            evidence='Extracted from KEGG',
            object_modifier=activity() if isinstance(
                v, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )
        return

    # Catalytic activity of subject increases transformation of reactant(s) to product(s)
    elif relation_type in {'reversible', 'irreversible'}:
        graph.add_increases(
            u,
            v,
            citation=KEGG_CITATION,
            evidence='Extracted from KEGG',
            subject_modifier=activity('cat') if isinstance(
                u, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )
        return

    # Subject decreases activity of object
    elif relation_type == 'inhibition':
        graph.add_decreases(
            u,
            v,
            citation=KEGG_CITATION,
            evidence='Extracted from KEGG',
            object_modifier=activity() if isinstance(
                v, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )
        return

    # Indirect effect and binding/association are noted to be equivalent relation types
    elif relation_type in {
            'indirect effect', 'binding/association', 'compound'
    }:
        graph.add_association(u,
                              v,
                              citation=KEGG_CITATION,
                              evidence='Extracted from KEGG',
                              annotations={})
        return

    # Subject increases expression of object
    elif relation_type == 'expression':

        # Expression object is converted to RNA abundance
        if isinstance(v, CentralDogma):
            v = v.get_rna()
        graph.add_increases(u,
                            v,
                            citation=KEGG_CITATION,
                            evidence='Extracted from KEGG',
                            annotations={})
        return

    # Subject decreases expression of object
    elif relation_type == 'repression':

        # Repression object is converted to RNA abundance
        if isinstance(v, CentralDogma):
            v = v.get_rna()
        graph.add_decreases(u,
                            v,
                            citation=KEGG_CITATION,
                            evidence='Extracted from KEGG',
                            annotations={})
        return

    elif relation_type in {
            'dissociation', 'hidden compound', 'missing interaction',
            'state change'
    }:
        return

    raise ValueError(
        f'Unexpected relation type {relation_type} between {u} and {v}')
Exemple #32
0
import networkx as nx
import pybel.constants as pc
from pybel.dsl import abundance, activity, bioprocess, \
    complex_abundance, hgvs, pmod, protein, reaction

from indra.assemblers.pybel import assembler as pa
from indra.databases import hgnc_client
from indra.statements import *


def id(gene_name):
    return hgnc_client.get_hgnc_id(gene_name)


phos_dsl = pmod('Ph', 'Ser', 218)
ub_dsl = pmod('Ub', 'Ser', 218)
egfr_phos_dsl = pmod('Ph', 'Tyr', 1173)

braf_dsl = protein(namespace='HGNC', name='BRAF', identifier='1097')
map2k1_dsl = protein(namespace='HGNC', name='MAP2K1', identifier='6840')
tp53_dsl = protein(namespace='HGNC', name='TP53', identifier='11998')
mdm2_dsl = protein(namespace='HGNC', name='MDM2', identifier='6973')
egfr_dsl = protein(namespace='HGNC', name='EGFR', identifier='3236')

chebi_17534 = abundance(namespace='CHEBI', name='D-glucose',
                        identifier='17634')
chebi_4170 = abundance(namespace='CHEBI', name='D-glucopyranose 6-phosphate',
                       identifier='4170')
chebi_17534_to_4170 = reaction(chebi_17534, chebi_4170)
Exemple #33
0
    Protein('HGNC', 'CXCR3'),
    Abundance('CHEBI', 'acrolein'),
    Protein('HGNC', 'IDO2'),
    Pathology('MESHD', 'Pulmonary Disease, Chronic Obstructive'),
    Protein('HGNC', 'IFNG'),
    Protein('HGNC', 'TNFRSF4'),
    Protein('HGNC', 'CTLA4'),
    Protein('HGNC', 'GZMA'),
    Protein('HGNC', 'PRF1'),
    Protein('HGNC', 'TNF'),
    Protein('SFAM', 'Chemokine Receptor Family'),
    ComplexAbundance([Protein('HGNC', 'CD8A'),
                      Protein('HGNC', 'CD8B')]),
    ComplexAbundance([Protein('HGNC', 'CD8A'),
                      Protein('HGNC', 'CD8B')]),
    Protein('HGNC', 'PLCG1', variants=pmod('Ph', 'Tyr')),
    Protein('EGID', '21577'),
}

jgif_expected_edges = [
    (calcium, calcineurin_complex, {
        RELATION: DIRECTLY_INCREASES,
        EVIDENCE:
        'NMDA-mediated influx of calcium led to activated of the calcium-dependent phosphatase calcineurin and the subsequent dephosphorylation and activation of the protein-tyrosine phosphatase STEP',
        CITATION: {
            CITATION_TYPE: CITATION_TYPE_PUBMED,
            CITATION_REFERENCE: '12483215'
        },
        OBJECT: {
            MODIFIER: ACTIVITY,
            EFFECT: {
import networkx as nx

import pybel.constants as pc
from indra.assemblers.pybel import assembler as pa
from indra.databases import hgnc_client
from indra.statements import *
from pybel.dsl import abundance, activity, bioprocess, complex_abundance, hgvs, pmod, protein, reaction


def id(gene_name):
    return hgnc_client.get_hgnc_id(gene_name)


phos_dsl = pmod('Ph', 'Ser', 218)
ub_dsl = pmod('Ub', 'Ser', 218)
egfr_phos_dsl = pmod('Ph', 'Tyr', 1173)

braf_dsl = protein(namespace='HGNC', name='BRAF')
map2k1_dsl = protein(namespace='HGNC', name='MAP2K1')
tp53_dsl = protein(namespace='HGNC', name='TP53')
mdm2_dsl = protein(namespace='HGNC', name='MDM2')
egfr_dsl = protein(namespace='HGNC', name='EGFR')

chebi_17534 = abundance(namespace='CHEBI', name='17634')
chebi_4170 = abundance(namespace='CHEBI', name='4170')
chebi_17534_to_4170 = reaction(chebi_17534, chebi_4170)

grb2_dsl = protein(namespace='HGNC', name='GRB2')
sos1_dsl = protein(namespace='HGNC', name='SOS1')
sos1_phosphorylated_dsl = sos1_dsl.with_variants(pmod('Ph'))
kras_node = protein(namespace='HGNC', name='KRAS')