This is a test version of Biostars. For the public version, visit https://www.biostars.org.
sequence renaming

I have a fasta file how to rename the sequence according to the name of the file, for example, the sequence name in the gene.fasta file is >1, >2, renamed >gene1, gene2. Thank you very much for telling me

renaming
$ sed -r  '/^>/ s/^./>gene_/' test.fa

2 answers

Using Linux (any flavour), Unix (OSX)

perl -pi -e 's/^(>[0-9])+.*/\1gene/g' myfile.fa

myfile.fa

>1
AGTC
>2
AGTC
>3
AGTC

output

>1gene
AGTC
>2gene
AGTC
>3gene
AGTC

Its called perl pie (one liner) and is extremely quick at handling massive files. Happy to explain the reg-ex if needed. It will change the file in situ so there's not needed to pipe it, or make a copy, the -i takes care of that.

This can be done with seqtk:

seqtk rename gene.fasta gene > renamed.fasta

Also, a simple replace command with perl:

perl -p -e 's/\>/\>gene/g' gene.fasta > renamed.fasta

Log in to answer this question.