def gen_pdm_from_indfile(ont_url, outfile): """Reads an owl file from ont_url; Writes a JSON file (outfile) of types and annotations on individuals in the file. JSON structure: id: label: string def: string types: - isAnonymous:boolean; - relId:URI_string; - objectId:URI_string. """ ont = Brain() ont.learn(ont_url) axioms = {} if ont.knowsClass("CARO_0030002"): axioms.update(gen_pdm(ont, ont.getInstances("CARO_0030002", 0), "CARO_0030002")) # expression_patterns if ont.knowsClass("FBbt_00005106"): axioms.update(gen_pdm(ont, ont.getInstances("FBbt_00005106", 0), "FBbt_00005106")) # neurons if ont.knowsClass("FBbt_00007683"): axioms.update(gen_pdm(ont, ont.getInstances("FBbt_00007683", 0), "FBbt_00007683")) # clones jfile = open(outfile, "w") jfile.write(json.dumps(axioms, sort_keys=True, indent=4)) ont.sleep()
#!/usr/bin/env jython import json from uk.ac.ebi.brain.core import Brain import sys """Takes a list of ontology URIs as args, writes a JSON lookup of ID:name.""" out = {} for path in sys.argv[1:]: entities = [] o = Brain() o.learn(path) entities.extend(list(o.getSubClasses('Thing', 0))) entities.extend(list(o.getInstances('Thing', 0))) for e in entities: # Need check for if label exists. Should be able to do that by iterating over all annotations on class to check. Will slow things down a lot... out[e] = o.getLabel(e) o.sleep() OUT = open('id_name.json', 'w') OUT.write(json.dumps(out))
vom = ont_manager(vfb.getOntology()) # vom.typeAxioms2pdm(sfid = 'VFB_00005000') # example = [{'isAnonymous': False, 'objectId': u'FBbt_00100247'}, # {'relId': u'BFO_0000050', 'isAnonymous': True, 'objectId': u'FBbt_00003624'}, # {'relId': u'BFO_0000050', 'isAnonymous': True, 'objectId': u'FBbt_00007011'}, # {'relId': u'RO_0002292', 'isAnonymous': True, 'objectId': u'FBtp0014830'}] # Simple to use. Only issue is resolution of short_form_ids. This can be done as long as these are stored as attributes on relations. These should be added in the process of adding named relations. Check proposed schema on ticket... # Get all inds by query inds = vfb.getInstances("Thing", 0) # Could grab from neo4J avoiding Brain #statements = ["MATCH (i:Individual) RETURN i"] #r = nc.commit_list(statements) #inds = {some proc step here} # Iterate over individuals, looking up types and adding them statements = [] for i in inds: types = vom.typeAxioms2pdm(sfid = i) for t in types: if t['isAnonymous']: rel = re.sub(' ', '_', vfb.getLabel(t['relId'])) # Using related link. Can denormalise with generic edge naming script.