generated from Wang-Bioinformatics-Lab/Flask_Website_Basic_Template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ontology_utils.py
41 lines (35 loc) · 1.41 KB
/
ontology_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import requests
import json
"""Resolving ontologies only if they need to be"""
def resolve_ontology(attribute, term):
if attribute == "ATTRIBUTE_BodyPart":
url = "https://www.ebi.ac.uk/ols/api/ontologies/uberon/terms?iri=http://purl.obolibrary.org/obo/%s" % (term.replace(":", "_"))
try:
requests.get(url)
ontology_json = json.loads(requests.get(url).text)
#print(json.dumps(ontology_json))
return ontology_json["_embedded"]["terms"][0]["label"]
except KeyboardInterrupt:
raise
except:
return term
if attribute == "ATTRIBUTE_Disease":
url = "https://www.ebi.ac.uk/ols/api/ontologies/doid/terms?iri=http://purl.obolibrary.org/obo/%s" % (term.replace(":", "_"))
try:
ontology_json = requests.get(url).json()
return ontology_json["_embedded"]["terms"][0]["label"]
except KeyboardInterrupt:
raise
except:
return term
if attribute == "ATTRIBUTE_DatasetAccession":
try:
url = f"https://massive.ucsd.edu/ProteoSAFe//proxi/v0.1/datasets?filter={term}&function=datasets"
dataset_information = requests.get(url).json()
return dataset_information["title"]
except KeyboardInterrupt:
raise
except:
return "Not Available"
#raise Exception(url)
return term