def fromYaml(cls, in_path): in_path = aug.RepoPath(in_path).resolve() with open(in_path, 'rt') as f: blob = yaml.safe_load(f) if 'include' in blob: orgs = [ OntResGit(path=aug.RepoPath(subblob['path']), ref=subblob['ref']) for subblob in blob['include'] ] else: orgs = [ OntResGit(path=aug.RepoPath(subblob['path']), ref=subblob['ref']) for subblob in blob['paths'] ] if not orgs: raise ValueError(f'orgs is epty for {in_path}') referenceIndex = blob['referenceIndex'] namespaces = blob['namespaces'] if isinstance(namespaces, str): namespaces = namespaces.split(' ') snchf = cls(orgs=orgs, namespaces=namespaces, referenceIndex=referenceIndex) return cls(graph=snchf.populate(OntGraph()))
def test(): snchf = SnchFile.fromYaml('../test/sneech-file.yaml') snchf.writeTtl(aug.RepoPath('../test/rando-sneech-ttl.ttl').resolve()) rp = aug.RepoPath(auth.get_path('ontology-local-repo')) wrangler = SneechWrangler(aug.RepoPath('~/git/sneechenator').expanduser()) dir_snchn = wrangler.dir_process / 'test-sneechening' if not dir_snchn.exists(): # FIXME bad workflow dir_snchn.mkdir() path_index = wrangler.path_index(snchf.index) if not path_index.exists(): path_index = wrangler.new_index( snchf.index) # FIXME move inside Sneechenator? or no path_index.commit_from_working_tree(f'new index {snchf.index}') org_index = OntResGit(path_index) expanded = snchf.write(dir_snchn) # TODO commit expanded.commit_from_working_tree(f'expanded snch file') sncher = Sneechenator(org_index, snchf.namespaces, snchf.orgs) #sncher.preSneechUpon(dir_snchn) rg, maybe_sneeches = sncher.sneechReviewGraph() # commit here I think ? # consider using ilxtr.maybeHasIlxId ? # TODO modified maybe_sneeches file + maybe list -> update list breakpoint()
def _todo(utr): # real output glb = auth.get_path('git-local-base') uberon_edit = aug.RepoPath( glb) / 'NOFORK/uberon/src/ontology/uberon-edit.obo' of = oio.OboFile(path=uberon_edit, strict=False) utr.submit_to_obofile(of, 'UBERON', uberon_id_range) of.write(overwrite=True, version=oio.OBO_VER_ROBOT)
def _parse_graph(self, graph): # there should be only one of each of these graph.debug() gen = graph[:rdf.type:snchn.SneechFile] s = next(gen) try: next(gen) raise ValueError('MORE THAN ONE SNEECH FILE IN A SINGLE FILE!') except StopIteration: pass self.identity_metadata = graph.subjectIdentity( s) # FIXME align naming with idlib when we get there self.referenceIndex = next(graph[s:snchn.referenceIndex:]) self.namespaces = list(graph[s:snchn.namespaces:]) _orgs = [] orgs = [] for bn in graph[s:snchn['include']:]: try: path = aug.RepoPath(next(graph[bn:snchn.path:])) except StopIteration: iri = next(graph[bn:snchn.iri:]) for string_path in graph[iri:snchn.hasLocalPath:]: path = aug.RepoPath(string_path).resolve() if path.exists(): break else: # TODO OntResIri failover ??? probalby not raise ValueError(f'could not find local path for {iri}') ref = next(graph[bn:snchn.ref:]) # TODO if there is a bound name use that and move the raw paths # to annotations for local sourcing of that file that can be # edited manually if needs be org = OntResGit(path, ref) dorg = org.asDeRef() _orgs.append(org) orgs.append(dorg) self._orgs = _orgs self.orgs = orgs
def __init__(self, path_repo): # TODO make sneech path configurable and passable via command line etc. rpath = aug.RepoPath(path_repo) if not rpath.exists(): self.rp_sneech = rpath self.rp_sneech.init() readme = self.rp_sneech / 'README.org' with open(readme, 'wt') as f: f.write('#+title: Sneechenator\n\nTrack the stars for your sneeches!') readme.commit_from_working_tree('first commit') self.dir_index.mkdir() self.dir_process.mkdir() else: self.rp_sneech = rpath.working_dir
def main(): #ori = OntResIri('https://alt.olympiangods.org/sparc/ontologies/community-terms.ttl') ori = OntResIri( 'http://localhost:8515/sparc/ontologies/community-terms.ttl') rdfl = oq.plugin.get('rdflib')(ori.graph, OntId) OntTerm.query_init(rdfl) utr = UpstreamTermRequests() _todo(utr) return # test output tof = oio.OboFile() utr.submit_to_obofile(tof, 'FIXME', (0, float('inf'))) tof.write(path=aug.RepoPath('/tmp/uberon-new-terms.obo'), overwrite=True) ori_uberon = OntResIri('http://purl.obolibrary.org/obo/uberon.owl') ori_uberon_meta = ori_uberon.metadata() # doap:GitRepository breakpoint() return
def metadata_events(self): """ metadata about dois from the crossref events api """ events_endpoint = 'https://api.eventdata.crossref.org/v1/events' rp = aug.RepoPath(__file__) try: email = rp.repo.config_reader().get_value('user', 'email') log.warning( f'your email {email} is being sent to crossref as part of the friendly way to use their api' ) mailto = f'mailto={email}' except aug.exceptions.NotInRepoError: # TODO failover to the git repo api? mailto = '*****@*****.**' resp_obj = requests.get( f'{events_endpoint}?{mailto}&obj-id={self.handle}') resp_sub = requests.get( f'{events_endpoint}?{mailto}&subj-id={self.handle}') # TODO if > 1000 get the rest using the pagination token yield from resp_sub.json()['message']['events'] yield from resp_obj.json()['message']['events']
this_repo.checkout_diff_tracked(), ) else: post_load = lambda: None post_main = lambda: None do_mains = True default_dir = aug.AugmentedPath(__file__).parent _test_ttl = (default_dir / 'graphload-test.ttl') test_ttl = _test_ttl.as_posix() _test_owl = (default_dir / 'owl-test.ttl') test_owl = _test_owl.as_posix() _temp_git = aug.RepoPath(temp_path) / 'git-test' temp_git = _temp_git.as_posix() nsmethodsobo = (glb / 'methodsOntology/source-material/ns_methods.obo').as_posix() ### build mains mains = { 'scigraph': None, 'combinators': None, 'hierarchies': None, 'closed_namespaces':
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() olr = aug.RepoPath(auth.get_path('ontology-local-repo')) ttl = olr / 'ttl' methods = ttl / 'methods.ttl' helper = ttl / 'methods-helper.ttl' core = ttl / 'methods-core.ttl' def methods_mapping(): from pyontutils.namespaces import TEMP, ilxtr, tech from nifstd_tools import methods as m import rdflib # TODO add this to ibnode tests _before = OntResGit(methods, ref='8c30706cbc7ccc7443685a34dec026e8afbbedd1') after = OntResGit(
import pprint import unittest import augpathlib as aug from sparcur.datasets import ( Tabular, DatasetDescriptionFile, SubmissionFile, SubjectsFile, SamplesFile, remove_rule, ) from sparcur import pipelines as pipes from sparcur import exceptions as exc from .common import examples_root, template_root, project_path, temp_path, ddih template_root = aug.RepoPath(template_root) class TestTabular(unittest.TestCase): def setUp(self): self.pp = probject_path class Helper: refs = ( 'd8a6aa5f83021b3b9ea208c295a19051ffe83cd9', # located in working dir not resources 'dataset-template-1.1', 'dataset-template-1.2', 'dataset-template-1.2.1', 'dataset-template-1.2.2', 'dataset-template-1.2.3',
def pathTtl(self): olr = aug.RepoPath(auth.get_path('ontology-local-repo')) path = olr / 'ttl' / 'modality.ttl' return path