Пример #1
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)
Пример #2
0
def make_graph_1() -> BELGraph:
    graph = BELGraph(
        name='Lab course example',
        version='1.1.0',
        description='',
        authors='LSI',
        contact='*****@*****.**',
    )

    graph.add_node_from_data(protein_a)
    graph.add_node_from_data(protein_b)
    graph.add_node_from_data(gene_c)
    graph.add_node_from_data(rna_d)

    graph.add_increases(protein_a,
                        protein_b,
                        citation='1',
                        evidence='Evidence 1',
                        annotations={'Annotation': 'foo'})

    graph.add_increases(rna_d,
                        protein_a,
                        citation='2',
                        evidence='Evidence 2',
                        annotations={'Annotation': 'foo'})

    graph.add_decreases(gene_c,
                        protein_b,
                        citation='3',
                        evidence='Evidence 3',
                        annotations={'Annotation': 'foo'})

    return graph
Пример #3
0
    def test_get_upstream_causal_subgraph(self):
        """Test get_upstream_causal_subgraph."""
        a, b, c, d, e, f = [
            protein(namespace='test', name=n()) for _ in range(6)
        ]

        universe = BELGraph()
        universe.namespace_pattern['test'] = 'test-url'
        universe.add_increases(a, b, citation=n(), evidence=n())
        universe.add_increases(b, c, citation=n(), evidence=n())
        universe.add_association(d, a, citation=n(), evidence=n())
        universe.add_increases(e, a, citation=n(), evidence=n())
        universe.add_decreases(f, b, citation=n(), evidence=n())

        subgraph = get_upstream_causal_subgraph(universe, [a, b])

        self.assertIsInstance(subgraph, BELGraph)
        self.assert_all_nodes_are_base_entities(subgraph)

        self.assertIn('test', subgraph.namespace_pattern)
        self.assertEqual('test-url', subgraph.namespace_pattern['test'])

        self.assertIn(a, subgraph)
        self.assertIn(b, subgraph)
        self.assertNotIn(c, subgraph)
        self.assertNotIn(d, subgraph)
        self.assertIn(e, subgraph)
        self.assertIn(f, subgraph)
        self.assertEqual(4, subgraph.number_of_nodes())

        self.assert_in_edge(e, a, subgraph)
        self.assert_in_edge(a, b, subgraph)
        self.assert_in_edge(f, b, subgraph)
        self.assertEqual(3, subgraph.number_of_edges())
Пример #4
0
def make_graph_4() -> BELGraph:
    """Make an example graph.
        A -> B
        B -| C
        B -| D
        B -| E
        B -| F
        B -> G
        B -> H
        B -| H
        B -> I
        B -- J
        """
    graph = BELGraph(
        name='Lab course example',
        version='1.1.0',
        description='',
        authors='LSI',
        contact='*****@*****.**',
    )

    graph.add_increases(protein_a, protein_b, n(), n())
    graph.add_decreases(protein_b, gene_c, n(), n())
    graph.add_decreases(protein_b, rna_d, n(), n())
    graph.add_decreases(protein_b, protein_e, n(), n())
    graph.add_decreases(protein_b, gene_f, n(), n())
    graph.add_increases(protein_b, protein_g, n(), n())
    graph.add_decreases(protein_b, protein_h, n(), n())
    graph.add_increases(protein_b, protein_h, n(), n())
    graph.add_increases(protein_b, protein_i, n(), n())
    graph.add_association(protein_b, protein_j, n(), n())

    return graph
Пример #5
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))
Пример #6
0
 def add_to_bel_graph(self, graph: BELGraph) -> str:
     """Add this relationship as an edge to the BEL graph."""
     return graph.add_decreases(
         self.compound.as_bel(),
         self.umls.as_bel(),
         citation='26481350',
         evidence='Extracted from SIDER',
         annotations={
             'Database': 'SIDER',
             'SIDER_MEDDRA_TYPE': self.meddra_type.name,
             'SIDER_DETECTION': self.detection.name,
         }
     )
