How to modify fasta file headers
2
0
Entering edit mode
2.4 years ago
Paula ▴ 60

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 • 966 views
ADD COMMENT
0
Entering edit mode

Try one of these two:

$ awk '/^>/ {print ">Seq_"++n} !/^>/' input.fa
$ awk '/^>/ {sub(".*", ">Seq_"++n)}1' input.fa
ADD REPLY
2
Entering edit mode
2.4 years ago

A seqkit answer.

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

seqkit replace -p .+ -r "Seq{nr}"
ADD COMMENT
0
Entering edit mode

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

Thanks!

ADD REPLY
1
Entering edit mode

You put it at the end.

seqkit replace -p .+ -r "Seq{nr}" old_file.fasta > new_file.fasta
ADD REPLY
1
Entering edit mode

Thanks broski!

ADD REPLY
2
Entering edit mode
2.4 years ago
awk '/^>/ {printf(">Seq%d\n",++N);next;} {print}' in.fa
ADD COMMENT

Login before adding your answer.

Traffic: 1964 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6