Ejemplo n.º 1
0
def is_human_protein(bio_ontology, node):
    if bio_ontology.get_ns(node) in {'HGNC', 'FPLX'}:
        return True
    elif bio_ontology.get_ns(node) == 'UP' and \
            uniprot_client.is_human(bio_ontology.get_id(node)):
        return True
    return False
Ejemplo n.º 2
0
def is_human_protein(bio_ontology, node):
    """Return True if the given ontology node is a human protein."""
    if bio_ontology.get_ns(node) == 'HGNC':
        return True
    elif bio_ontology.get_ns(node) == 'UP' and \
            uniprot_client.is_human(bio_ontology.get_id(node)):
        return True
    return False
Ejemplo n.º 3
0
def add_ido_parents(bio_ontology: BioOntology):
    ido_root = bio_ontology.label('IDO', '0')
    bio_ontology.add_node(ido_root, name='infectious disease concept')
    edges_to_add = []
    for node in bio_ontology.nodes():
        if bio_ontology.get_ns(node) == 'IDO' and not \
                bio_ontology.get_parents(*bio_ontology.get_ns_id(node)):
            edges_to_add.append((node, ido_root, {'type': 'isa'}))
    bio_ontology.add_edges_from(edges_to_add)
Ejemplo n.º 4
0
def add_efo_parents(bio_ontology):
    edges_to_add = []
    efo_root = 'EFO:0000001'
    for node in bio_ontology.nodes():
        if bio_ontology.get_ns(node) == 'EFO' and \
                not bio_ontology.get_parents(*bio_ontology.get_ns_id(node)):
            edges_to_add.append((node, efo_root, {'type': 'isa'}))
    print('Adding %d EFO isa edges.' % len(edges_to_add))
    bio_ontology.add_edges_from(edges_to_add)
Ejemplo n.º 5
0
def add_drugbank_parents(bio_ontology):
    edges_to_add = []
    drugbank_root = 'DRUGBANK:DB00000'
    bio_ontology.add_node(drugbank_root, name='Drugs')
    for node in bio_ontology.nodes():
        if bio_ontology.get_ns(node) == 'DRUGBANK' and \
                not bio_ontology[node]:
            edges_to_add.append((node, drugbank_root, {'type': 'isa'}))
    print('Adding %d DRUGBANK isa edges.' % len(edges_to_add))
    bio_ontology.add_edges_from(edges_to_add)
Ejemplo n.º 6
0
def is_protein_family(bio_ontology, node):
    """Return True if the given ontology node is a protein family."""
    if bio_ontology.get_ns(node) == 'FPLX':
        return True
    return False
Ejemplo n.º 7
0
def is_non_human_protein(bio_ontology, node):
    if bio_ontology.get_ns(node) == 'UP' and \
             not uniprot_client.is_human(bio_ontology.get_id(node)):
        return True
    return False
Ejemplo n.º 8
0
    networkx.draw_networkx(G, pos, node_color='pink')
    edge_labels = networkx.get_edge_attributes(G, 'source')
    networkx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
    plt.show()


if __name__ == '__main__':
    bio_ontology.initialize()
    xrefs = [(e[0], e[1]) for e in bio_ontology.edges(data=True)
             if e[2]['type'] == 'xref']
    xrefg = bio_ontology.edge_subgraph(xrefs)
    comps = networkx.algorithms.strongly_connected_components(xrefg)

    problems = []
    for comp in comps:
        namespaces = [bio_ontology.get_ns(node) for node in comp]
        cnt = Counter(namespaces)
        if any(v > 1 for k, v in cnt.items()):
            problems.append(comp)

    print('Found %d problems in total' % len(problems))

    problems_by_ns = defaultdict(list)
    for problem in problems:
        nscnt = Counter([bio_ontology.get_ns(n) for n in problem])
        namespaces = [ns for ns, cnt in nscnt.items() if cnt > 1]
        for ns in namespaces:
            problems_by_ns[ns].append(problem)

    for ns, problems_ns in problems_by_ns.items():
        print(ns, len(problems_ns))