Hi,
I'm using the Ensembl REST api to retrieve protein sequences from transcript ids in a python pipeline https://rest.ensembl.org/documentation/info/sequence_id
Is there a way to provide all my transcript ids in one request? Because right now, I'm doing a for loop for each id, launching a request each time and it's kinda slow. As an alternative, I guess that I could do the same myself using the human proteome from Uniprot.
Another question, as seen in the examples from the documentation
import requests, sys
server = "https://rest.ensembl.org"
ext = "/sequence/id/ENST00000288602?type=protein"
r = requests.get(server+ext, headers={ "Content-Type" : "text/x-fasta"})
if not r.ok:
r.raise_for_status()
sys.exit()
print(r.text)
The request stops if it goes bad, which it sometimes does in my case (mapping issue, deprecated ids etc), returning :
Traceback (most recent call last):
File "/Users/test_field/pipeline2.py", line 123, in <module>
r.raise_for_status()
File "/opt/homebrew/lib/python3.9/site-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://rest.ensembl.org/sequence/id/ENST00000611534?type=protein
and the whole script stops. Which it's supposed to do because the sys.exit() but if I remove it or replace it with a continue, the script stops nonetheless. How can I keep the loop running while catching which ids couldn't retrieve a sequence? I guess it has to do with exception and catching and all but I'm not familiar at all with it so if someone has a quick answer or a resource to link, I would appreciate it. If I remove the whole if not r.ok: then the script seems to keep running but I loose the information of which ids is wrong.
Thank you,
Maxime
Have you tried - https://rest.ensembl.org/documentation/info/sequence_id_post, POST instead of GET? I have used POST to access multiple transcript information at once and it seemed to work fine
Just to add some extra help here: manaswwm is correct- we would advise using the POST endpoints for batch queries using the Ensembl REST API. There is a free online course that walks through the Ensembl REST API and covers POST queries in module 6: https://www.ebi.ac.uk/training/online/courses/ensembl-rest-api/take-the-course/