Ejemplo n.º 1
0
def print_trees(graph, bridge):
    PPO = 'ro:proper_part_of'
    HPP = 'ro:has_proper_part'
    hpp = HPP.replace('ro:', graph.namespaces['ro'])
    ppo = PPO.replace('ro:', graph.namespaces['ro'])
    a, b = creatTree(*Query(tc.red('birnlex_796'), HPP, 'OUTGOING', 10),  # FIXME seems to be a last one wins bug here with birnlex_796 vs NIFGA:birnlex_796 depending on the has seed...
                     json=graph.make_scigraph_json(HPP))
    c, d = creatTree(*Query('NIFGA:birnlex_796', hpp, 'OUTGOING', 10), graph=sgg)
    j = bridge.make_scigraph_json(HPP)  # issue https://github.com/RDFLib/rdflib/pull/661
    e, f = creatTree(*Query('UBERON:0000955', HPP, 'OUTGOING', 10), json=j)
    k_, l_ = creatTree(*Query('NIFGA:nlx_anat_101177', ppo, 'INCOMING', 10), graph=sgg)

    merge = dict(d[-1])  # full tree with ppo converted to hpp
    merge['nodes'].extend(l_[-1]['nodes'])
    merge['edges'].extend([{'sub':e['obj'], 'pred':hpp, 'obj':e['sub']} for e in l_[-1]['edges']])
    m_, n_ = creatTree(*Query('NIFGA:birnlex_796', hpp, 'OUTGOING', 10), json=merge)

    print('nifga dep')
    print(a)
    print('nifga live')
    print(c)
    print('new bridge')
    print(e)
    print('nifga total (both directions)')
    print(m_)

    print('nifga white matter')
    print(k_)

    return a, b, c, d, e, f, k_, l_, m_, n_
Ejemplo n.º 2
0
def print_trees(graph, bridge):
    PPO = 'ro:proper_part_of'
    HPP = 'ro:has_proper_part'
    hpp = HPP.replace('ro:', graph.namespaces['ro'])
    ppo = PPO.replace('ro:', graph.namespaces['ro'])
    a, b = creatTree(
        *Query(
            tc.red('birnlex_796'), HPP, 'OUTGOING', 10
        ),  # FIXME seems to be a last one wins bug here with birnlex_796 vs NIFGA:birnlex_796 depending on the has seed...
        json=graph.make_scigraph_json(HPP))
    c, d = creatTree(*Query('NIFGA:birnlex_796', hpp, 'OUTGOING', 10),
                     graph=sgg)
    j = bridge.make_scigraph_json(
        HPP)  # issue https://github.com/RDFLib/rdflib/pull/661
    e, f = creatTree(*Query('UBERON:0000955', HPP, 'OUTGOING', 10), json=j)
    k_, l_ = creatTree(*Query('NIFGA:nlx_anat_101177', ppo, 'INCOMING', 10),
                       graph=sgg)

    merge = dict(d[-1])  # full tree with ppo converted to hpp
    merge['nodes'].extend(l_[-1]['nodes'])
    merge['edges'].extend([{
        'sub': e['obj'],
        'pred': hpp,
        'obj': e['sub']
    } for e in l_[-1]['edges']])
    m_, n_ = creatTree(*Query('NIFGA:birnlex_796', hpp, 'OUTGOING', 10),
                       json=merge)

    print('nifga dep')
    print(a)
    print('nifga live')
    print(c)
    print('new bridge')
    print(e)
    print('nifga total (both directions)')
    print(m_)

    print('nifga white matter')
    print(k_)

    return a, b, c, d, e, f, k_, l_, m_, n_
