This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Modify Fasta header

Hello

I have a fasta file with amino acids sequences, which was translated from nucleotide sequence by transeq.

>CE99543_15407_1
MAV.....
>CE99641_51257_1
MSQ......

I want to delete _1 at the end of fasta header because it was somehow added by transeq.

>CE99543_15407
MAV.....
>CE99641_51257
MSQ......

Just deleting _1 would not work because there are headers including _1 in the middle.

Could you please tell me how to do it?

Thank you very much for your help.

fasta

2 answers

sed  's/_1$//'

Thank you very much! It helped me to solve the issue.

You need to add end-of-line character \n to the replace command to make sure that _1 found anywhere else is not replaced.

perl -pi -e 's/_1\n/\n/g' input_file

Will it need an option to specify that this is a multi-line regex? Would replacing _1$ with nothing not be better for a single line regex?

Thank you very much! I have solved my issue.

Log in to answer this question.