1
$\begingroup$

I have a list of scientific names of species. Is there a python module that can fetch NCBI taxonomy IDs?

$\endgroup$
1

3 Answers 3

1
$\begingroup$

This isn't a Python library, but it's easily invoked from Python code, easy to install, and has a lot of useful features.

I just discovered the amazing taxonkit library this week. In particular, the taxonkit name2taxid command seems to be what you're looking for.

$ cat NAMES
Polistes dominula
Sinorhizobium meliloti
Gossypium hirsutum
$ cat NAMES | taxonkit name2taxid
Polistes dominula       743375
Sinorhizobium meliloti  382
Gossypium hirsutum      3635

Easily installed using conda install taxonkit.

$\endgroup$
1
$\begingroup$

Biopython has an efetch frontend.

from Bio import Entrez
Entrez.email = "[email protected]" 
handle = Entrez.efetch(db="nucleotide", id="KR052012.1", rettype="gb", retmode="text")
print(handle.read())

OUT

LOCUS KR052012 10714 bp RNA linear VRL 09-MAY-2015 DEFINITION Dengue virus strain Hb33/CHN/2014, complete genome. ACCESSION KR052012 VERSION KR052012.1 KEYWORDS
.... etc

You will likely need to perform an EFetch search and then extract out the accession numbers for import (as done above)

$\endgroup$
0
$\begingroup$

If you want to perform a species search, here's the raw efetch code. I use this within an alias and the complex quotes are needed for complicated reasons. The reg-ex may need to be adapted to your search. $virus here is your species of interest, e.g. set virus='some species' (csh or tcsh), `virus='some species' (bash). You'll just need to translate this to Biopython.

alias esummary-acc \
'esearch -db protein -query "$virus" |\
efetch -format docsum |\
xtract -pattern DocumentSummary -element Title,AccessionVersion |\
grep "$virus" |\
perl -p -e '"'"'s/^.*\[.*\]\s+(\w+)/$1/'"'"''
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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