예제 #1
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
예제 #2
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
예제 #3
0
    def test_regulates_with_multiple_nnotations(self):
        """
        3.1.7 http://openbel.org/language/web/version_2.0/bel_specification_version_2.0.html#_regulates_reg
        Test nested definitions"""
        statement = 'pep(complex(p(HGNC:F3),p(HGNC:F7))) regulates pep(p(HGNC:F9))'
        result = self.parser.relation.parseString(statement)

        expected_dict = {
            SUBJECT: {
                MODIFIER: ACTIVITY,
                EFFECT: {
                    NAME: 'pep',
                    NAMESPACE: BEL_DEFAULT_NAMESPACE
                },
                TARGET: {
                    FUNCTION:
                    COMPLEX,
                    MEMBERS: [{
                        FUNCTION: PROTEIN,
                        NAMESPACE: 'HGNC',
                        NAME: 'F3'
                    }, {
                        FUNCTION: PROTEIN,
                        NAMESPACE: 'HGNC',
                        NAME: 'F7'
                    }]
                }
            },
            RELATION: REGULATES,
            OBJECT: {
                MODIFIER: ACTIVITY,
                EFFECT: {
                    NAME: 'pep',
                    NAMESPACE: BEL_DEFAULT_NAMESPACE
                },
                TARGET: {
                    FUNCTION: PROTEIN,
                    NAMESPACE: 'HGNC',
                    NAME: 'F9'
                }
            }
        }
        self.assertEqual(expected_dict, result.asDict())

        sub_member_1 = protein('HGNC', 'F3')
        self.assert_has_node(sub_member_1)

        sub_member_2 = protein('HGNC', 'F7')
        self.assert_has_node(sub_member_2)

        sub = complex_abundance([sub_member_1, sub_member_2])
        self.assert_has_node(sub)

        self.assert_has_edge(sub, sub_member_1)
        self.assert_has_edge(sub, sub_member_2)

        obj = protein('HGNC', 'F9')
        self.assert_has_node(obj)

        self.assert_has_edge(sub, obj, relation=expected_dict[RELATION])
예제 #4
0
def flatten_complex_to_bel_node(graph, node):
    """Create complex abundance BEL node.

    :param pybel.BELGraph graph: BEL Graph
    :param dict node: dictionary of node attributes
    :return: BEL node dictionary
    :rtype: pybel.dsl.BaseEntity
    """
    members = list()

    for node_dict in node:

        if HGNC in node_dict:
            protein_node = protein(namespace=HGNC,
                                   name=node_dict[HGNC_SYMBOL],
                                   identifier=node_dict[HGNC])
            members.append(protein_node)

        elif UNIPROT in node_dict:
            protein_node = protein(namespace=UNIPROT.upper(),
                                   name=node_dict[UNIPROT],
                                   identifier=node_dict[UNIPROT])
            members.append(protein_node)

        else:
            protein_node = protein(namespace=KEGG.upper(),
                                   name=node_dict[KEGG_ID],
                                   identifier=node_dict[KEGG_ID])
            members.append(protein_node)

    complex_members = complex_abundance(members=members)
    graph.add_node_from_data(complex_members)

    return complex_members
예제 #5
0
    def test_complex_with_name(self):
        """Test what happens with a named complex.

        .. code-block::

            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:HUS1)
            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD1)
            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD9A)

        """
        hus1 = protein(namespace='HGNC', name='HUS1')
        rad1 = protein(namespace='HGNC', name='RAD1')
        rad9a = protein(namespace='HGNC', name='RAD9A')
        members = [hus1, rad1, rad9a]

        nine_one_one = complex_abundance(members=members,
                                         namespace='SCOMP',
                                         name='9-1-1 Complex')

        graph = BELGraph()

        graph.add_node_from_data(nine_one_one)
        self.assertIn(nine_one_one, graph)
        self.assertIn(hus1, graph)
        self.assertIn(rad1, graph)
        self.assertIn(rad9a, graph)
예제 #6
0
파일: test_dsl.py 프로젝트: stashkov/pybel
    def test_complex_with_name(self):
        """Tests a what happens with a named complex

        .. code-block::

            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:HUS1)
            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD1)
            complex(SCOMP:"9-1-1 Complex") hasComponent p(HGNC:RAD9A)

        """
        hus1 = protein(namespace='HGNC', name='HUS1')
        rad1 = protein(namespace='HGNC', name='RAD1')
        rad9a = protein(namespace='HGNC', name='RAD9A')
        members = [hus1, rad1, rad9a]

        nine_one_one = complex_abundance(members=members,
                                         namespace='SCOMP',
                                         name='9-1-1 Complex')

        node_tuple = (COMPLEX, ) + tuple(member.as_tuple()
                                         for member in members)

        self.assertEqual(node_tuple, nine_one_one.as_tuple())
        self.assertEqual(hash(node_tuple), hash(nine_one_one))
        self.assertEqual(hash_node(node_tuple), nine_one_one.as_sha512())
예제 #7
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
예제 #8
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')
    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}
