예제 #1
0
    def enrich_drug_inchi(self, graph: BELGraph) -> None:
        """Enrich drugs in the graph with their InChI equivalent nodes."""
        self.add_namespace_to_graph(graph)

        for node, drug_model in list(self.iter_drugs(graph)):
            if drug_model.inchi:
                graph.add_equivalence(node, drug_model.as_inchi_bel())
예제 #2
0
def append_equivalences_graph(df: pd.DataFrame, graph: BELGraph) -> None:
    """Append equivalence relations to the graph."""
    graph.namespace_url.update(famplex_to_belns)
    graph.namespace_pattern.update({
        identifiers_key: pattern
        for _, (identifiers_key, pattern) in famplex_to_identifiers.items()
    })

    for index, (namespace, name, famplex_name) in df.iterrows():
        is_complex = "complex" in name.lower()

        if is_complex:
            func = named_complex_abundance
        else:
            func = protein

        if namespace in famplex_to_belns:
            if is_complex:
                namespace = "SCOMP"
            else:
                namespace = "SFAM"

        elif namespace in famplex_to_identifiers:
            namespace = famplex_to_identifiers[namespace][0]
        else:
            continue

        external = func(namespace, name)
        famplex = func('FPLX', famplex_name)

        graph.add_equivalence(external, famplex)
예제 #3
0
    def test_indirect_has_namespace(self):
        graph = BELGraph()

        a = Protein(namespace='HGNC', name='CD33')
        b = Protein(namespace='HGNCID', identifier='1659')

        graph.add_equivalence(a, b)

        self.assertEqual({a, b}, graph.get_equivalent_nodes(a))
        self.assertEqual({a, b}, graph.get_equivalent_nodes(b))

        self.assertTrue(graph.node_has_namespace(a, 'HGNC'))
        self.assertTrue(graph.node_has_namespace(b, 'HGNC'))
예제 #4
0
파일: manager.py 프로젝트: bio2bel/mirbase
    def to_bel(self) -> BELGraph:
        """Convert miRBase to BEL."""
        result = BELGraph()

        for sequence in self._get_query(Sequence):
            mirbase_node = sequence.as_pybel()

            for xref in sequence.xrefs:
                result.add_equivalence(
                    mirbase_node,
                    MicroRna(
                        namespace=xref.database,
                        identifier=xref.database_id,
                    ))

        return result
예제 #5
0
    def test_triangle_has_namespace(self):
        graph = BELGraph()

        a = Protein(namespace='A', name='CD33')
        b = Protein(namespace='B', identifier='1659')
        c = Protein(namespace='C', identifier='1659')
        d = Protein(namespace='HGNC', identifier='1659')

        graph.add_equivalence(a, b)
        graph.add_equivalence(b, c)
        graph.add_equivalence(c, a)
        graph.add_equivalence(c, d)

        self.assertEqual({a, b, c, d}, graph.get_equivalent_nodes(a))
        self.assertEqual({a, b, c, d}, graph.get_equivalent_nodes(b))
        self.assertEqual({a, b, c, d}, graph.get_equivalent_nodes(c))
        self.assertEqual({a, b, c, d}, graph.get_equivalent_nodes(d))

        self.assertTrue(graph.node_has_namespace(a, 'HGNC'))
        self.assertTrue(graph.node_has_namespace(b, 'HGNC'))
        self.assertTrue(graph.node_has_namespace(c, 'HGNC'))
        self.assertTrue(graph.node_has_namespace(d, 'HGNC'))
예제 #6
0
    def enrich_drug_equivalences(self, graph: BELGraph) -> None:
        """Enrich drugs in the graph with their equivalent nodes."""
        self.add_namespace_to_graph(graph)

        for node, drug_model in list(self.iter_drugs(graph)):
            if drug_model.inchi:
                graph.add_equivalence(node, drug_model.as_inchi_bel())

            if drug_model.inchikey:
                graph.add_equivalence(node, drug_model.as_inchikey_bel())

            for xref in drug_model.xrefs:
                resource = xref.resource.lower()
                identifier = xref.identifier

                if xref.resource in {'chebi', 'chembl'}:
                    graph.add_equivalence(
                        node,
                        abundance(namespace=resource, identifier=identifier))
                elif xref.resource == 'KEGG Compound':
                    # https://www.ebi.ac.uk/miriam/main/datatypes/MIR:00000013
                    graph.add_equivalence(
                        node,
                        abundance(namespace='kegg.compound',
                                  identifier=identifier))
                elif xref.resource == 'PubChem Substance':
                    # https://www.ebi.ac.uk/miriam/main/datatypes/MIR:00000033
                    graph.add_equivalence(
                        node,
                        abundance(namespace='pubchem.substance',
                                  identifier=identifier))
                elif xref.resource == 'PubChem Compound':
                    # https://www.ebi.ac.uk/miriam/main/datatypes/MIR:00000034
                    graph.add_equivalence(
                        node,
                        abundance(namespace='pubchem.compound',
                                  identifier=identifier))
예제 #7
0
파일: manager.py 프로젝트: bio2bel/entrez
    def enrich_equivalences(self, graph: BELGraph) -> None:
        """Add equivalent node information."""
        self.add_namespace_to_graph(graph)

        for node, gene_model in list(self.iter_genes(graph)):
            graph.add_equivalence(node, gene_model.as_bel(node[FUNCTION]))