Exemplo n.º 1
0
def main():
    Query = namedtuple('Query', ['root','relationshipType','direction','depth'])

    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()
Exemplo n.º 2
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.º 3
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 = ''
    s_existing_id = None
    s_existing_label = None
Exemplo n.º 4
0
Tuesday 3.5
Th 1hr + 2:30-6:05
"""

import re
import numpy
import collections
from pyontutils.scigraph_client import Graph, Vocabulary
import json
import csv
from collected import data  # imports data from a previous py file
from collections import defaultdict, namedtuple
from IPython import embed

g = Graph()

with open("species_data.csv", "rt") as f:
    species_rows = [r for r in csv.reader(f)]
    species_labels = species_rows[0]
    species_labels[0] = "Categories"
    species_rows = species_rows[1:]
with open("cell_layer_data.csv", "rt") as f:
    layer_rows = [r for r in csv.reader(f)]
    layer_labels = layer_rows[0]
    layer_labels[0] = "Categories"
    layer_rows = layer_rows[1:]
with open("brain_region_data.csv", "rt") as f:
    brain_rows = [r for r in csv.reader(f)]
    brain_labels = brain_rows[0]
    brain_labels[0] = "Categories"
Exemplo n.º 5
0
#!/usr/bin/env python3
import csv
from pyontutils.scigraph_client import Graph

g = Graph('http://localhost:9000/scigraph')

with open('/tmp/nlx_154697_8.csv','rt') as f:
    rows = [r for r in csv.reader(f)]
    header = rows[0]
    index = {name:index for index, name in enumerate(header)}
    rows = rows[1:]

dbx = 'http://www.geneontology.org/formats/oboInOwl#hasDbXref'
with open('/tmp/nlx_154697_8_fma.csv','wt') as f:
    writer = csv.writer(f)
    writer.writerow(header[:index['identifier']+1] + ['fma_id'] + header[index['identifier']+1:])
    for row in rows:
        fma_id = ''
        id_ = row[index['identifier']]
        if id_.startswith('UBERON'):
            meta = g.getNode(id_)['nodes'][0]['meta']
            if dbx in meta:
                xrefs = meta[dbx]
                for ref in xrefs:
                    if ref.startswith('FMA:'):
                        fma_id += ref

        writer.writerow(row[:index['identifier']+1] + [fma_id] + row[index['identifier']+1:])


Exemplo n.º 6
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()