Downloading NCBI genomes from a given taxonomy

The Entrez Direct toolkit is great for programmatic access to all of NCBI’s resources. This little snippet below finds all of the refseq representative genomes for a given NCBI taxonomy ID, makes a little summary of the genomes downloaded and uses wget to download the genbank files from the Assembly FTP. Change the inital query in the first call to esearch to change what genomes are downloaded.

esearch -db assembly -query "txid28890[Organism:exp] AND representative [PROP]" |\
 efetch -format docsum |\
 xtract -pattern DocumentSummary -element \
    AssemblyAccession SpeciesTaxid SpeciesName FtpPath_RefSeq |\
 sed 's/,.*//' |\
 sort -k 3,3 |\
 tee downloaded_genomes.tsv |\
 cut -f 4 |\
 sed -e 's/$/\/*genomic.gbff.gz/' |\
 wget -i /dev/stdin

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s