-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathapi_access.py
More file actions
143 lines (109 loc) · 4.13 KB
/
Copy pathapi_access.py
File metadata and controls
143 lines (109 loc) · 4.13 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#Import libraries
import requests
def write_output_file (file, graph_id, node_id, original_name, preferred_name):
"""
write outputfile
"""
file.writerow({'graph_id': graph_id, #graph id
'node_id': node_id, # node identifier
'original_node_name': original_name, #original node name
"preferred_node_name":preferred_name}) #prederred node name
def access_MESH_API(node_id):
"""
Return preferred name of MESH identifiers
"""
session = requests.Session()
node_id = node_id.strip("MESH:")
api_access = f"https://id.nlm.nih.gov/mesh/lookup/details?descriptor={node_id}"
#print(api_access)
with session.get(api_access) as res:
res = res.json()
preferred_name = [term["label"] for term in res["terms"]if term["preferred"] == True]
return (preferred_name[0])
def access_GO_API(node_id):
"""
Return preferred name of GO identifiers
"""
session = requests.Session()
api_access = f"http://api.geneontology.org/api/ontology/term/{node_id}"
#print(api_access)
with session.get(api_access) as res:
res = res.json()
preferred_name = res["label"]
return preferred_name
def access_UniProt_API(node_id):
"""
Return preferred name of UniProt identifiers
"""
session = requests.Session()
node_id = node_id.strip("UniProt:")
try:
api_access = f"https://www.ebi.ac.uk/proteins/api/proteins/P{node_id}"
#print(api_access)
with session.get(api_access) as res:
res = res.json()
try:
preferred_name = res["protein"]["recommendedName"]["fullName"]["value"]
except:
preferred_name = res["protein"]["recommendedName"]["shortName"]["value"]
return preferred_name
except:
api_access = f"https://www.ebi.ac.uk/proteins/api/proteins/{node_id}"
#print(api_access)
with session.get(api_access) as res:
res = res.json()
try:
preferred_name = res["protein"]["recommendedName"]["fullName"]["value"]
except:
preferred_name = res["protein"]["recommendedName"]["shortName"]["value"]
return preferred_name
def access_nodenormalizer_API(node_id):
"""
Return preferred name of HP,NCBITaxon, UBERON,REACT, PR identifiers
"""
session = requests.Session()
prefix = node_id.split(":")[0]
_id = node_id.split(":")[1]
api_access = f"https://nodenormalization-sri.renci.org/1.3/get_normalized_nodes?curie={prefix}%3A{_id}&conflate=true"
#print(api_access)
with requests.get(api_access) as res:
res = res.json()
preferred_name = res[node_id]["id"]["label"]
return preferred_name
def access_mychem_API(node_id):
"""
Return preferred name of CHEBI
"""
session = requests.Session()
api_access = f"http://mychem.info/v1/chem/{node_id}"
#print(api_access)
with requests.get(api_access) as res:
res = res.json()
try:
preferred_name = (res["chebi"]["name"])
return preferred_name
except:
preferred_name = (res["aeolus"]["drug_name"])
return preferred_name
def access_interpro_API(node_id):
"""
Return preferred name of InterPro
"""
node_id = node_id.strip("InterPro:IPR")
session = requests.Session()
api_access = f"https://www.ebi.ac.uk/interpro/api/protein/reviewed/entry/interpro/ipr{node_id}"
with requests.get(api_access) as res:
res = res.json()
preferred_name = res["results"][0]["metadata"]["name"]
return preferred_name
def access_pfam_API(node_id):
"""
Return preferred name of Pfam
"""
node_id = node_id.strip("Pfam:")
session = requests.Session()
api_access = f"https://www.ebi.ac.uk/interpro/api/entry/pfam/pf{node_id}"
with requests.get(api_access) as res:
res = res.json()
preferred_name = res["metadata"]["name"]["name"]
return preferred_name