Beispiel #1
0
def get_common_ancestors(id1, id2):
    e1 = ssm.get_id(id1.replace(":", "_"))
    e2 = ssm.get_id(id2.replace(":", "_"))
    #print(id1, id2, e1, e2)
    a = ssm.common_ancestors(e1, e2)
    a = [ssm.get_name(x) for x in a]
    return a
def get_common_ancestors(id1, id2):
    """

    :param id1:
    :param id2:
    :return:
    """

    if id1.startswith('CHEBI'):
        ssm.semantic_base('bin/DiShIn/chebi.db')
    if id1.startswith('HP'):
        ssm.semantic_base('bin/DiShIn/hp.db')
    if id1.startswith('GO'):
        ssm.semantic_base('bin/DiShIn/go.db')
    if id1.startswith('DOID'):
        ssm.semantic_base('bin/DiShIn/doid.db')

    e1 = ssm.get_id(id1.replace(':', '_'))

    if id2.startswith('CHEBI'):
        ssm.semantic_base('bin/DiShIn/chebi.db')
    if id2.startswith('HP'):
        ssm.semantic_base('bin/DiShIn/hp.db')
    if id2.startswith('GO'):
        ssm.semantic_base('bin/DiShIn/go.db')
    if id2.startswith('DOID'):
        ssm.semantic_base('bin/DiShIn/doid.db')

    e2 = ssm.get_id(id2.replace(':', '_'))

    a = ssm.common_ancestors(e1, e2)
    a = [ssm.get_name(x) for x in a]

    return a
Beispiel #3
0
def get_common_ancestors(id1, id2):
    global chebi_cache
    if (id1, id2) in chebi_cache:
        #logging.info("using chebi cache")
        return chebi_cache[(id1, id2)]
    else:
        e1 = ssm.get_id(id1.replace(":", "_"))
        e2 = ssm.get_id(id2.replace(":", "_"))
        #print(id1, id2, e1, e2)
        a = ssm.common_ancestors(e1, e2)
        a = [ssm.get_name(x) for x in a]
        chebi_cache[(id1, id2)] = a
        return a
Beispiel #4
0
def get_dist_direct(cid1, cid2, max_dist=100):
    global ssm_cache
    #print("getting dist between", cid1, cid2)
    if (cid1, cid2) in ssm_cache:
        #print("cached")
        return ssm_cache[(cid1, cid2)]
    #else:
        #print("newdist")
        #rows = ssm.connection.execute("""
        #    SELECT MAX(distance)
        #    FROM transitive t, entry e1, entry e2
        #     WHERE ((t.entry1=e1.id and t.entry2=e2.id) or
        #          (t.entry1=e2.id and t.entry2=e1.id))
        #           and e1.name = ? and e2.name = ?
        #    """, (cid1, cid2,)).fetchone()
        #if rows[0] is None:
        #    dist = 0
        #else:
        #    dist = rows[0]
        #if dist > 0:
        #    print(cid1, cid2, dist)
    e1 = ssm.get_id(cid1.replace(":", "_"))
    e2 = ssm.get_id(cid2.replace(":", "_"))
        #ca = ssm.common_ancestors(e1, e2)
        # print(e1, e2, ca)
    d1 = ssm.connection.execute("""
        SELECT distance
        FROM transitive t, entry e1, entry e2
         WHERE t.distance < ? and ((t.entry1=e1.id and t.entry2=e2.id) or
              (t.entry1=e2.id and t.entry2=e1.id))
               and e1.id = ? and e2.id = ?
        """, (max_dist,e1, e2,)).fetchone()
        #d2 = ssm.connection.execute("""
        #            SELECT distance
        #            FROM transitive t, entry e1, entry e2
        #             WHERE ((t.entry1=e1.id and t.entry2=e2.id) or
        #                  (t.entry1=e2.id and t.entry2=e1.id))
        #                   and e1.name = ? and e2.id = ?
        #            """, (cid2, ca[0],)).fetchone()
        #d1 = len(ssm.common_ancestors(e1, e1)) - len(ca)
        #d2 = len(ssm.common_ancestors(e2, e2)) - len(ca)

    if d1 is None:
        ssm_cache[(cid1, cid2)] = -1
        return -1
    else:
        ssm_cache[(cid1, cid2)] = d1[0]
        return d1[0]
Beispiel #5
0
def get_path_to_root(id1):
    global chebi_cache
    if id1 in chebi_cache:
        #logging.info("using chebi cache")
        return chebi_cache[id1]
    else:
        e1 = ssm.get_id(id1.replace(":", "_"))
        a = ssm.common_ancestors(e1, e1)
        a = [ssm.get_name(x) for x in a]
        chebi_cache[id1] = a
    return a
Beispiel #6
0
def get_path_to_root(entity_id):
    """

    :param entity_id:
    :return:
    """

    if entity_id.startswith('CHEBI'):
        ssm.semantic_base('bin/DiShIn/chebi.db')
    if entity_id.startswith('HP'):
        ssm.semantic_base('bin/DiShIn/hp.db')
    if entity_id.startswith('GO'):
        ssm.semantic_base('bin/DiShIn/go.db')
    if entity_id.startswith('DOID'):
        ssm.semantic_base('bin/DiShIn/doid.db')

    e1 = ssm.get_id(entity_id.replace(':', '_'))

    a = ssm.common_ancestors(e1, e1)
    a = [ssm.get_name(x) for x in a]

    return a
Beispiel #7
0
def get_path_to_root(id1):
    e1 = ssm.get_id(id1.replace(":", "_"))
    a = ssm.common_ancestors(e1, e1)
    a = [ssm.get_name(x) for x in a]
    return a