Ejemplo n.º 3
0
    def equiv(curie, label):
        if curie in manual:
            replaced_by[curie] = manual[curie]
            return manual[curie]

        ec = sgg.getNeighbors(curie, relationshipType='equivalentClass')
        nodes = [n for n in ec['nodes'] if n['id'] != curie]
        if len(nodes) > 1:
            #print('wtf node', [n['id'] for n in nodes], curie)
            for node in nodes:
                id_ = node['id']
                label_ = node['lbl']

                if id_.startswith('UBERON'):
                    if curie in replaced_by:
                        one = replaced_by[curie]
                        replaced_by[curie] = one, id_
                        print('WE GOT DUPES', curie, label, one, id_)  # TODO
                    else:
                        replaced_by[curie] = id_
                else:
                    internal_equivs[curie] = id_
        elif not nodes:
            node = sgg.getNode(curie)['nodes'][0]
            if OWL.deprecated.toPython() in node['meta']:
                print('THIS CLASS IS DEPRECATED', curie)
                lbl = node['lbl']
                if lbl.startswith(
                        'Predominantly white regional') or lbl.startswith(
                            'Predominantly gray regional'):
                    print('\tHE\'S DEAD JIM!', lbl, node['id'])
                    replaced_by[curie] = 'NOREP'
                if IRBC in node['meta']:
                    existing_replaced = node['meta'][IRBC][0]
                    ec2 = sgg.getNeighbors(existing_replaced,
                                           relationshipType='equivalentClass')
                    print('\tFOUND ONE', existing_replaced)
                    #scigPrint.pprint_node(sgg.getNode(existing_replaced))
                    if ec2['edges']:  # pass the buck if we can
                        print('\t', end='')
                        scigPrint.pprint_edge(ec2['edges'][0])
                        rb = ec2['edges'][0]['obj']
                        print('\tPASSING BUCK : (%s -> %s -> %s)' %
                              (curie, existing_replaced, rb))
                        irbcs[curie] = (existing_replaced, rb)
                        replaced_by[curie] = rb
                        return nodes
                    else:
                        er_node = sgv.findById(existing_replaced)
                        if not er_node['deprecated']:
                            if not er_node['curie'].startswith('NIFGA:'):
                                print('\tPASSING BUCK : (%s -> %s)' %
                                      (curie, er_node['curie']))
                                return nodes

                        print(
                            '\tERROR: could not pass buck, we are at a dead end at',
                            er_node)  # TODO
                    print()

            moar = [
                t for t in sgv.findByTerm(label)
                if t['curie'].startswith('UBERON')
            ]
            if moar:
                #print(moar)
                #replaced_by[curie] = moar[0]['curie']
                if len(moar) > 1:
                    print('WARNING', curie, label,
                          [(m['curie'], m['labels'][0]) for m in moar])

                for node in moar:
                    #if node['curie'] in uberon_obsolete:  # node['deprecated']?
                    #continue
                    ns = sgg.getNode(node['curie'])
                    assert len(
                        ns['nodes']) == 1, "WTF IS GOING ON %s" % node['curie']
                    ns = ns['nodes'][0]
                    if _doprint:
                        print(
                            'Found putative replacement in moar: (%s -> %s)' %
                            (curie, ns['id']))
                        if DBX in ns['meta']:
                            print(' ' * 8, node['curie'], ns['meta'][DBX],
                                  node['labels'][0], node['synonyms'])

                        if AID in ns['meta']:
                            print(' ' * 8, node['curie'], ns['meta'][AID],
                                  node['labels'][0], node['synonyms'])

                        if CON in ns['meta']:
                            print(' ' * 8, node['curie'], ns['meta'][CON],
                                  node['labels'][0], node['synonyms'])

                    replaced_by[curie] = ns['id']
            else:
                replaced_by[curie] = None
                if False:  # review
                    print('NO FORWARD EQUIV', tc.red(curie), label)  # TODO
                    for k, v in sorted(
                            sgg.getNode(curie)['nodes'][0]['meta'].items()):
                        if type(v) == iter:
                            print(' ' * 4, k)
                            for _ in v:
                                print(' ' * 8, _)
                        else:
                            print(' ' * 4, k, v)
        else:
            node = nodes[0]
            replaced_by[curie] = node['id']
            exact[curie] = node['id']

        return nodes
