Exemplo n.º 1
0
def main():
    olr = auth.get_path('ontology-local-repo')
    ori = OntResIri('http://purl.obolibrary.org/obo/doid.owl')
    orp = OntResPath(olr / 'ttl/external/doid.owl')
    ort = ori
    g = ori.graph
    query = """
    SELECT DISTINCT ?s ?o ?l
    WHERE {
        ?s a owl:Class .
        ?s rdfs:subClassOf* <http://purl.obolibrary.org/obo/DOID_4> .
        ?s rdfs:subClassOf ?o .
        ?s rdfs:label ?l .
    }"""
    res = list(g.query(query))
    filt = [r for r in res if not isinstance(r[1], rdflib.BNode)]
    spath = 'ttl/generated/doidslim.ttl'
    go = OntGraph(path=olr / spath)
    # TODO prov record like the one we have for chebi
    go.bind('DOID', 'http://purl.obolibrary.org/obo/DOID_')
    s = rdflib.URIRef('http://ontology.neuinfo.org/NIF/' + spath)
    go.populate_from_triples(
        ((s, p, o) for p, o in
         ((rdf.type, owl.Ontology),
          (rdfs.label, rdflib.Literal("NIF DOID slim")),)))
    ds = rdflib.URIRef('http://purl.obolibrary.org/obo/DOID_4')
    go.add((ds, rdf.type, owl.Class))
    go.add((ds, rdfs.label, rdflib.Literal('disease')))
    go.populate_from_triples(
        (t for s, o, l in filt for t in
         ((s, rdf.type, owl.Class),
          (s, rdfs.subClassOf, o),
          (s, rdfs.label, l))))
    go.write()
Exemplo n.º 2
0
    def sneechReviewGraph(self,
                          source_graph,
                          namespaces,
                          sneech_file=None,
                          path_out=None):
        # TODO cache
        (already, cannot, maybe, sneeches,
         maybe_sneeches) = self.preSneech(source_graph, namespaces)
        # TODO not entirely sure about the best place to put this ...
        self.reView(source_graph, maybe_sneeches)  # FIXME dump and commit

        review_graph = OntGraph(path=path_out)
        oq.OntCuries.populate(review_graph)
        review_graph.bind('snchn', str(snchn))  # FIXME -> curies probably
        review_graph.bind('sncho', str(sncho))  # FIXME -> curies probably
        review_graph.bind('h', str(sghashes))  # FIXME -> curies probably
        if sneech_file:
            sneech_file.populate(review_graph)

        gen = self.triples_review(already, cannot, maybe, sneeches,
                                  sneech_file)
        [review_graph.add(t) for t in gen]
        # TODO hasReport -> maybe_sneeches report / reView
        # TODO snchn predicate ordering
        return review_graph, maybe_sneeches
Exemplo n.º 3
0
def npokb():
    index_graph = OntGraph(path=auth.get_path('ontology-local-repo') /
                           'ttl/generated/neurons/npokb-index.ttl')

    if index_graph.path.exists():
        index_graph.parse()

    # testing
    index_graph.bind('npokb', npokb)
    #[index_graph.add((npokb[str(i)], rdf.type, owl.Class)) for i in range(1, 11)]
    #[index_graph.add((npokb[str(i)], ilxtr.hasTemporaryId, TEMP[str(i)])) for i in range(1, 11)]

    ios = []
    for eff in ('common-usage-types', 'huang-2017', 'markram-2015',
                'allen-cell-types'):
        path = auth.get_path(
            'ontology-local-repo') / f'ttl/generated/neurons/{eff}.ttl'
        input_graph = OntGraph(path=path)
        input_graph.parse()
        output_graph = input_graph.mapTempToIndex(index_graph, npokb, TEMP)
        ios.append((input_graph, output_graph))

    input_graph, output_graph = ios[0]
    a, r, c = output_graph.subjectsChanged(input_graph)
    index_graph.write()
    # [o.write() for i, o, in ios]  # when ready
    #from sparcur.paths import Path
    #Path(index_graph.path).xopen()
    breakpoint()
