Hi I am trying to get the cancer ontologies (obo_id and label) from EBI-OLS. Earlier I have used the below code to get the obo_id
terms and labels
descendants = requests.get(
"https://www.ebi.ac.uk/ols/api/ontologies/efo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMONDO_0004992/descendants"
)
As there are more than 1 page so I created total_pages
total_pages = descendants.json()["page"]["totalElements"] // 1000 + 1
cancer_id = []
for i in range(total_pages):
## Check the number of id's present in 'totalElements'
des = {"page": i, "size": descendants.json()["page"]["totalElements"]}
## Add the number of 'totalElements' and 'pages' in the new python request for descendants
cancer_efo = requests.get(
"https://www.ebi.ac.uk/ols/api/ontologies/efo/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMONDO_0004992/descendants",
params=des,
)
## Get the number of obo_id's present in the cancer_efo.json
obo = [obj["obo_id"] for obj in cancer_efo.json()["_embedded"]["terms"]]
## Get the number of cancer labels present in the cancer_efo.json
label = [obj["label"] for obj in cancer_efo.json()["_embedded"]["terms"]]
data = zip(obo, label)
cancer_id.extend(data)
The above code worked pretty well with one link Now the issue is that I want to get ontologies for 37 descendent links and maximum links have more than 1 page. I want to get one file (cancer_id) containing all obo_id's and labels from these all 37 links.
I made a separate file called list.txt
(Right now I am copying only 3 here)
list.txt
https://www.ebi.ac.uk/ols/api/ontologies/ncit/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FNCIT_C4861/descendants
https://www.ebi.ac.uk/ols/api/ontologies/ncit/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FNCIT_C3171/descendants
https://www.ebi.ac.uk/ols/api/ontologies/ncit/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FNCIT_C3457/descendants
I tried the below code but it is not working
import requests
with open ('list.txt', 'r') as fin:
links = fin.readlines()
def requestIt(links):
cancer_all = requests.get(links)
return cancer_all.json()
data = list(map(requestIt, links))
obo = obj["obo_id"] for obj in data
The error is
obo = obj["obo_id"] for obj in data
^
SyntaxError: invalid syntax