def ID_to_label_lookup(self, ID): result = [] onto_result = [] mesh_result = [] hgnc_result = [] if ID.startswith('MESH'): try: ID_split = ID.split(':') ID_split[0] = ID_split[0].lower() mesh_ID_formatted = ID_split[0]+':'+ID_split[1] url = "http://id.nlm.nih.gov/mesh/sparql" mesh_response = MeshKS(ServiceContext.create_context(), url).get_label_by_id(mesh_ID_formatted) mesh_result = result + [{ "id" : ID, "label" : mesh_response[0]['label']} ] except: traceback.print_exc () elif ID.lower().startswith('hgnc'): try: hgnc_service = HGNC('hgnc',ServiceContext.create_context()) result = {'id': ID} result.update(hgnc_service.get_label(ID)) hgnc_result.append(result) logger.debug(hgnc_result) except: traceback.print_exc () else: try: onto_result = result + [ { "id" : ID, "label" : self.context.core.onto.get_label (ID) }] except: traceback.print_exc () all_results = onto_result + mesh_result + hgnc_result return all_results
def test_one(infname, outfname, fieldnum): from greent.servicecontext import ServiceContext m = Mondo(ServiceContext.create_context()) n_good = 0 n_bad = 0 diseases = set() with open(infname, 'r') as inf, open(outfname, 'w') as outf: h = inf.readline() for line in inf: if line.startswith('#'): continue x = line.strip().split('\t')[fieldnum] if x in diseases: continue diseases.add(x) result = m.search(x) if len(result) == 0: mondos = '' names = '' doids = '' umlss = '' efos = '' n_bad += 1 else: n_good += 1 mondos = ';'.join(result) names = ';'.join([m.get_label(r) for r in result]) doids = ';'.join(sum([m.mondo_get_doid(r) for r in result], [])) umlss = ';'.join(sum([m.mondo_get_umls(r) for r in result], [])) efos = ';'.join(sum([m.mondo_get_efo(r) for r in result], [])) outf.write('{}\t{}\t{}\t{}\t{}\n'.format(x, mondos, doids, umlss, efos)) print('Good: {} Bad: {}'.format(n_good, n_bad))
def test_parts(uberon): uk = UberonGraphKS(ServiceContext.create_context()) results = uberon.get_anatomy_parts('UBERON:0004535') #What are the parts of the cardiovascular system? #Note that we don't use this atm, it's just here as an example curies = [x['curie'] for x in results] assert 'UBERON:0000948' in curies #heart assert 'UBERON:0001981' in curies #blood vessel
def test_chebi_input(unichem): q = UniChem(ServiceContext.create_context()) synonyms = unichem.get_synonyms("CHEBI:49575") assert len(synonyms) == 4 assert 'CHEMBL:CHEMBL12' in synonyms assert 'DRUGBANK:DB00829' in synonyms assert 'CHEBI:49575' in synonyms assert 'PUBCHEM:3016' in synonyms
def ontology(): url = "http://purl.obolibrary.org/obo/mondo.obo" ontology_file = "mondo.obo" if not os.path.exists(ontology_file): r = requests.get(url, stream=True) with open(ontology_file, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) return GenericOntology(ServiceContext.create_context(), ontology_file)
def ontology(): """ Creates and returns a GenericOntology instance. For cases relying on .obo files, this ontology relies on the mondo.obo file. """ url = "http://purl.obolibrary.org/obo/mondo.obo" ontology_file = "mondo.obo" if not os.path.exists (ontology_file): r = requests.get(url, stream=True) with open(ontology_file, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) return GenericOntology(ServiceContext.create_context(), ontology_file)
def hpo(): hpo = HPO(ServiceContext.create_context()) return hpo
def mesh(): url = "http://id.nlm.nih.gov/mesh/sparql" return MeshKS(ServiceContext.create_context(), url)
def bionames(): """ Create a bionames instance for passing in to the test functions. """ return BioNames(ServiceContext.create_context())
def mondo2(): return Mondo2(ServiceContext.create_context())
def hpo2(): return HPO2(ServiceContext.create_context())
def omnicorpus(): uberon = OmniCorp(ServiceContext.create_context()) return uberon
def pubchem(): return PubChem("pubchem", ServiceContext.create_context())
def hgnc(): return HGNC("hgnc", ServiceContext.create_context())
def unichem(): unichem = UniChem(ServiceContext.create_context()) return unichem
"Bionames is a generic facility which aggregates bio-ontology lookup services to retrieve names from IDs or IDs based on Natural Language names.", "contact": { "responsibleOrganization": "renci.org", "responsibleDeveloper": "*****@*****.**", "email": "*****@*****.**", "url": "www.renci.org", }, "termsOfService": "http://renci.org/terms", "version": "0.0.2" }, "schemes": ["https", "http"] } app.config['SWAGGER'] = {'title': 'BioNames Service'} swagger = Swagger(app, template=template) core = BioNames(ServiceContext.create_context()) cache = LRU(1000) @app.route('/lookup/<q>/<concept>/') def lookup(q, concept): """ Find ids by various methods. --- parameters: - name: q in: path type: string required: true default: asthma description: "A text string of interest. If 'include_similar' is set to true, fragments may be used. 'include_similar' also makes the search NOT case sensitive. " x-valueType:
def oxo(): oxo = OXO(ServiceContext.create_context()) return oxo
def mondo(): mondo = Mondo(ServiceContext.create_context()) return mondo
def test_unknown_curie(unichem): q = UniChem(ServiceContext.create_context()) synonyms = unichem.get_synonyms("DruggyDrug:49575") assert len(synonyms) == 0
def go(): go = GO(ServiceContext.create_context()) return go
def uniprot(): uniprot = UniProt(ServiceContext.create_context()) return uniprot
def hgnc(): hgnc = HGNC(ServiceContext.create_context()) return hgnc
def go2(): return GO2(ServiceContext.create_context())
def type_graph(conf): return TypeGraph( ServiceContext.create_context(config=conf.get('config', None)))
def chembl(): return CHEMBL("chembl", ServiceContext.create_context())