Ejemplo n.º 4
0
    def equiv(curie, label):
        if curie in manual:
            replaced_by[curie] = manual[curie]
            return manual[curie]

        ec = sgg.getNeighbors(curie, relationshipType='equivalentClass')
        nodes = [n for n in ec['nodes'] if n['id'] != curie]
        if len(nodes) > 1:
            #print('wtf node', [n['id'] for n in nodes], curie)
            for node in nodes:
                id_ = node['id']
                label_ = node['lbl']

                if id_.startswith('UBERON'):
                    if curie in replaced_by:
                        one = replaced_by[curie]
                        replaced_by[curie] = one, id_
                        print('WE GOT DUPES', curie, label, one, id_)  # TODO
                    else:
                        replaced_by[curie] = id_
                else:
                    internal_equivs[curie] = id_
        elif not nodes:
            node = sgg.getNode(curie)['nodes'][0]
            if OWL.deprecated.toPython() in node['meta']:
                print('THIS CLASS IS DEPRECATED', curie)
                lbl = node['lbl']
                if lbl.startswith('Predominantly white regional') or lbl.startswith('Predominantly gray regional'):
                    print('\tHE\'S DEAD JIM!', lbl, node['id'])
                    replaced_by[curie] = 'NOREP'
                if IRBC in node['meta']:
                    existing_replaced = node['meta'][IRBC][0]
                    ec2 = sgg.getNeighbors(existing_replaced, relationshipType='equivalentClass')
                    print('\tFOUND ONE', existing_replaced)
                    #scigPrint.pprint_node(sgg.getNode(existing_replaced))
                    if ec2['edges']:  # pass the buck if we can
                        print('\t',end='')
                        scigPrint.pprint_edge(ec2['edges'][0])
                        rb = ec2['edges'][0]['obj']
                        print('\tPASSING BUCK : (%s -> %s -> %s)' % (curie, existing_replaced, rb))
                        irbcs[curie] = (existing_replaced, rb)
                        replaced_by[curie] = rb
                        return nodes
                    else:
                        er_node = sgv.findById(existing_replaced)
                        if not er_node['deprecated']:
                            if not er_node['curie'].startswith('NIFGA:'):
                                print('\tPASSING BUCK : (%s -> %s)' % (curie, er_node['curie']))
                                return nodes

                        print('\tERROR: could not pass buck, we are at a dead end at', er_node)  # TODO
                    print()

            moar = [t for t in sgv.findByTerm(label) if t['curie'].startswith('UBERON')]
            if moar:
                #print(moar)
                #replaced_by[curie] = moar[0]['curie']
                if len(moar) > 1:
                    print('WARNING', curie, label, [(m['curie'], m['labels'][0]) for m in moar])

                for node in moar:
                    #if node['curie'] in uberon_obsolete:  # node['deprecated']?
                        #continue
                    ns = sgg.getNode(node['curie'])
                    assert len(ns['nodes']) == 1, "WTF IS GOING ON %s" % node['curie']
                    ns = ns['nodes'][0]
                    if _doprint:
                        print('Found putative replacement in moar: (%s -> %s)' % (curie, ns['id']))
                        if DBX in ns['meta']:
                            print(' ' * 8, node['curie'], ns['meta'][DBX],
                                  node['labels'][0], node['synonyms'])

                        if AID in ns['meta']:
                            print(' ' * 8, node['curie'], ns['meta'][AID],
                                  node['labels'][0], node['synonyms'])

                        if CON in ns['meta']:
                            print(' ' * 8, node['curie'], ns['meta'][CON],
                                  node['labels'][0], node['synonyms'])

                    replaced_by[curie] = ns['id']
            else:
                replaced_by[curie] = None
                if False:  # review
                    print('NO FORWARD EQUIV', tc.red(curie), label)  # TODO
                    for k,v in sorted(sgg.getNode(curie)['nodes'][0]['meta'].items()):
                        if type(v) == iter:
                            print(' ' * 4, k)
                            for _ in v:
                                print(' ' * 8, _)
                        else:
                            print(' ' * 4, k, v)
        else:
            node = nodes[0]
            replaced_by[curie] = node['id']
            exact[curie] = node['id']

        return nodes