Determining Phylum From .Faa Files?
Entering edit mode
12.3 years ago
Greg ▴ 50

I have a large number of .faa files that I want to be able to organize according to taxonomic group.

Is there a file that exists that will associate gi numbers in .faa files to which taxonomic group (phylum) they belong to?

taxonomy identifiers • 3.8k views
Entering edit mode
Entering edit mode

Almost ... he appears to be asking for the larger taxonimic groups then just organism. Perhaps someone knows a way to go from TaxID to Phylum level information.

Entering edit mode
12.3 years ago
Neilfws 49k

Using the dumped taxonomy files in the NCBI FTP site is a good suggestion. You can also do this programmatically, with a little work.

Assuming that the *.faa file is from the NCBI, it should contain a standard header which includes the GI identifier. For example, the header for this fasta file looks like this:

>gi|298501435|ref|NC_014250.1| 'Nostoc azollae' 0708 plasmid pAzo02, complete sequence

You extract the GI (298501435) and use it for an EUtils ELink query, to find the Taxonomy ID for the sequence. For example:

curl ""

This returns XML, which you can parse for the Taxonomy ID. The relevant part of the XML looks like this:


Now you can use the Taxonomy ID (551115) in an EUtils EFetch query, to return the complete record in XML from the Entrez taxonomy database:

curl ""

Finally, you again need to parse this XML to find the phylum. The relevant part looks like this:


Here is a quick and dirty script written in Ruby to illustrate. It uses some libraries: BioRuby to parse the fasta sequence and interact with NCBI, open-uri for the ELink query and Crack to parse the XML. Note that it has only been tested using the example fasta file mentioned previously and comes with no tests, exception handlers or guarantees.


require "rubygems"
require "bio"
require "crack"
require "open-uri"

Bio::NCBI.default_email = ""
ncbi  =
fasta = "nostoc.faa"
ff    =, fasta)

while fe = ff.next_entry
  gi      =
  phylum  = ""
  tax     = open("{gi}").read
  tax     = Crack::XML.parse(tax)
  taxid   = tax['eLinkResult']['LinkSet']['LinkSetDb']['Link']['Id']
  taxdata = ncbi.efetch(taxid, {"report" => "xml", "db" => "taxonomy", "mode" => "text"})
  taxdata = Crack::XML.parse(taxdata)
  taxdata['TaxaSet']['Taxon']['LineageEx']['Taxon'].each do |t|
    if t['Rank'] == "phylum"
      phylum = t['ScientificName']
  puts "#{gi}\t#{phylum}"

Result: it prints the sequence GI and the phylum:

298501435       Cyanobacteria
Entering edit mode
12.3 years ago
Will 4.5k

Looking at the NCBI FTP site there is a file taxdump_readme.txt which implies that nodes.dmp is the file that you probably need. It can be downloaded from

So you can use the .faa files to determine the GI for each entry. Then use gi_taxid.dmp to determine the species-level classification. Then use the nodes.dmp file to determine which phylum each TaxID belongs to.


Login before adding your answer.

Traffic: 2031 users visited in the last hour
Help About
Access RSS

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

Powered by the version 2.3.6