This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to change the header of input file

I have a fasta file input, I want change the header in my way like

>AGP1
AAAAAAAAAAAACTCAAAAG
>CRK25
AAAAAAAAAAAACTTTGAACTTGCTT
AT5G27080
AAAAAAAAAAAAGAAAGAA
>AT1G12620
AAAAAAAAAAACAAATT

I want output in this way

>chromosome1
AAAAAAAAAAAACTCAAAAG
>chromosome2
AAAAAAAAAAAACTTTGAACTTGCTT

change all the header in input file with chromosome

and chromosome number like chromosome1 , chromosome2... is equal to number of headers present in input file.

is there way to resolve this problem by using sed awk or shell script?

please suggest me

thank you in advance

fasta awk sed

3 answers

Hi take a look at the

Renaming Entries In A Fasta File

hope it helps,

$ awk 'BEGIN { seqIdx = 0; } { if (/^>/) { print ">chromosome"seqIdx; seqIdx++; } else { print $0; } }' in.fa > out.fa

Dear Sir Alex thank you for your fruitful suggestions.

Perl One Liner:

perl -nle '(/>/) ? print ">chromosome" . ++$n : print' < FileIn.fa > FileOut.fa

Dear Sir JC thank you for your fruitful suggestions.

Log in to answer this question.