Only getting 25 results from UniProt REST ID Mapping
1
0
Entering edit mode
12 weeks ago
ngarber ▴ 50

Hello again! I'm trying to map Ensembl Proteins to UniProtKB using the REST API, but although I have 237 items in the list, only 25 results are returned.

Here is my code snippet:

ensembl_id_list = data_df["Ensembl_ID"].tolist() #Returns 237 IDs
ensembl_id_list = list(dict.fromkeys(ensembl_id_list)) #Removes duplicates

URL = 'https://rest.uniprot.org/idmapping'

params = {
   'from': 'Ensembl_Protein',
   'to': 'UniProtKB',
   'ids': ' '.join(ensembl_id_list)
}

response = requests.post(f'{URL}/run', params)
job_id = response.json()['jobId']
job_status = requests.get(f'{URL}/status/{job_id}')
d = job_status.json()

ensembl_to_uniprot_dict = {}

#Retry getting results every 1 sec until they are ready
loop_end = ""
while loop_end != "Done":
   if d.get("job_status") == 'FINISHED' or d.get('results'):
      loop_end = "Done"
      job_results = requests.get(f'{URL}/results/{job_id}')
      results = job_results.json()
      for obj in results['results']:
         ensembl_to_uniprot_dict[obj["from"]] = obj["to"]
         #print(f'{obj["from"]}\t{obj["to"]}')
      break
   time.sleep(1)

But when I query len(ensembl_to_uniprot_dict), it's only 25 entries long. What's going on and how do I fix it?

UniProt mapping Python REST Ensembl • 372 views
ADD COMMENT
4
Entering edit mode
12 weeks ago

UniProt is now undergoing major changes. In the meantime you can use job_results = requests.get(f'{URL}/results/{job_id}/?size=500'). Unfortunately, 500 is the upper limit for the number of retrieved items from UniProt's REST API. Thus if your query list of ids is longer than 500, you might want to divide the list into smaller sublists of max 500 elements each.

ADD COMMENT
0
Entering edit mode

It works!! Thanks so much; adding that /size=500 fixed the issue. My list is 237 entries long, so it fits the limit. :)

ADD REPLY
0
Entering edit mode

Great. I moved my comment to the answer. You can accept the answer if it has solved your issue.

ADD REPLY

Login before adding your answer.

Traffic: 1079 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6