This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract protein files from nucleotide accession numbers

Hey everyone,

I would like to extract all proteins, using a list of nucleotide accession numbers as input. For example, considering the list.txt with the following accessions:

NC_008803.1
NCVQ01000001.1
NC_039364.1
NC_005101.4

I would like to extract the protein files for all coding sequences within each one of these nucleotide accession numbers.

Thanks!

sequence

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.
code_formatting

1 answer

You can use Entrez Direct for this as shown below:

$ cat accs.txt
NC_008803.1
NCVQ01000001.1
NC_039364.1
NC_005101.4

$ epost -db nuccore -input accs.txt -format acc \
| elink -target protein \
| efetch -format fasta 
>NP_001008767.1 thioredoxin-interacting protein [Rattus norvegicus]
MVMFKKIKSFEVVFNDPEKVYGSGEKVAGRVTVEVCEVTRVKAVRILACGVAKVLWMQGSQQCKQTLDYL

However, for the four accessions in your list, nearly 24000 proteins are returned. Downloading that many proteins using efetch can quickly become a time-consuming process. If you are doing this for entire chromosomes, you may be better off with the following three-step approach:

  1. use efetch with the parameter -format acc to download a list of protein accessions
  2. downloading the entire protein datasets for the organisms of your interest from NCBI FTP
  3. use a different program such as seqkit to extract the specific protein accessions of interest

Thanks for the reply. Your solution works well, but it outputs tons of proteins with no link to the chromosome. I would like to link the extracted proteins to the chromosome. Any solution?

Which solution are you talking about? The one using efetch or the one where you download from from FTP path?

If you download the entire protein.faa.gz file(s) from FTP, there is another file ending in feature_table.txt.gz in the same path. It should have information about which chromosome each protein is annotated on.

If you want to do this using esearch/efetch method then you'd have to skip the epost step and do this for each acc using a bash loop as shown below:

for acc in `cat accs.txt`; do 
esearch -db nuccore -query ${acc} \
    | elink -target protein \
    | efetch -format acc \
    | sed "s/^/${acc}\t/g" ; 
done

This will produce a tab-delimited file with <chromosome> <tab> <protein_acc> fields.

Log in to answer this question.