This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Modify chromosome name in fasta file

I have a fasta file with chromosome naming starting with

NW_018085366.1, NW_018085367.1, ..NC_010450.4

and I want to add chr ahead of it.

chrNW_018085366.1, chrNW_018085367.1, ..chrNC_010450.4

I tried to fix but it just rename whole chromosome. Is there a way to ass chr ahead of it. I will be thankful for the suggestion.

fasta chromosome genome name

2 answers

Using sed

cat genome.fa | sed -r 's/(N[CTW]_[0-9]*)/chr\1/g' > genome.modified.fa

If you are familiar with command line working environment, then the following command might help you:

perl -lpe '/>(\S+)/ and $_=qq{>chr$1}' in.fa > out.fa

If you want to make this easier, try TBtools with it functions "ID Rename".

enter image description here

Log in to answer this question.