Пример #7
0
def make_graph_3() -> BELGraph:
    """Make an example graph.
        A -> B -| C
        D -| F -> C
        C -| F
        C -- G
        """
    graph = BELGraph(
        name='Lab course example',
        version='1.1.0',
        description='',
        authors='LSI',
        contact='*****@*****.**',
    )

    graph.add_increases(protein_a, protein_b, n(), n())
    graph.add_decreases(protein_b, gene_c, n(), n())
    graph.add_decreases(rna_d, gene_f, n(), n())
    graph.add_increases(protein_e, gene_f, n(), n())
    graph.add_increases(gene_f, gene_c, n(), n())
    graph.add_association(gene_c, protein_g, n(), n())

    return graph
Пример #8
0
    def test_expand_upstream_causal_subgraph(self):
        """Test expanding on the upstream causal subgraph."""
        a, b, c, d, e, f = [
            protein(namespace='test', name=i)
            for i in string.ascii_lowercase[:6]
        ]

        universe = BELGraph()
        universe.add_increases(a, b, citation=n(), evidence=n())
        universe.add_increases(b, c, citation=n(), evidence=n())
        universe.add_association(d, a, citation=n(), evidence=n())
        universe.add_increases(e, a, citation=n(), evidence=n())
        universe.add_decreases(f, b, citation=n(), evidence=n())

        subgraph = BELGraph()
        subgraph.add_increases(a, b, citation=n(), evidence=n())

        expand_upstream_causal(universe, subgraph)

        self.assertIsInstance(subgraph, BELGraph)
        self.assert_all_nodes_are_base_entities(subgraph)

        self.assertIn(a, subgraph)
        self.assertIn(b, subgraph)
        self.assertNotIn(c, subgraph)
        self.assertNotIn(d, subgraph)
        self.assertIn(e, subgraph)
        self.assertIn(f, subgraph)
        self.assertEqual(4, subgraph.number_of_nodes())

        self.assert_in_edge(e, a, subgraph)
        self.assert_in_edge(a, b, subgraph)
        self.assert_in_edge(f, b, subgraph)
        self.assertEqual(2, len(subgraph[a][b]))
        self.assertEqual(4,
                         subgraph.number_of_edges(),
                         msg='\n'.join(map(str, subgraph.edges())))
