This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to change the chromosome names of the head line of fasta file?

I want to add "chr" to the chromosome names of the head line of fasta file:

>1 dna:chromosome chromosome:GRCm38:1:1:195471971:1 REF

to

>chr1 dna:chromosome chromosome:GRCm38:chr1:1:195471971:1 REF

I tried

cat Mus_musculus.GRCm38.dna.primary_assembly.fa | sed -e 's/^>\([0-9XY]\)/>chr\1/' -e 's/.*GRCm38:\([0-9XY]\):.*/chr\1/'

which can only change the first position, how should I change the second position?

Thanks

sed

1 answer

Since the patterns to replace are so unique you can literally just do the sledgehammer method:

awk '{gsub("^>",">chr");gsub(":GRCm38:",":GRCm38:chr");print}' your.fa

Log in to answer this question.