This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to replace the headers in a fasta files with same keyword?

Hi

I have thousands(1000's) of fasta files in one directory, I want to replace all the fasta file headers with the same keyword >Gast_superba ??

suggestions.

gene genome

Do you want to add Gast_superba in to the description line of the entries following the caret in each one and leave the rest of the previous description line? A few examples of what you have and what you want for each entry in the file would make sure you got the best advice. Because I wonder if I have it backwards, and you want to replace all those occurences with something different, similar to here.

This sounds like the fastest way to do this would be to use a shell script to iterate on the FASTA files matching your extension, see here, and then use sed to the a find/replace on the header line, see here. If I understand correctly you replace every caret with >Gast_superba.

There's a lot of similar answers already in Biostars if you look around.

Replacing the header name of each fasta file (10000's) in a directory, I solved it writting a loop.

awk '/>/{print ">Gast_superba"}!/>/' *.fasta > con.fasta

Original file

head -n1 data1.fasta
>clostridium buryricum TOA

Modified file

head -n1 data1.fasta
 >Gast_superba
$ awk '/>/{print ">Gast_superba"}!/>/' test.fa
$ sed '/^>/ s/.*/>Gast_superba/' test.fa

1 answer

At the risk of sounding redundant after Wayne's answer, I think you should be able to use the following command in Unix:

sed 's/>.*/>Gast_superba/' *.fasta

Log in to answer this question.