4
$\begingroup$

I'm trying to make a Biopython script that reproduces a manual search on the NCBI website.

My manual search gives me the following URL:

https://www.ncbi.nlm.nih.gov/nuccore?term=ANOS1[gene%20name]%20AND%20refseq[filter]

And the "Search details" box indicates:ANOS1[gene name] AND refseq[filter].

I get 338 results that I "Send to" "File" as "GI List", save as ANOS1_orthologs_manual.txt.

How can I do the same using Biopython?

$\endgroup$
6
$\begingroup$

This can be done by using the "Search details" as a search term in Entrez.esearch:

import os
OPJ = os.path.join
base_dir = os.getcwd()

from Bio import Entrez
Entrez.email = "my_email_here"
query = "ANOS1[gene name] AND refseq[filter]"
handle = Entrez.esearch(term=query, db="nuccore", retmax=400)
ids = Entrez.read(handle)["IdList"]
with open(OPJ(base_dir, "ANOS1_orthologs_max400_ids.txt"), "w") as ids_file:
    ids_file.write("\n".join(ids))
    ids_file.write("\n")
$\endgroup$
5
  • $\begingroup$ Rubber duck debugging at its finest :) $\endgroup$
    – terdon
    Mar 9 '18 at 12:45
  • $\begingroup$ @terdon I did not know this expression. I learned something new today :). Regarding off-topicness, I think the question can still be useful to others, in that it gives an almost-working example of something one may try to do in a bioinformatics context. $\endgroup$
    – bli
    Mar 9 '18 at 13:28
  • $\begingroup$ useful, yes, but not on topic since the actual problem was a very simple mistake and therefore the answer is unlikely to help others. You could, if you want, change it around: ask how you can reproduce the manual search in python and then post your (corrected) solution as an answer. That would be great! $\endgroup$
    – terdon
    Mar 9 '18 at 13:30
  • $\begingroup$ @terdon I see your point. I updated the question and answer. $\endgroup$
    – bli
    Mar 9 '18 at 13:37
  • $\begingroup$ Perfect, thanks! I would upvote, but I already had :) $\endgroup$
    – terdon
    Mar 9 '18 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.