Tutorial: Add count numbers to headers in a fasta file
1
gravatar for wu.zhiqiang.1020
2.4 years ago by
United States
wu.zhiqiang.102020 wrote:
>a
ACTCTAAAT

>b
AAAAACCCT

etc.

To

>a_1
ACTCTAAAT

>b_2
AAAAACCCT

 

awk '/^>/{$0=$0"_"(++i)}1'  in > out
blog tutorial genome • 1.1k views
ADD COMMENTlink modified 2.4 years ago by Alex Reynolds28k • written 2.4 years ago by wu.zhiqiang.102020

Could you expand a bit on your post? What's the purpose of doing this?

ADD REPLYlink written 2.4 years ago by WouterDeCoster38k

Soory, I just want to record this. thanks for you concern, I will explain more for next time.

ZQ

ADD REPLYlink written 2.4 years ago by wu.zhiqiang.102020
1
gravatar for Alex Reynolds
2.4 years ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

Another way to do it, which works with single-line FASTA input:

$ awk 'BEGIN{RS=">"}{if(NR>1)print ">"$1"_"(NR-1)"\n"$2}' input.fa > output.fa

A second way, which allows multiline FASTA input:

$ awk 'BEGIN{RS=">";OFS="\n"}(NR>1){print ">"$1"_"(NR-1)"\n";$1="";print $0}' input.fa | awk '$0' > output.fa
ADD COMMENTlink modified 2.4 years ago • written 2.4 years ago by Alex Reynolds28k
0
gravatar for venu
2.4 years ago by
venu6.1k
Germany
venu6.1k wrote:

You can do something like following

cat file.fa | paste - - | awk '{print $1"_"NR"\n"$2}' > new_file.fa
ADD COMMENTlink written 2.4 years ago by venu6.1k

I don't think it's a question, but that he is sharing a way of doing just this.

ADD REPLYlink written 2.4 years ago by WouterDeCoster38k
2

Oops! I think I was too hurry as I am busy with our Biostars Handbook.

ADD REPLYlink written 2.4 years ago by venu6.1k

Best excuse I can imagine, keep up the good work.

ADD REPLYlink written 2.4 years ago by WouterDeCoster38k

If you put this in the Handbook, make sure to use the OPs awk as it works with all FASTA files and not just ones where the sequence is less than 120 characters! :) (or don't put awk in at all, because awk is the devil! :P)

ADD REPLYlink modified 2.4 years ago • written 2.4 years ago by John12k

thanks for the new way to do this. ZQ

ADD REPLYlink written 2.4 years ago by wu.zhiqiang.102020
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1444 users visited in the last hour