예제 #9
0
def complex_to_bel(complex_dict, nodes, graph: BELGraph):
    """Convert complex abundance to BEL."""
    members = list({
        nodes[member_id]
        for member_id in complex_dict['participants']
        if member_id in nodes
    })

    _, _, _, identifier = parse_id_uri(complex_dict['uri_id'])

    complex_bel_node = complex_abundance(members=members, identifier=identifier)
    graph.add_node_from_data(complex_bel_node)

    return complex_bel_node
예제 #10
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
예제 #11
0
    def bel_isolated_reconstituted(self, graph: BELGraph):
        """Run the isolated node test."""
        self.assertIsNotNone(graph)
        self.assertIsInstance(graph, BELGraph)

        adgrb1 = protein(namespace='HGNC', name='ADGRB1')
        adgrb2 = protein(namespace='HGNC', name='ADGRB2')
        adgrb_complex = complex_abundance([adgrb1, adgrb2])
        achlorhydria = pathology(namespace='MESHD', name='Achlorhydria')

        for node in graph:
            self.assertIsInstance(node, BaseEntity)

        self.assertIn(adgrb1, graph)
        self.assertIn(adgrb2, graph)
        self.assertIn(adgrb_complex, graph)
        self.assertIn(achlorhydria, graph)

        assert_has_edge(self, adgrb_complex, adgrb1, graph)
        assert_has_edge(self, adgrb_complex, adgrb2, graph)
예제 #12
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
예제 #13
0
def node_to_bel(node: Dict, graph, hgnc_manager: HgncManager,
                chebi_manager: ChebiManager, species) -> BaseEntity:
    """Convert node dictionary to BEL node object."""
    node_types = node['entity_type']

    identifier, name, namespace = get_valid_node_parameters(
        node, hgnc_manager, chebi_manager, species)
    members = set()

    if namespace == 'hgnc_multiple_entry':
        return composite_abundance(process_multiple_proteins(identifier))

    elif 'Protein' in node_types:
        return protein(namespace=namespace.upper(),
                       name=name,
                       identifier=identifier)

    elif 'Dna' in node_types:
        return gene(namespace=namespace.upper(),
                    name=name,
                    identifier=identifier)

    elif 'Rna' in node_types:
        return rna(namespace=namespace.upper(),
                   name=name,
                   identifier=identifier)

    elif 'SmallMolecule' in node_types:
        return abundance(namespace=namespace.upper(),
                         name=name,
                         identifier=identifier)

    elif 'PhysicalEntity' in node_types:
        return abundance(namespace=namespace.upper(),
                         name=name,
                         identifier=identifier)

    elif 'Complex' in node_types:
        complex_components = node.get('complex_components')

        if complex_components:
            for component in complex_components:
                bel_node = node_to_bel(component, graph, hgnc_manager,
                                       chebi_manager, species)

                members.add(bel_node)

        if members:
            return complex_abundance(name=node.get('display_name'),
                                     members=members,
                                     identifier=identifier,
                                     namespace=namespace.upper())
        else:
            return NamedComplexAbundance(name=node.get('display_name'),
                                         identifier=identifier,
                                         namespace=namespace.upper())

    elif 'Pathway' in node_types:
        bioprocess_node = bioprocess(identifier=identifier,
                                     name=name,
                                     namespace=namespace.upper())
        graph.add_node_from_data(bioprocess_node)
        return bioprocess_node
    else:
        log.warning('Entity type not recognized', node_types)
예제 #14
0
파일: examples.py 프로젝트: pybel/pybel-cx
)

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 " \
     "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)."
예제 #15
0
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)

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

egfr_grb2_sos1_complex_dsl = complex_abundance([
    egfr_dsl,
    grb2_dsl,
    sos1_dsl,
])

egfr_grb2_sos1_phos_complex_dsl = complex_abundance([
    egfr_dsl,
    grb2_dsl,
    sos1_phosphorylated_dsl,
])


def draw(g, filename):
    ag = nx.nx_agraph.to_agraph(g)
    ag.draw(filename, prog='dot')

예제 #16
0
 def test_empty_complex(self):
     """Test that an empty complex causes a failure."""
     with self.assertRaises(ValueError):
         complex_abundance(members=[])
예제 #17
0
def complexes_to_bel_node(graph, members):
    complex_node = complex_abundance(members=members)
    graph.add_node_from_data(complex_node)

    return complex_node
예제 #18
0
 def test_complex_abundance(self):
     node = complex_abundance(members=[
         protein(namespace='HGNC', name='FOS'),
         protein(namespace='HGNC', name='JUN')
     ])
     self.assertEqual('complex(p(HGNC:FOS), p(HGNC:JUN))', str(node))
예제 #19
0
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')

egfr_grb2_sos1_complex_dsl = complex_abundance([
    egfr_dsl,
    grb2_dsl,
    sos1_dsl,
])

egfr_grb2_sos1_phos_complex_dsl = complex_abundance([
    egfr_dsl,
    grb2_dsl,
    sos1_phosphorylated_dsl,
])


def draw(g, filename):
    ag = nx.nx_agraph.to_agraph(g)
    ag.draw(filename, prog='dot')