This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to retrieve sequences of genes list at a time from a fasta file

Hi,

I have a protein fasta file and a gene list file. I want to retrieve sequences of all genes in gene list file at one time to save time. I am using this command line:

for i in `cat  gene_list.txt` ; do grep -A1 "$i"  protein.fasta ; done

However, it only gives sequence for the last gene in the gene_list.txt file. I want to retrieve sequences of all the gene. Thank you for the help!

next-gen

By genome I meant protein. Sorry for the confusion. I have edited it in the question.

1 answer

for i in `cat  gene_list.txt` ; do grep -A1 "$i"  protein.fasta

hum, better:

grep -A1 -F -w -f gene_list.txt protein.fasta

However, it only gives sequence for the last gene in the gene_list.txt file

are you sure these are text file and not a windoz-thing ? What is the output of file gene_lists.txt protein.fasta ?

Hi, thank you! This code also gives sequence only for the last gene ID in the list. Output of file gene_lists.txt protein.fasta is:

gene_lists.txt:        ASCII text, with CRLF line terminators
protein.fasta: ASCII text, with very long lines

Convert the CRFL line terminators with Unix one (LF). The simplest way is with dos2unix or with a text editor (not suggested for huge text file).

It worked even with my previous code after converting using dos2unix. Thank you very much.

Log in to answer this question.