def get(self, term): hgene_results = list(homologene.filter( (homologene.gene_symbol == term) or (homologene.protein_gi == term) or (homologene.protein_accession == term)) .select(homologene.gene_symbol, homologene.ce_gene_name, homologene.species) .distinct() .dicts().execute()) wbgene_results = list(wb_orthologs.filter( (wb_orthologs.gene_symbol == term) or (wb_orthologs.ortholog == term)) .select(wb_orthologs.gene_symbol, wb_orthologs.ce_gene_name, wb_orthologs.species) .distinct() .dicts().execute()) for x in hgene_results: x.update({"source": "homologene"}) for x in wbgene_results: x.update({"source": "wormbase"}) homologs = hgene_results + wbgene_results # For genes that can't be looked up, fetch coordinates. for x in homologs: if x["ce_gene_name"].find(".") > 0: try: gene = wb_gene.get( wb_gene.sequence_name == x["ce_gene_name"]) x.update( {"CHROM": gene.CHROM, "start": gene.start, "end": gene.end}) except: del x result = hgene_results + wbgene_results return jsonify(result)
def omim(gene_name): gene_id = wb_gene.get(Name = gene_name) r = requests.get('http://www.wormbase.org/rest/widget/gene/%s/human_diseases' % gene_id.Name, headers = {'Content-Type': 'application/json; charset=utf-8'}).json() r = r["fields"]["human_diseases"]["data"] omim_models, omim_genes, omim_diseases, response = {}, [], [], {} if r: if "potential_model" in r: omim_models = {x["id"]:x["label"] for x in r["potential_model"]} if "gene" in r: omim_genes = r["gene"] if "disease" in r: omim_diseases = r["disease"] api_key = ds.get(ds.key("credential", "OMIM"))["apiKey"] omim_url = "http://api.omim.org/api/entry?mimNumber={omim_ids}&apiKey={api_key}" omim_url = omim_url.format(omim_ids = ','.join(omim_genes + omim_diseases), api_key = api_key) omim_results = requests.get(omim_url).text dom = minidom.parseString(omim_results) omim_results = {x[1].firstChild.nodeValue: x[0].firstChild.nodeValue for x in zip(dom.getElementsByTagName("preferredTitle"), dom.getElementsByTagName("mimNumber"))} response = {"omim_diseases": {x: omim_results[x] for x in omim_diseases}, "omim_genes" : {x: omim_results[x] for x in omim_genes}} return jsonify(response)