Exemplo n.º 4
0
 def graph(self):
     g = OntGraph()
     OntCuries.populate(g)
     self.populate(g)
     g.bind('local', self.context)
     g.bind('apinatomy', readable)  # FIXME populate from store
     g.bind('elements', elements)
     return g
Exemplo n.º 5
0
 def build_instances(self, instances, dids):
     folder = Path(self.config.out_graph_path()).parent
     # WOW do I need to implement the new/better way of
     # managing writing collections of neurons to graphs
     neuron_uri = next(NeuronACT.out_graph[:rdf.type:owl.Ontology])
     name = 'allen-cell-instances.ttl'
     base, _ = neuron_uri.rsplit('/', 1)
     uri = rdflib.URIRef(base + '/' + name)
     metadata = ((uri, rdf.type, owl.Ontology),)
     instance_graph = OntGraph(path=folder / name)
     instance_graph.bind('AIBSSPEC', AIBSSPEC)
     instance_graph.bind('npokb', npokb)
     [instance_graph.add(t) for t in metadata]
     [instance_graph.add(t) for t in instances]
     [instance_graph.add(t) for t in allDifferent(None, distinctMembers(*dids))]
     instance_graph.write()
Exemplo n.º 6
0
def npokb_mapping():
    index_graph = OntGraph(path=auth.get_path('ontology-local-repo') /
                           'ttl/generated/neurons/npokb-index.ttl')

    if index_graph.path.exists():
        index_graph.parse()

    # testing
    index_graph.bind('npokb', npokb)
    #[index_graph.add((npokb[str(i)], rdf.type, owl.Class)) for i in range(1, 11)]
    #[index_graph.add((npokb[str(i)], ilxtr.hasTemporaryId, TEMP[str(i)])) for i in range(1, 11)]

    ios = []
    for eff in (
            'common-usage-types',
            'huang-2017',
            'markram-2015',
            'allen-cell-types',
    ):
        # FIXME if the index id is already being used it is still added as a temp id incorrectly
        path = auth.get_path(
            'ontology-local-repo') / f'ttl/generated/neurons/{eff}.ttl'
        org = OntResGit(
            path, ref='HEAD'
        )  # HEAD is default but just for clarity set it explicitly here
        prev_graph = org.graph
        input_graph = OntGraph(path=path)
        input_graph.parse()
        mapped_graph = input_graph.mapStableIdentifiers(
            prev_graph, ilxtr.origLabel)
        output_graph = mapped_graph.mapTempToIndex(index_graph, npokb, TEMP)
        ios.append((mapped_graph, output_graph))

    mapped_graph, output_graph = ios[0]
    a, r, c = output_graph.subjectsChanged(mapped_graph)
    index_graph.write()
    [o.write() for i, o, in ios]  # when ready
    #from sparcur.paths import Path
    #Path(index_graph.path).xopen()
    breakpoint()
Exemplo n.º 7
0
def fixns(g):
    ns = rdflib.Namespace(dict(g.namespace_manager)[''])
    nsb = ns + 'pCL_'
    nsu = ns + 'UBERON_'
    nsc = ns + 'CL_'

    ng = OntGraph()
    ng.namespace_manager.populate_from(g)
    ng.bind('ilxtr', ilxtr)
    ng.bind('CL', CL)
    ng.bind('pCL', pCL)
    ng.bind('UBERON', UBERON)
    ng.bind('NCBITaxon', NCBITaxon)
    ng.bind('HGNC', HGNC)
    ng.bind('LOC', LOC)
    ng.populate_from_triples(
        (rdflib.URIRef(str(e.replace(nsb, pCL))) if e.startswith(nsb) else
         (rdflib.URIRef(str(e.replace(nsu, UBERON))) if e.startswith(nsu) else
          (rdflib.URIRef(str(e.replace(nsc, CL))) if e.startswith(nsc) else e))
         for e in t) for t in g)

    return ng