This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to modify fasta file headers

Hi All!

I need to change modifty my fasta file headers in the follow way

Example

Input:

> Proteobacteria;_1 # 52 # 312 # 1 # ID=1_1;partial=01;start
> Firmicutes;_1 # 52 # 312 # 1 # ID=1_1;partial=01;start
> Planctomycetes;_1 # 52 # 312 # 1 # ID=1_1;partial=01;start

Output:

>Seq1
>Seq2
>Seq3

Thanks a lot!

fasta

Try one of these two:

$ awk '/^>/ {print ">Seq_"++n} !/^>/' input.fa
$ awk '/^>/ {sub(".*", ">Seq_"++n)}1' input.fa

2 answers

A seqkit answer.

Example 6 for seqkit replace is almost identical to your question with slight modification.

seqkit replace -p .+ -r "Seq{nr}"

Hi! One question, where should I put the input file? (sorry, I am new to this)

Thanks!

You put it at the end.

seqkit replace -p .+ -r "Seq{nr}" old_file.fasta > new_file.fasta
awk '/^>/ {printf(">Seq%d\n",++N);next;} {print}' in.fa

Log in to answer this question.