I have about 10,000 genome files all named by either refseq or genbank accession number, do you know if it's possible to convert these numbers to the corresponding NCBI taxon ID or species?

for example:

GCA_000005845.2 to 79781

In the case of E.coli


The file names look like this:


My operating system is Ubuntu 16.04

  • $\begingroup$ Hi and welcome to the site. Please edit your question and show us a few examples of the actual file names. If you have both refseq and genbank accessions, show examples of both. Also, please mention your operating system since some solutions might depend on it. $\endgroup$
    – terdon
    Jun 28, 2018 at 12:27
  • $\begingroup$ Thanks for the edit. So, are your filenames always accession.version_assembly_protein.faa.gz? $\endgroup$
    – terdon
    Jun 28, 2018 at 12:35
  • $\begingroup$ Yes, although they are all in different folders, for example: /refseq/archaea/GCF_000337855.1/GCF_000337855.1_ASM33785v1_protein.faa.gz $\endgroup$
    – Biomage
    Jun 28, 2018 at 12:38

2 Answers 2


Turns out I'd already written some code that did it, human memory is a funny thing.

This uses biopython to split the field description to where the species is. May not work for all NCBI files, but seems to work on most.

import Bio
from Bio import SeqIO
from Bio import AlignIO    

for record in SeqIO.parse (FILE, "fasta"):
    Speciesname = record.description.split('[', 1)[1].split(']', 1)[0]

You can use eutils to get this information as shown below:

esearch -db assembly -q 'GCF_000337855.1' | esummary | xtract -pattern DocumentSummary -element AssemblyAccession,Taxid
GCF_000337855.1 469382

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.