Exemplo n.º 1
0
#!/usr/bin/env python3

import csv
from os.path import expanduser
import rdflib
from pyontutils.scigraph_client import Vocabulary, Graph
from IPython import embed

dbx = 'http://www.geneontology.org/formats/oboInOwl#hasDbXref'

with open(expanduser('~/git/entity_mapping/mappings/uberon-nervous'),
          'rt') as f:
    brain_only = set([l.strip() for l in f.readlines()])

v = Vocabulary('http://localhost:9000/scigraph')
sg = Graph('http://localhost:9000/scigraph')

g = rdflib.Graph()
g.parse(expanduser('~/git/NIF-Ontology/ttl/generated/cocomacslim.ttl'),
        format='turtle')
sos = [so for so in g.subject_objects(rdflib.RDFS.label)]

map_ = []
smap_ = []
fma_lookup = {}
for s, o in sos:
    cc_id = g.qname(s)
    cc_label = o.toPython()
    existing_id = None
    existing_label = None
    existing_fma = ''
Exemplo n.º 2
0
def main():
    sgg = Graph(cache=True)
    sgg_local = Graph('http://localhost:9000/scigraph', cache=True)

    cell = Query("GO:0044464", 'subClassOf', 'INCOMING', 9)
    nifga = Query('NIFGA:birnlex_796',
                  'http://www.obofoundry.org/ro/ro.owl#has_proper_part',
                  'OUTGOING', 9)
    uberon = Query('UBERON:0000955',
                   'http://purl.obolibrary.org/obo/BFO_0000050', 'INCOMING', 9)
    uberon_ae = Query('UBERON:0001062', 'subClassOf', 'INCOMING',
                      9)  # anatomical entity
    uberon_cc = Query('UBERON:0002749',
                      'http://purl.obolibrary.org/obo/BFO_0000050', 'INCOMING',
                      9)
    ncbi_ins = Query('NCBITaxon:50557', 'subClassOf', 'INCOMING', 10)
    ncbi_rod = Query('NCBITaxon:9989', 'subClassOf', 'INCOMING', 10)

    queries = cell, nifga, uberon, uberon_cc
    queries = ncbi_ins, ncbi_rod, uberon, nifga
    queries = uberon_ae,

    fma3_r = Query('FMA3:Brain',
                   'http://sig.biostr.washington.edu/fma3.0#regional_part_of',
                   'INCOMING', 9)
    fma3_c = Query(
        'FMA3:Brain',
        'http://sig.biostr.washington.edu/fma3.0#constitutional_part_of',
        'INCOMING', 9)
    #fma3_tree, fma3_extra = creatTree(*fma3_r, graph=sgg_local)

    fma_r = Query('FMA:50801', 'http://purl.org/sig/ont/fma/regional_part_of',
                  'INCOMING', 20)
    fma_c = Query('FMA:50801',
                  'http://purl.org/sig/ont/fma/constitutional_part_of',
                  'INCOMING', 20)
    fma_rch_r = Query('FMA:61819',
                      'http://purl.org/sig/ont/fma/regional_part_of',
                      'INCOMING', 20)
    #fma_tree, fma_extra = creatTree(*fma_r, graph=sgg_local)
    #fma_tree, fma_extra = creatTree(*fma_rch_r, graph=sgg_local)

    fma_hip = Query('FMA:275020',
                    'http://purl.org/sig/ont/fma/regional_part_of', 'BOTH', 20)
    fma_hip = Query('FMA:275020',
                    'http://purl.org/sig/ont/fma/constitutional_part_of',
                    'BOTH', 20)
    #fma_tree, fma_extra = creatTree(*fma_hip, graph=sgg_local)

    fma_mfg = Query('FMA:273103',
                    'http://purl.org/sig/ont/fma/regional_part_of', 'BOTH', 20)
    #fma_tree, fma_extra = creatTree(*fma_mfg, graph=sgg_local)

    ncbi_metazoa = Query('NCBITaxon:33208', 'subClassOf', 'INCOMING', 20)
    ncbi_vertebrata = Query('NCBITaxon:7742', 'subClassOf', 'INCOMING', 40)
    #ncbi_tree, ncbi_extra = creatTree(*ncbi_vertebrata, graph=sgg_local)

    fma_tel = Query('FMA:62000',
                    'http://purl.org/sig/ont/fma/regional_part_of', 'INCOMING',
                    20)
    DOFMA = False
    if DOFMA:
        fma_gsc_tree, fma_gsc_extra = creatTree(*fma_tel, graph=sgg_local)

        childs = list(
            fma_gsc_extra[2]
        )  # get the curies for the left/right so we can get parents for all
        from heatmaps.scigraph_client import Graph
        g = Graph('http://localhost:9000/scigraph')
        parent_nodes = []
        for curie in childs:
            json = g.getNeighbors(curie, relationshipType='subClassOf')
            if json:
                for node in json['nodes']:
                    if node['id'] != curie:
                        parent_nodes.append(node)  # should have dupes

        embed()
        return

    uberon_tree, uberon_extra = creatTree(
        *uberon,
        graph=sgg)  # ,url_base='localhost:9000')  # FIXME why does this crash?

    print(uberon_tree)
    print(uberon_extra[0])
    embed()
    return

    uberon_flat = [n.replace(':', '_') for n in flatten(uberon_extra[0])]
    with open('/tmp/uberon_partonomy_terms', 'wt') as f:
        f.writelines('\n'.join(uberon_flat))

    for query in queries:
        tree, extra = creatTree(*query, graph=sgg)
        dematerialize(list(tree.keys())[0], tree)
        print(tree)
        #print(extra[0])
        with open('/tmp/' + query.root, 'wt') as f:
            f.writelines(tree.print_tree())

        level_sizes = [len(levels(tree, i)) for i in range(11)]
        print('level sizes', level_sizes)
        parent_counts = np.unique([len(v) for v in extra[-4].values()])
        print('unique parent counts', parent_counts)
        print('num terms', len(extra[2]))

    embed()