def test_simple_modification_no_evidence():
    braf = Agent('BRAF', db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_cat = Agent('BRAF', activity=ActivityCondition('catalytic', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt1 = Phosphorylation(braf, mek, 'S', '218')
    stmt2 = Phosphorylation(braf_kin, mek, 'S', '218')
    stmt3 = Ubiquitination(braf_cat, mek, 'S', '218')
    # Edge info for subject
    edge1 = None
    edge2 = activity('kin')
    edge3 = activity('cat')
    for stmt, modtuple, subj_edge in ((stmt1, phos_dsl, edge1),
                                      (stmt2, phos_dsl, edge2),
                                      (stmt3, ub_dsl, edge3)):
        pba = pa.PybelAssembler([stmt])
        belgraph = pba.make_model()
        assert len(belgraph.nodes()) == 3
        assert braf_dsl in belgraph
        map2k1_mod_dsl = map2k1_dsl.with_variants(modtuple)
        assert map2k1_mod_dsl in belgraph
        assert belgraph.number_of_edges() == 2
        edge_data = get_edge_data(belgraph, braf_dsl, map2k1_mod_dsl)
        assert edge_data.get(pc.SUBJECT) == subj_edge
        assert edge_data[pc.RELATION] == pc.INCREASES
Example #2
0
def add_simple_edge(graph: BELGraph, u, v, edge_types):
    """Add a simple edge into the graph."""
    if 'ACTIVATION' in edge_types:
        graph.add_increases(
            u,
            v,
            citation=REACTOME_CITATION,
            evidence='Extracted from Reactome',
            object_modifier=activity() if isinstance(
                v, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )

    elif 'INHIBITION' in edge_types:
        graph.add_decreases(
            u,
            v,
            citation=REACTOME_CITATION,
            evidence='Extracted from Reactome',
            object_modifier=activity() if isinstance(
                v, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )
    else:
        log.warning('edge type %s', edge_types)
Example #3
0
    def test_mixed_1(self):
        """Test mixed having location and something else."""
        self.graph.add_increases(
            Protein(namespace='HGNC', name='CDC42'),
            Protein(namespace='HGNC', name='PAK2'),
            evidence=
            """Summary: PAK proteins, a family of serine/threonine p21-activating kinases, include PAK1, PAK2,
         PAK3 and PAK4. PAK proteins are critical effectors that link Rho GTPases to cytoskeleton reorganization
         and nuclear signaling. They serve as targets for the small GTP binding proteins Cdc42 and Rac and have
         been implicated in a wide range of biological activities. PAK4 interacts specifically with the GTP-bound
         form of Cdc42Hs and weakly activates the JNK family of MAP kinases. PAK4 is a mediator of filopodia
         formation and may play a role in the reorganization of the actin cytoskeleton. Multiple alternatively
         spliced transcript variants encoding distinct isoforms have been found for this gene.""",
            citation={
                CITATION_DB: "Online Resource",
                CITATION_IDENTIFIER: "PAK4 Hs ENTREZ Gene Summary"
            },
            annotations={'Species': '9606'},
            subject_modifier=activity('gtp'),
            object_modifier=activity('kin'),
        )

        make_dummy_namespaces(self.manager, self.graph)
        make_dummy_annotations(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count())
        self.assertEqual(1, network.edges.count())

        edge = network.edges.first()
Example #4
0
    def test_mixed_2(self):
        """Tests both subject and object activity with location information as well."""
        self.graph.add_directly_increases(
            Protein(namespace='HGNC', name='HDAC4'),
            Protein(namespace='HGNC', name='MEF2A'),
            citation='10487761',
            evidence=
            """"In the nucleus, HDAC4 associates with the myocyte enhancer factor MEF2A. Binding of HDAC4 to
        MEF2A results in the repression of MEF2A transcriptional activation, a function that requires the
        deacetylase domain of HDAC4.""",
            annotations={'Species': '9606'},
            subject_modifier=activity('cat',
                                      location=Entity(namespace='GO',
                                                      name='nucleus')),
            object_modifier=activity('tscript',
                                     location=Entity(namespace='GO',
                                                     name='nucleus')))

        make_dummy_namespaces(self.manager, self.graph)
        make_dummy_annotations(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count())
        self.assertEqual(1, network.edges.count())

        edge = network.edges.first()
def test_activation():
    braf_no_act = Agent('BRAF', db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt1 = Activation(braf_no_act, mek)
    stmt2 = Activation(braf_kin, mek, 'kinase')
    edge1 = {
        pc.RELATION: pc.INCREASES,
        pc.OBJECT: {pc.MODIFIER: pc.ACTIVITY}
    }
    edge2 = {
        pc.RELATION: pc.INCREASES,
        pc.SUBJECT: activity('kin'),
        pc.OBJECT: activity('kin')
    }
    for stmt, edge in ((stmt1, edge1), (stmt2, edge2)):
        pba = pa.PybelAssembler([stmt])
        belgraph = pba.make_model()
        assert len(belgraph.nodes()) == 2
        assert braf_dsl in belgraph
        assert map2k1_dsl in belgraph
        assert belgraph.number_of_edges() == 1
        edge_data = get_first_edge_data(belgraph)
        assert edge_data == edge
Example #6
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
Example #7
0
def test_simple_modification_no_evidence():
    braf = Agent('BRAF', db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_cat = Agent('BRAF', activity=ActivityCondition('catalytic', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    map2k1 = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})  # MEK
    stmt1 = Phosphorylation(braf, map2k1, 'S', '218')
    stmt2 = Phosphorylation(braf_kin, map2k1, 'S', '218')
    stmt3 = Ubiquitination(braf_cat, map2k1, 'S', '218')
    # Edge info for subject
    edge1 = None
    edge2 = activity('kin')
    edge3 = activity('cat')
    for stmt, modtuple, subj_edge in ((stmt1, phos_dsl, edge1),
                                      (stmt2, phos_dsl, edge2),
                                      (stmt3, ub_dsl, edge3)):
        pba = pa.PybelAssembler([stmt])
        belgraph = pba.make_model()
        assert belgraph.number_of_nodes() == 3, belgraph.number_of_nodes()
        map2k1_mod_dsl = map2k1_dsl.with_variants(modtuple)
        assert set(belgraph) == {braf_dsl, map2k1_dsl, map2k1_mod_dsl}, \
            (set(belgraph), {braf_dsl, map2k1_dsl, map2k1_mod_dsl})
        assert belgraph.number_of_edges() == 2, belgraph.number_of_edges()
        assert belgraph.has_edge(map2k1_dsl, map2k1_mod_dsl)
        assert belgraph.has_edge(braf_dsl, map2k1_mod_dsl)
        edge_data = get_edge_data(belgraph, braf_dsl, map2k1_mod_dsl)
        assert edge_data[pc.RELATION] == pc.INCREASES
        assert edge_data.get(pc.SUBJECT) == subj_edge
Example #8
0
def test_inhibition():
    braf_kin = Agent('BRAF',
                     activity=ActivityCondition('kinase', True),
                     db_refs={
                         'HGNC': '1097',
                         'UP': 'P15056'
                     })
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt = Inhibition(braf_kin, mek, 'kinase')
    stmt_hash = stmt.get_hash(refresh=True)
    edge = {
        pc.RELATION: pc.DECREASES,
        pc.SUBJECT: activity('kin'),
        pc.OBJECT: activity('kin'),
        pc.ANNOTATIONS: {
            'stmt_hash': {
                stmt_hash: True
            },
            'uuid': {
                stmt.uuid: True
            },
            'belief': {
                stmt.belief: True
            },
        },
    }
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert belgraph.number_of_nodes() == 2, belgraph.number_of_nodes()
    assert braf_dsl in belgraph
    assert map2k1_dsl in belgraph
    assert belgraph.number_of_edges() == 1
    edge_data = get_first_edge_data(belgraph)
    assert edge_data == edge, edge_data
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_direct_activation():
    braf_no_act = Agent('BRAF', db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_kin = Agent('BRAF',
                     activity=ActivityCondition('kinase', True),
                     db_refs={
                         'HGNC': '1097',
                         'UP': 'P15056'
                     })
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt1_ev = Evidence(
        pmid='1234',
        epistemics={'direct': True},
    )
    stmt1 = Activation(braf_no_act, mek, evidence=stmt1_ev)
    stmt2 = Activation(braf_kin, mek, 'kinase', evidence=stmt1_ev)
    hash1 = stmt1.get_hash(refresh=True)
    hash2 = stmt2.get_hash(refresh=True)
    edge1 = {
        pc.RELATION: pc.DIRECTLY_INCREASES,
        pc.OBJECT: {
            pc.MODIFIER: pc.ACTIVITY
        },
        pc.EVIDENCE: 'No evidence text.',
        pc.CITATION: {
            pc.CITATION_DB: pc.CITATION_TYPE_PUBMED,
            pc.CITATION_IDENTIFIER: '1234',
        },
        pc.ANNOTATIONS: {
            'stmt_hash': hash1,
            'source_hash': stmt1_ev.get_source_hash(),
            'uuid': stmt1.uuid,
            'belief': stmt1.belief,
        },
    }
    edge2 = {
        pc.RELATION: pc.DIRECTLY_INCREASES,
        pc.SUBJECT: activity('kin'),
        pc.OBJECT: activity('kin'),
        pc.EVIDENCE: 'No evidence text.',
        pc.CITATION: {
            pc.CITATION_DB: pc.CITATION_TYPE_PUBMED,
            pc.CITATION_IDENTIFIER: '1234',
        },
        pc.ANNOTATIONS: {
            'stmt_hash': hash2,
            'source_hash': stmt1_ev.get_source_hash(),
            'uuid': stmt2.uuid,
            'belief': stmt2.belief,
        },
    }
    for stmt, expected_edge in ((stmt1, edge1), (stmt2, edge2)):
        pba = pa.PybelAssembler([stmt])
        belgraph = pba.make_model()
        assert belgraph.number_of_nodes() == 2, belgraph.number_of_nodes()
        assert braf_dsl in belgraph
        assert map2k1_dsl in belgraph
        assert belgraph.number_of_edges() == 1
        edge_data = get_first_edge_data(belgraph)
        assert expected_edge == edge_data, json.dumps(edge_data, indent=1)
Example #11
0
def test_activation():
    braf_no_act = Agent('BRAF', db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_kin = Agent('BRAF',
                     activity=ActivityCondition('kinase', True),
                     db_refs={
                         'HGNC': '1097',
                         'UP': 'P15056'
                     })
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt1 = Activation(braf_no_act, mek)
    stmt2 = Activation(braf_kin, mek, 'kinase')
    hash1 = stmt1.get_hash(refresh=True)
    hash2 = stmt2.get_hash(refresh=True)
    edge1 = {
        pc.RELATION: pc.INCREASES,
        pc.OBJECT: activity(),
        pc.ANNOTATIONS: {
            'stmt_hash': {
                hash1: True
            },
            'uuid': {
                stmt1.uuid: True
            },
            'belief': {
                stmt1.belief: True
            },
        },
    }
    edge2 = {
        pc.RELATION: pc.INCREASES,
        pc.SUBJECT: activity('kin'),
        pc.OBJECT: activity('kin'),
        pc.ANNOTATIONS: {
            'stmt_hash': {
                hash2: True
            },
            'uuid': {
                stmt2.uuid: True
            },
            'belief': {
                stmt2.belief: True
            },
        },
    }
    for stmt, edge in ((stmt1, edge1), (stmt2, edge2)):
        pba = pa.PybelAssembler([stmt])
        belgraph = pba.make_model()
        assert belgraph.number_of_nodes() == 2, belgraph.number_of_nodes()
        assert braf_dsl in belgraph
        assert map2k1_dsl in belgraph
        assert belgraph.number_of_edges() == 1
        edge_data = get_first_edge_data(belgraph)
        assert edge_data == edge, edge_data
Example #12
0
    def test_canonicalize_edge_info(self):
        c1 = self.add_edge(annotations={'Species': '9606'})

        c2 = self.add_edge(annotations={'Species': '9606'})

        c3 = self.add_edge(subject_modifier=activity('tport'), )

        c4 = self.add_edge(subject_modifier=activity(
            'tport', namespace=BEL_DEFAULT_NAMESPACE), )

        self.assertEqual(c1, c2)
        self.assertNotEqual(c1, c3)
        self.assertEqual(c3, c4)
Example #13
0
def add_simple_edge(graph: BELGraph, u: BaseEntity, v: BaseEntity, edge_types, uri_id):
    """Add simple edge to graph.

    :param graph: BEL Graph
    :param u: source
    :param v: target
    :param edge_types: edge type dict
    :param uri_id: citation URI
    """
    if 'Stimulation' in edge_types:
        graph.add_increases(
            u, v,
            citation=uri_id, evidence='Extracted from WikiPathways',
            object_modifier=activity() if isinstance(v, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )

    elif 'Inhibition' in edge_types:
        graph.add_decreases(
            u, v,
            citation=uri_id, evidence='Extracted from WikiPathways',
            object_modifier=activity() if isinstance(v, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )

    elif 'Catalysis' in edge_types:
        graph.add_increases(
            u, v,
            citation=uri_id, evidence='Extracted from WikiPathways',
            object_modifier=activity() if isinstance(v, ACTIVITY_ALLOWED_MODIFIERS) else None,
            annotations={},
        )

    elif 'DirectedInteraction' in edge_types:
        graph.add_regulates(
            u, v,
            citation=uri_id,
            evidence='Extracted from WikiPathways',
            annotations={
                'EdgeTypes': edge_types,
            },
        )

    elif 'Interaction' in edge_types:
        logger.debug('No interaction subtype for %s', str(uri_id))

    elif 'TranscriptionTranslation' in edge_types:
        graph.add_translation(u, v)

    else:
        logger.debug('No handled edge type %s', str(uri_id))
    def test_canonicalize_edge_info(self):
        c1 = self.add_edge(annotations={'Species': '9606'})

        c2 = self.add_edge(annotations={'Species': '9606'})

        c3 = self.add_edge(source_modifier=activity('tport'), )

        c4 = self.add_edge(
            source_modifier=activity(namespace='go',
                                     name='transporter activity',
                                     identifier='0005215'), )

        self.assertEqual(c1, c2)
        self.assertNotEqual(c1, c3)
        self.assertEqual(c3, c4)
def test_inhibition():
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt = Inhibition(braf_kin, mek, 'kinase')
    edge = {pc.RELATION: pc.DIRECTLY_DECREASES,
            pc.SUBJECT: activity('kin'),
            pc.OBJECT: activity('kin')}
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph.nodes()) == 2
    assert braf_dsl in belgraph
    assert map2k1_dsl in belgraph
    assert belgraph.number_of_edges() == 1
    edge_data = get_first_edge_data(belgraph)
    assert edge_data == edge
Example #16
0
    def test_subject_activity_custom(self, mock):
        p1_name = n()
        p2_name = n()
        dummy_activity_namespace = n()
        dummy_activity_name = n()

        self.graph.add_increases(Protein(name=p1_name, namespace='HGNC'),
                                 Protein(name=p2_name, namespace='HGNC'),
                                 evidence=n(),
                                 citation=n(),
                                 subject_modifier=activity(
                                     name=dummy_activity_name,
                                     namespace=dummy_activity_namespace))

        make_dummy_namespaces(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count())
        self.assertEqual(1, network.edges.count())

        kin_list = self.manager.session.query(NamespaceEntry).filter(
            NamespaceEntry.name == dummy_activity_name).all()
        self.assertEqual(1, len(kin_list))

        kin = list(kin_list)[0]
        self.assertEqual(dummy_activity_name, kin.name)
Example #17
0
    def test_subject_activity_default(self, mock):
        p1_name = n()
        p2_name = n()

        self.graph.add_increases(Protein(name=p1_name, namespace='HGNC'),
                                 Protein(name=p2_name, namespace='HGNC'),
                                 evidence=n(),
                                 citation=n(),
                                 subject_modifier=activity('kin'))

        make_dummy_namespaces(self.manager, self.graph)

        network = self.manager.insert_graph(self.graph)
        self.assertEqual(2, network.nodes.count(), msg='number of nodes')
        self.assertEqual(1, network.edges.count(), msg='number of edges')

        kin_list = self.manager.session.query(NamespaceEntry).filter(
            NamespaceEntry.name == 'kin').all()
        self.assertEqual(1,
                         len(kin_list),
                         msg='number of kinase NamespaceEntrys')

        kin = list(kin_list)[0]
        self.assertEqual('kin', kin.name)

        effects = self.manager.session.query(Property).join(
            NamespaceEntry).filter(Property.effect == kin)
        self.assertEqual(1, effects.count(), msg='number of effects')
Example #18
0
def test_bound_condition():
    egfr = Agent('EGFR', db_refs={'HGNC': id('EGFR')})
    grb2 = Agent('GRB2', db_refs={'HGNC': id('GRB2')})
    ras = Agent('KRAS', db_refs={'HGNC': '6407'})
    sos1_bound = Agent('SOS1', mods=[ModCondition('phosphorylation')],
                       bound_conditions=[BoundCondition(egfr), BoundCondition(grb2)],
                       db_refs={'HGNC': id('SOS1')})
    stmt = Gef(sos1_bound, ras)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph) == 6
    assert belgraph.number_of_edges() == 5
    # Don't bother to check the tuple, which is now generated by
    # PyBEL directly, but check the node data

    assert egfr_grb2_sos1_phos_complex_dsl in belgraph
    assert kras_node in belgraph
    assert (egfr_grb2_sos1_phos_complex_dsl, kras_node) in belgraph.edges()

    edge_data = (egfr_grb2_sos1_phos_complex_dsl, kras_node,
                 {
                     pc.RELATION: pc.DIRECTLY_INCREASES,
                     pc.OBJECT: activity('gtp')
                 })
    assert edge_data in belgraph.edges(data=True)
Example #19
0
    def test_p1_active(self):
        """cat(p(HGNC:HSD11B1)) increases deg(a(CHEBI:cortisol))"""
        g = BELGraph()

        u = protein(name='HSD11B1', namespace='HGNC')
        v = abundance(name='cortisol', namespace='CHEBI', identifier='17650')

        g.add_increases(
            u,
            v,
            citation={
                NAMESPACE: CITATION_TYPE_ONLINE, IDENTIFIER: 'https://www.ncbi.nlm.nih.gov/gene/3290'
            },
            evidence="Entrez Gene Summary: Human: The protein encoded by this gene is a microsomal enzyme that "
                     "catalyzes the conversion of the stress hormone cortisol to the inactive metabolite cortisone. "
                     "In addition, the encoded protein can catalyze the reverse reaction, the conversion of cortisone "
                     "to cortisol. Too much cortisol can lead to central obesity, and a particular variation in this "
                     "gene has been associated with obesity and insulin resistance in children. Two transcript "
                     "variants encoding the same protein have been found for this gene.",
            annotations={'Species': '9606'},
            source_modifier=activity('cat'),
            target_modifier=degradation(),
        )

        self.assertFalse(is_translocated(g, u))
        self.assertFalse(is_degraded(g, u))
        self.assertTrue(has_activity(g, u))

        self.assertFalse(is_translocated(g, v))
        self.assertTrue(is_degraded(g, v))
        self.assertFalse(has_activity(g, v))
Example #20
0
def test_modification_with_evidences():
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    evidence = Evidence(source_api='test', text='evidence text', pmid='1234', epistemics={
        'dummy': ['a', 'b'],
        'scalar': 'yes',
        'missing': None,
    })
    stmt = Phosphorylation(braf_kin, mek, 'S', '218', evidence=evidence)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert belgraph.number_of_nodes() == 3, belgraph.number_of_nodes()
    assert braf_dsl in belgraph
    map2k1_mod_dsl = map2k1_dsl.with_variants(phos_dsl)
    assert map2k1_mod_dsl in belgraph
    assert belgraph.number_of_edges() == 2
    edge_data = get_edge_data(belgraph, braf_dsl, map2k1_mod_dsl)
    assert edge_data.get(pc.SUBJECT) == activity('kin')
    assert edge_data[pc.RELATION] == pc.INCREASES
    assert edge_data.get(pc.EVIDENCE) == 'evidence text', edge_data
    assert edge_data[pc.CITATION] == {
        pc.CITATION_DB: pc.CITATION_TYPE_PUBMED,
        pc.CITATION_IDENTIFIER: '1234',
    }
    assert 'source_api' in edge_data[pc.ANNOTATIONS]
    assert 'test' in edge_data[pc.ANNOTATIONS]['source_api']
    assert 'source_id' not in edge_data[pc.ANNOTATIONS]
    assert 'source_hash' in edge_data[pc.ANNOTATIONS]
    assert 'dummy' in edge_data[pc.ANNOTATIONS]
    assert 'a' in edge_data[pc.ANNOTATIONS]['dummy']
    assert 'b' in edge_data[pc.ANNOTATIONS]['dummy']
    assert 'scalar' in edge_data[pc.ANNOTATIONS]
    assert 'yes' in edge_data[pc.ANNOTATIONS]['scalar']
    assert 'missing' not in edge_data[pc.ANNOTATIONS]
Example #21
0
def test_inhibition():
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt = Inhibition(braf_kin, mek, 'kinase')
    edge = {
        pc.RELATION: pc.DECREASES,
        pc.SUBJECT: activity('kin'),
        pc.OBJECT: activity('kin')
    }
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph.nodes()) == 2
    assert braf_dsl in belgraph
    assert map2k1_dsl in belgraph
    assert belgraph.number_of_edges() == 1
    edge_data = get_first_edge_data(belgraph)
    assert edge_data == edge
Example #22
0
def test_direct_activation():
    braf_no_act = Agent('BRAF', db_refs={'HGNC': '1097', 'UP': 'P15056'})
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    stmt1_ev = Evidence(
        pmid='1234',
        epistemics={'direct': True},
    )
    stmt1 = Activation(braf_no_act, mek, evidence=stmt1_ev)
    stmt2 = Activation(braf_kin, mek, 'kinase', evidence=stmt1_ev)
    edge1 = {
        pc.RELATION: pc.DIRECTLY_INCREASES,
        pc.OBJECT: {pc.MODIFIER: pc.ACTIVITY},
        pc.EVIDENCE: 'No evidence text.',
        pc.CITATION: {
            pc.CITATION_TYPE: pc.CITATION_TYPE_PUBMED,
            pc.CITATION_REFERENCE: '1234',
        },
    }
    edge2 = {
        pc.RELATION: pc.DIRECTLY_INCREASES,
        pc.SUBJECT: activity('kin'),
        pc.OBJECT: activity('kin'),
        pc.EVIDENCE: 'No evidence text.',
        pc.CITATION: {
            pc.CITATION_TYPE: pc.CITATION_TYPE_PUBMED,
            pc.CITATION_REFERENCE: '1234',
        },
    }
    for stmt, expected_edge in ((stmt1, edge1), (stmt2, edge2)):
        pba = pa.PybelAssembler([stmt])
        belgraph = pba.make_model()
        assert len(belgraph.nodes()) == 2
        assert braf_dsl in belgraph
        assert map2k1_dsl in belgraph
        assert belgraph.number_of_edges() == 1
        edge_data = get_first_edge_data(belgraph)
        assert expected_edge == edge_data
Example #23
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)
    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
Example #24
0
    def test_spia_matrix_complexes(self):
        """Test handling of complexes."""
        self.sialic_acid_graph.add_increases(
            sialic_acid_cd33_complex,
            trem2,
            citation=citation,
            annotations={'Species': '9606', 'Confidence': 'High'},
            evidence=evidence_1,
            target_modifier=activity(),
        )

        spia_dfs = to_spia_dfs(self.sialic_acid_graph)

        self.assertEqual(spia_dfs["activation"][cd33.name][trem2.name], 1)
Example #25
0
def test_increase_amount_tscript():
    tp53 = Agent('TP53', activity=ActivityCondition('transcription', True),
                 db_refs={'HGNC': '11998'})
    mdm2 = Agent('MDM2', db_refs={'HGNC': '6973'})

    stmt = IncreaseAmount(tp53, mdm2)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert belgraph.number_of_nodes() == 2, belgraph.number_of_nodes()
    assert mdm2_dsl in belgraph
    assert tp53_dsl in belgraph
    assert belgraph.number_of_edges() == 1
    edge_data = get_first_edge_data(belgraph)
    assert edge_data[pc.RELATION] == pc.INCREASES
    assert edge_data[pc.SUBJECT] == activity('tscript')
Example #26
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)
    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
Example #27
0
def test_increase_amount_tscript():
    tp53 = Agent('TP53', activity=ActivityCondition('transcription', True),
                 db_refs={'HGNC': '11998'})
    mdm2 = Agent('MDM2', db_refs={'HGNC': '6973'})

    stmt = IncreaseAmount(tp53, mdm2)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph.nodes()) == 2
    assert mdm2_dsl in belgraph
    assert tp53_dsl in belgraph
    assert belgraph.number_of_edges() == 1
    edge_data = get_first_edge_data(belgraph)
    assert edge_data[pc.RELATION] == pc.INCREASES
    assert edge_data[pc.SUBJECT] == activity('tscript')
Example #28
0
 def _add_to_graph(self, graph: BELGraph, source: BaseEntity,
                   target: BaseEntity) -> Set[str]:
     """Return the set of keys used to add these edges."""
     return {
         graph.add_regulates(
             source,
             target,
             citation=article.pubmed_id,
             evidence='From DrugBank',
             annotations={
                 'bio2bel': MODULE_NAME,
             },
             object_modifier=activity(),
         )
         for article in self.articles
     }
    def test_convert_phosphorylates(self):
        """Test the conversion of a BEL statement like ``act(p(X)) -> p(Y, pmod(Ph))."""
        bel_graph = BELGraph()
        bel_graph.add_directly_increases(
            cdk5,
            p_tau,
            evidence=n(),
            citation=n(),
            subject_modifier=activity('kin'),
        )

        r_edge = 0
        expected_reified_graph = self.help_make_simple_expected_graph(
            cdk5, p_tau, PHOSPHORYLATES, r_edge, self.help_causal_increases)

        reified_graph = reify_bel_graph(bel_graph)
        self.help_test_graphs_equal(expected_reified_graph, reified_graph)
Example #30
0
    def test_spia_matrix_composites(self):
        """Test handling of composites."""
        shp = composite_abundance([shp1, shp2])

        self.sialic_acid_graph.add_increases(shp,
                                             trem2,
                                             citation=citation,
                                             annotations={
                                                 'Species': '9606',
                                                 'Confidence': 'High'
                                             },
                                             evidence=evidence_1,
                                             object_modifier=activity())

        spia_dfs = to_spia_dfs(self.sialic_acid_graph)

        self.assertEqual(spia_dfs["activation"][shp1.name][trem2.name], 1)
        self.assertEqual(spia_dfs["activation"][shp2.name][trem2.name], 1)
    def test_convert_promote_translation(self):
        """Test the conversion of a bel statement like A -> r(B)"""
        # example from Colorectal Cancer Model v2.0.6 @ scai
        # act(p(HGNC:CTNNB1), ma(tscript)) increases r(HGNC:BIRC5)
        ctnnb1 = protein('HGNC', name='CTNNB1')
        birc5 = rna('HGNC', name='BIRC5')

        # a(MESH:Microglia) reg deg(a(CHEBI:"amyloid-beta"))
        bel_graph = BELGraph()
        bel_graph.add_increases(ctnnb1,
                                birc5,
                                evidence='10.1038/s41586-018-0368-8',
                                citation='18075512',
                                subject_modifier=activity('tscript'))

        expected_reified_graph = self.help_make_simple_expected_graph(
            ctnnb1, birc5, PROMOTES_TRANSLATION, 0, self.help_causal_increases)
        reified_graph = reify_bel_graph(bel_graph)

        self.help_test_graphs_equal(expected_reified_graph, reified_graph)
    def test_convert_two_phosphorylates(self):
        """Test that two phosphorylations of the same object get different reified nodes."""
        bel_graph = BELGraph()
        for kinase in (cdk5, gsk3b):
            bel_graph.add_directly_increases(
                kinase,
                p_tau,
                evidence=n(),
                citation=n(),
                subject_modifier=activity('kin'),
            )

        re1, re2 = 0, 1
        expected_reified_graph = self.help_make_simple_expected_graph(
            cdk5, p_tau, PHOSPHORYLATES, re1, self.help_causal_increases)
        expected_reified_graph.add_node(re2,
                                        label='phosphorylates',
                                        causal=self.help_causal_increases)
        expected_reified_graph.add_edge(gsk3b, re2, label=REIF_SUBJECT)
        expected_reified_graph.add_edge(p_tau, re2, label=REIF_OBJECT)

        reified_graph = reify_bel_graph(bel_graph)
        self.help_test_graphs_equal(expected_reified_graph, reified_graph)
Example #33
0
def test_modification_with_evidences():
    braf_kin = Agent('BRAF', activity=ActivityCondition('kinase', True),
                     db_refs={'HGNC': '1097', 'UP': 'P15056'})
    mek = Agent('MAP2K1', db_refs={'HGNC': '6840', 'UP': 'Q02750'})
    evidence = Evidence(source_api='test', text='evidence text', pmid='1234')
    stmt = Phosphorylation(braf_kin, mek, 'S', '218', evidence=evidence)
    pba = pa.PybelAssembler([stmt])
    belgraph = pba.make_model()
    assert len(belgraph.nodes()) == 3
    assert braf_dsl in belgraph
    map2k1_mod_dsl = map2k1_dsl.with_variants(phos_dsl)
    assert map2k1_mod_dsl in belgraph
    assert belgraph.number_of_edges() == 2
    edge_data = get_edge_data(belgraph, braf_dsl, map2k1_mod_dsl)
    assert edge_data.get(pc.SUBJECT) == activity('kin')
    assert edge_data[pc.RELATION] == pc.INCREASES
    assert edge_data[pc.EVIDENCE] == 'evidence text'
    assert edge_data[pc.CITATION] == {
        pc.CITATION_TYPE: pc.CITATION_TYPE_PUBMED,
        pc.CITATION_REFERENCE: '1234',
    }
    assert 'source_api' in edge_data[pc.ANNOTATIONS]
    assert edge_data[pc.ANNOTATIONS]['source_api'] == 'test'
    assert 'source_id' not in edge_data[pc.ANNOTATIONS]
Example #34
0
    def test_decreases(self):
        """Test parsing a decreases relation with a reaction.

        3.1.3 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#Xdecreases
        """
        statement = 'pep(p(FPLX:CAPN, location(GO:intracellular))) -| reaction(reactants(p(HGNC:CDK5R1)),products(p(HGNC:CDK5)))'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SOURCE: {
                MODIFIER: ACTIVITY,
                FUNCTION: PROTEIN,
                CONCEPT: {
                    NAMESPACE: 'FPLX',
                    NAME: 'CAPN',
                },
                LOCATION: {
                    NAMESPACE: 'GO',
                    NAME: 'intracellular'
                },
                EFFECT: activity_mapping['pep'],
            },
            RELATION: DECREASES,
            TARGET: {
                FUNCTION:
                REACTION,
                REACTANTS: [{
                    FUNCTION: PROTEIN,
                    CONCEPT: {
                        NAMESPACE: 'HGNC',
                        NAME: 'CDK5R1',
                    },
                }],
                PRODUCTS: [
                    {
                        FUNCTION: PROTEIN,
                        CONCEPT: {
                            NAMESPACE: 'HGNC',
                            NAME: 'CDK5',
                        },
                    },
                ],
            },
        }
        self.assertEqual(expected_dict, result.asDict())

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

        obj_member_1 = protein('HGNC', 'CDK5R1')
        self.assert_has_node(obj_member_1)

        obj_member_2 = protein('HGNC', 'CDK5')
        self.assert_has_node(obj_member_2)

        obj = reaction(reactants=[obj_member_1], products=[obj_member_2])
        self.assert_has_node(obj)

        self.assert_has_edge(obj, obj_member_1, relation=HAS_REACTANT)
        self.assert_has_edge(obj, obj_member_2, relation=HAS_PRODUCT)

        expected_edge_attributes = {
            RELATION: DECREASES,
            SOURCE_MODIFIER: {
                MODIFIER: ACTIVITY,
                EFFECT: activity_mapping['pep'],
                LOCATION: {
                    NAMESPACE: 'GO',
                    NAME: 'intracellular',
                }
            }
        }

        self.assertEqual(
            expected_edge_attributes[SOURCE_MODIFIER],
            activity(name='pep',
                     location=Entity(name='intracellular', namespace='GO')),
        )

        self.assert_has_edge(sub, obj, **expected_edge_attributes)
Example #35
0
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 " \
     "through the Src kinase (13). Finally, there is evidence that Src phosphorylates FAK at Tyr925, creating a" \
     " binding site for the complex of the adapter Grb2 and Ras guanosine 5'-triphosphate exchange factor mSOS (10)." \
     " These interactions link FAK to signaling pathways that modify the cytoskeleton and activate mitogen-activated" \
     " protein kinase (MAPK) cascades (Fig. 3A)."

e1 = str(hash(e1))

"""
p(HGNC:PTK2,pmod(P,Y,925)) increases kin(p(HGNC:MAPK1))
complex(p(HGNC:PTK2),p(HGNC:GRB2),p(HGNC:SOS1)) increases gtp(p(SFAM:"RAS Family"))