Пример #9
0
g(HGNC:MTHFR,sub(C,677,T)) pos path(MESH:"Alzheimer Disease")
"""

c2 = '21119889'
e2 = "Two common MTHFR polymorphisms, namely 677C>T (Ala222Val) and 1298A>C (Glu429Ala), are known to reduce MTHFR activity. \
It has been shown that the MTHFR 677T allele is associated with increased total plasma Hcy levels (tHcy) and decreased serum folate levels, mainly in 677TT homozygous subjects.\
the MTHFR 677C>T polymorphism as a candidate AD risk factor"
e2 = str(hash(e2))

mthfr = protein('HGNC', 'MTHFR')
mthfr_c677t = protein('HGNC', 'MTHFR', variants=[protein_substitution('Ala', 222, 'Val')])
mthfr_a1298c = protein('HGNC', 'MTHFR', variants=[protein_substitution('Glu', 429, 'Ala')])
folic_acid = abundance('CHEBI', 'folic acid')
alzheimer_disease = pathology('MESH', 'Alzheimer Disease')

example_graph.add_decreases(mthfr_c677t, mthfr, citation=c2, evidence=e2, object_modifier=activity())
example_graph.add_decreases(mthfr_a1298c, mthfr, citation=c2, evidence=e2, object_modifier=activity())
example_graph.add_negative_correlation(mthfr_c677t, folic_acid, citation=c2, evidence=e2)
example_graph.add_positive_correlation(mthfr_c677t, alzheimer_disease, citation=c2, evidence=e2)

c3 = '17948130'
e3 = 'A polymorphism in the NDUFB6 promoter region that creates a possible DNA methylation site (rs629566, A/G) was ' \
     'associated with a decline in muscle NDUFB6 expression with age. Although young subjects with the rs629566 G/G ' \
     'genotype exhibited higher muscle NDUFB6 expression, this genotype was associated with reduced expression in' \
     ' elderly subjects. This was subsequently explained by the finding of increased DNA methylation in the promoter ' \
     'of elderly, but not young, subjects carrying the rs629566 G/G genotype. Furthermore, the degree of DNA' \
     ' methylation correlated negatively with muscle NDUFB6 expression, which in turn was associated with insulin ' \
     'sensitivity.'
e3 = str(hash(e3))

rs629566 = gene('DBSNP', 'rs629566', variants=[gmod('Me')])
Пример #10
0
class TestAnnotation(unittest.TestCase):
    """Tests for getting sub-graphs by annotation."""
    def setUp(self):
        """Set up the test case with a pre-populated BEL graph."""

        self.graph = BELGraph()

        self.graph.namespace_url['test'] = test_namespace_url
        self.graph.annotation_url['subgraph'] = test_annotation_url

        # A increases/decreases B.
        self.graph.add_increases(a,
                                 b,
                                 citation=citation,
                                 evidence=evidence,
                                 annotations={'subgraph': {'1', '2'}})
        self.graph.add_decreases(a,
                                 b,
                                 citation=citation,
                                 evidence=evidence,
                                 annotations={'subgraph': {'1'}})

        # B increases association with C.
        self.graph.add_increases(b,
                                 c,
                                 citation=citation,
                                 evidence=evidence,
                                 annotations={'subgraph': {'1', '2'}})
        self.graph.add_association(b,
                                   c,
                                   citation=citation,
                                   evidence=evidence,
                                   annotations={'subgraph': {'2'}})

        # C increases D
        self.graph.add_increases(c, d, citation=citation, evidence=evidence)

        self.graph.add_increases(d,
                                 e,
                                 citation=citation,
                                 evidence=evidence,
                                 annotations={'subgraph': {'1', '2'}})
        self.graph.add_qualified_edge(d,
                                      e,
                                      relation=CAUSES_NO_CHANGE,
                                      evidence=evidence,
                                      citation=citation,
                                      annotations={'subgraph': {'1', '2'}})

    def test_contradictions_finder(self):
        """Simple test to find contradictions."""
        contradictory_edges = get_contradiction_summary(self.graph)

        contradictions = [(protein(namespace='test', name='0'),
                           protein(namespace='test',
                                   name='1'), {'decreases', 'increases'}),
                          (protein(namespace='test', name='3'),
                           protein(namespace='test',
                                   name='4'), {'causesNoChange', 'increases'})]

        for edge in contradictory_edges:
            self.assertIn(edge, contradictions)
Пример #11
0
def _add_row(
    graph: BELGraph,
    relation: str,
    source_prefix: str,
    source_id: str,
    source_name: Optional[str],
    target_prefix: str,
    target_id: str,
    target_name: Optional[str],
    pubmed_id: str,
    int_detection_method: str,
    source_database: str,
    confidence: str,
) -> None:  # noqa:C901
    """Add for every PubMed ID an edge with information about relationship type, source and target.

    :param source_database: row value of column source_database
    :param graph: graph to add edges to
    :param relation: row value of column relation
    :param source_prefix: row value of source prefix
    :param source_id: row value of source id
    :param target_prefix: row value of target prefix
    :param target_id: row value of target id
    :param pubmed_id: row value of column PubMed_id
    :param int_detection_method: row value of column interaction detection method
    :param confidence: row value of confidence score column
    :return: None
    """
    if pubmed_id is None:
        pubmed_id = 'database', 'intact'

    annotations = {
        'psi-mi': relation,
        'intact-detection': int_detection_method,
        'intact-source': source_database,
        'intact-confidence': confidence,
    }

    # map double spaces to single spaces in relation string
    relation = ' '.join(relation.split())

    source_dsl = NAMESPACE_TO_DSL.get(source_prefix, pybel.dsl.Protein)
    source = source_dsl(
        namespace=source_prefix,
        identifier=source_id,
        name=source_name,
    )
    target_dsl = NAMESPACE_TO_DSL.get(target_prefix, pybel.dsl.Protein)
    target = target_dsl(
        namespace=target_prefix,
        identifier=target_id,
        name=target_name,
    )

    if relation in PROTEIN_INCREASES_MOD_DICT:
        graph.add_increases(
            source,
            target.with_variants(PROTEIN_INCREASES_MOD_DICT[relation]),
            citation=pubmed_id,
            evidence=EVIDENCE,
            annotations=annotations,
            subject_modifier=SUBJECT_ACTIVITIES.get(relation),
        )

    # dna strand elongation
    elif relation == 'psi-mi:"MI:0701"(dna strand elongation)':
        target_mod = pybel.dsl.Gene(
            namespace=target_prefix,
            identifier=target_id,
            name=target_name,
            variants=[
                GeneModification(
                    name='DNA strand elongation',
                    namespace='go',
                    identifier='0022616',
                ),
            ],
        )
        graph.add_increases(
            source,
            target_mod,
            citation=pubmed_id,
            evidence=EVIDENCE,
            annotations=annotations,
        )

    # DECREASES
    elif relation in INTACT_DECREASES_ACTIONS:
        #: dna cleavage: Covalent bond breakage of a DNA molecule leading to the formation of smaller fragments
        if relation == 'psi-mi:"MI:0572"(dna cleavage)':
            target_mod = pybel.dsl.Gene(
                namespace=target_prefix,
                identifier=source_id,
                name=target_name,
            )
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
            )
        #: rna cleavage: Any process by which an RNA molecule is cleaved at specific sites or in a regulated manner
        elif relation == 'psi-mi:"MI:0902"(rna cleavage)':
            target_mod = pybel.dsl.Rna(
                namespace=target_prefix,
                identifier=source_id,
                name=target_name,
            )
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
            )

        # cleavage
        elif relation in {
                #: Covalent bond breakage in a molecule leading to the formation of smaller molecules
                'psi-mi:"MI:0194"(cleavage reaction)',
                #: Covalent modification of a polypeptide occuring during its maturation or its proteolytic degradation
                'psi-mi:"MI:0570"(protein cleavage)',
        }:
            graph.add_decreases(
                source,
                target,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
            )

        #: Reaction monitoring the cleavage (hydrolysis) or a lipid molecule
        elif relation == 'psi-mi:"MI:1355"(lipid cleavage)':
            target_mod = target.with_variants(
                pybel.dsl.ProteinModification(
                    name='lipid catabolic process',
                    namespace='go',
                    identifier='0016042',
                ), )

            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
                object_modifier=pybel.dsl.activity(),
            )

        #: 'lipoprotein cleavage reaction': Cleavage of a lipid group covalently bound to a protein residue
        elif relation == 'psi-mi:"MI:0212"(lipoprotein cleavage reaction)':
            target_mod = target.with_variants(
                pybel.dsl.ProteinModification(
                    name='lipoprotein modification',
                    namespace='go',
                    identifier='0042160',
                ), )
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
                object_modifier=pybel.dsl.activity(),
            )

        # deformylation reaction
        elif relation == 'psi-mi:"MI:0199"(deformylation reaction)':
            target_mod = target.with_variants(
                pybel.dsl.ProteinModification(
                    name='protein formylation',
                    namespace='go',
                    identifier='0018256',
                ), )
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
            )
        # protein deamidation
        elif relation == 'psi-mi:"MI:2280"(deamidation reaction)':
            target_mod = target.with_variants(
                pybel.dsl.ProteinModification(
                    name='protein amidation',
                    namespace='go',
                    identifier='0018032',
                ), )
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
                object_modifier=pybel.dsl.activity(),
            )

        # protein decarboxylation
        elif relation == 'psi-mi:"MI:1140"(decarboxylation reaction)':
            target_mod = target.with_variants(
                pybel.dsl.ProteinModification(
                    name='protein carboxylation',
                    namespace='go',
                    identifier='0018214',
                ), )
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
            )
        # protein deamination:
        elif relation == 'psi-mi:"MI:0985"(deamination reaction)':
            target_mod = target.with_variants(
                pybel.dsl.ProteinModification(
                    name='amine binding',
                    namespace='go',
                    identifier='0043176',
                ), )
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
            )
        # protein modification
        elif relation in PROTEIN_DECREASES_MOD_DICT:
            target_mod = target.with_variants(
                PROTEIN_DECREASES_MOD_DICT[relation])
            graph.add_decreases(
                source,
                target_mod,
                citation=pubmed_id,
                evidence=EVIDENCE,
                annotations=annotations,
            )
        else:
            raise ValueError(
                f"The relation {relation} is not in DECREASE relations.")

    # ASSOCIATION:
    elif relation in INTACT_ASSOCIATION_ACTIONS:
        graph.add_association(
            source,
            target,
            citation=pubmed_id,
            evidence=EVIDENCE,
            annotations=annotations,
        )

    # REGULATES:
    elif relation in INTACT_REGULATES_ACTIONS:
        graph.add_regulates(
            source,
            target,
            citation=pubmed_id,
            evidence=EVIDENCE,
            annotations=annotations,
        )

    # BINDS
    elif relation in INTACT_BINDS_ACTIONS:
        graph.add_binds(
            source,
            target,
            citation=pubmed_id,
            evidence=EVIDENCE,
            annotations=annotations,
        )

    # no specified relation
    else:
        raise ValueError(
            f"Unspecified relation {relation} between {source} and {target}")
Пример #12
0
def _add_my_row(graph: BELGraph, row) -> None:
    relation = row['relation']
    source_uniprot_id = row['source']
    target_uniprot_id = row['target']

    pubmed_ids = row['pubmed_ids']
    pubmed_ids = pubmed_ids.split('|')

    source = pybel.dsl.Protein(
        namespace='uniprot',
        identifier=source_uniprot_id,
        name=get_mnemonic(source_uniprot_id),
    )
    target = pybel.dsl.Protein(
        namespace='uniprot',
        identifier=target_uniprot_id,
        name=get_mnemonic(target_uniprot_id),
    )

    for pubmed_id in pubmed_ids:
        if relation == 'deubiquitination':
            target_ub = target.with_variants(
                pybel.dsl.ProteinModification('Ub'))
            graph.add_decreases(
                source,
                target_ub,
                citation=pubmed_id,
                evidence='From intact',
            )
        elif relation == 'ubiqutination':
            target_ub = target.with_variants(
                pybel.dsl.ProteinModification('Ub'))
            graph.add_increases(
                source,
                target_ub,
                citation=...,
                evidence='From intact',
            )

        elif relation == 'degratation':
            graph.add_decreases(
                source,
                target,
                citation=...,
                evidence='From intact',
            )

        elif relation == 'activates':
            graph.add_increases(
                source,
                target,
                ...,
                object_modifier=pybel.dsl.activity(),
            )
        elif relation == 'co-expressed':
            graph.add_correlation(
                pybel.dsl.Rna(
                    namespace='uniprot',
                    identifier=source_uniprot_id,
                    name=get_mnemonic(source_uniprot_id),
                ),
                pybel.dsl.Rna(
                    namespace='uniprot',
                    identifier=target_uniprot_id,
                    name=get_mnemonic(target_uniprot_id),
                ),
                annotations=dict(cell_line={'HEK2': True}),
            )