コード例 #1
0
    else:
        name = current_class.label
        cui = None
    kg.add_symp_term(current_id, name, cui)

# add relations
for current_class in ontology_classes:
    current_id = current_class.name.replace('_', ':')
    superclasses = [
        x for x in current_class.is_a
        if not (isinstance(x, owlready2.entity.Restriction)
                or isinstance(x, owlready2.class_construct.And))
    ]
    for superclass in superclasses:
        target_id = superclass.name.replace('_', ':')
        kg.add_isa_relation(current_id, 'SympTerm', 'symp_id', target_id,
                            'SympTerm', 'symp_id', 'symp')

# kg = KnowledgeGraph()
# uq = UmlsQuery()
# with driver.session() as session:
#     while to_process:
#         print(len(to_process))
#         current_class = to_process.pop()
#         superclasses = [x for x in current_class.is_a
#                         if not (isinstance(x, owlready2.entity.Restriction) or
#                                 isinstance(x, owlready2.class_construct.And))]
#         for superclass in superclasses:
#             target_symp_id = superclass.name.replace('_', ':')
#             if target_symp_id in id_map:
#                 cui = id_map[target_symp_id]
#                 umls_result = uq.cui2bestname(cui)
コード例 #2
0
        cui = 'UMLS:' + umls_result[0]['cui']
    else:
        name = current_class.label
        cui = None
    kg.add_hpo_term(current_id, name, cui)

# add relations
for current_class in ontology_classes:
    current_id = current_class.name.replace('_', ':')
    superclasses = [
        x for x in current_class.is_a
        if not isinstance(x, owlready2.entity.Restriction)
    ]
    for superclass in superclasses:
        target_id = superclass.name.replace('_', ':')
        kg.add_isa_relation(current_id, 'HpoTerm', 'hpo_id', target_id,
                            'HpoTerm', 'hpo_id', 'hpo')

# ## get all targets
# with driver.session() as session:
#     diseases = get_diseases(session)

# ## loop over targets and get ancestors, then loop until full hierarchy is loaded
# to_process = {obo[record['hpo_id'].replace(':', '_')] for record in diseases}
# processed = set()

# kg = KnowledgeGraph()
# uq = UmlsQuery()
# with driver.session() as session:
#     while to_process:
#         print(len(to_process))
#         current_class = to_process.pop()
コード例 #3
0
        cui = id_map[current_id]
        umls_result = uq.cui2bestname(cui)
        if umls_result:
            name = umls_result[0]['name']
        else:
            name = current_class.label
    else:
        name = current_class.label
        cui = None
    kg.add_uberon_term(current_id, name, cui)

# add relations
for current_class in ontology_classes:
    current_id = current_class.name.replace('_', ':')
    superclasses = [
        x for x in current_class.is_a
        if not isinstance(x, owlready2.class_construct.And)
    ]
    for superclass in superclasses:
        if isinstance(superclass, owlready2.entity.Restriction):
            if isinstance(superclass.property(), obo.BFO_0000050):
                target = superclass.value().is_a[0]
                target_id = target.name.replace('_', ':')
                kg.add_part_of_relation(current_id, 'UberonTerm', 'uberon_id',
                                        target_id, 'UberonTerm', 'uberon_id',
                                        'uberon')
        else:
            target_id = superclass.name.replace('_', ':')
            kg.add_isa_relation(current_id, 'UberonTerm', 'uberon_id',
                                target_id, 'UberonTerm', 'uberon_id', 'uberon')
コード例 #4
0
            name = current_class.label
    else:
        name = current_class.label
        cui = None
    kg.add_cl_term(current_id, name, cui)


# add relations
for current_class in ontology_classes:
    current_id = current_class.name.replace('_', ':')
    superclasses = [x for x in current_class.is_a
                    if not (isinstance(x, owlready2.entity.Restriction) or
                            isinstance(x, owlready2.class_construct.And))]
    for superclass in superclasses:
        target_id = superclass.name.replace('_', ':')
        kg.add_isa_relation(current_id, 'ClTerm', 'cl_id', target_id, 'ClTerm', 'cl_id', 'cell_ontology')


### deprecated
# uq = UmlsQuery()
# kg = KnowledgeGraph()

# ## get all targets
# terms = kg.get_cl_terms() ## TODO no cl_ids in knowledge graph yet - either map or load full ontology

# ## loop over targets and get ancestors, then loop until full hierarchy is loaded
# to_process = {obo[cl_id.replace(':', '_')] for cl_id in terms}
# processed = set()

# while to_process:
#     print(len(to_process))
コード例 #5
0
# add relations
for current_class in ontology_classes:
    current_id = current_class.name.replace('_', ':')
    superclasses = [x for x in current_class.is_a]
    for superclass in superclasses:
        if isinstance(superclass, owlready2.entity.Restriction):
            if isinstance(superclass.property(), obo.RO_0000087):
                target = superclass.value().is_a[0]
                target_id = target.name.replace('_', ':')
                kg.add_has_role_relation(current_id, 'ChebiTerm', 'chebi_id',
                                         target_id, 'ChebiTerm', 'chebi_id',
                                         'chebi')
        else:
            target_id = superclass.name.replace('_', ':')
            kg.add_isa_relation(current_id, 'ChebiTerm', 'chebi_id', target_id,
                                'ChebiTerm', 'chebi_id', 'chebi')

# kg = KnowledgeGraph()
# uq = UmlsQuery()

# ## get all drugs
# drugs = kg.get_drugs()

# ## loop over targets and get ancestors, then loop until full hierarchy is loaded
# to_process = {obo[record['chebi_id'].replace(':', '_')] for record in drugs}

# processed = set()
# while to_process:
#     print(len(to_process))
#     current_class = to_process.pop()
#     restrictions = [x for x in current_class.is_a if isinstance(x, owlready2.entity.Restriction)]
コード例 #6
0
        cui = 'UMLS:' + umls_result[0]['cui']
    else:
        name = current_class.label
        cui = None
    kg.add_go_term(current_id, name, cui)

# add relations
for current_class in ontology_classes:
    current_id = current_class.name.replace('_', ':')
    superclasses = [
        x for x in current_class.is_a
        if not isinstance(x, owlready2.entity.Restriction)
    ]
    for superclass in superclasses:
        target_id = superclass.name.replace('_', ':')
        kg.add_isa_relation(current_id, 'GoTerm', 'go_id', target_id, 'GoTerm',
                            'go_id', 'go')

# ## loop over targets and get ancestors, then loop until full hierarchy is loaded
# to_process = {obo[record['go_id'].replace(':', '_')] for record in pathways}
# processed = set()

# kg = KnowledgeGraph()
# uq = UmlsQuery()
# while to_process:
#     current_class = to_process.pop()
#     superclasses = [x for x in current_class.is_a if not isinstance(x, owlready2.entity.Restriction)]
#     for superclass in superclasses:
#         target_go_id = superclass.name.replace('_', ':')
#         umls_results = uq.go2cui(target_go_id)
#         if umls_results:
#             kg.add_go_term(current_class.name.replace('_', ':'),