Question: Fasta length count format
0
gravatar for baurumon
4 weeks ago by
baurumon10
Norway
baurumon10 wrote:

Hi, i have used awk '/^>/{if (l!="") print l; print; l=0; next}{l+=length($0)}END{print l}' seq.fasta to count sequence length. How can i get the output in below format.

Thanks in advance

head length

NC_035897.1:11929374-11930116 742

NC_035897.1:11929384-11930116 732

enter image description here

sequence • 184 views
ADD COMMENTlink modified 4 weeks ago by kloetzl1.0k • written 4 weeks ago by baurumon10
1

Use tr command to change the new line characters to a tab. It is unclear if you want to go in the other direction but if that is the case then switch tab and new lines.

ADD REPLYlink modified 4 weeks ago • written 4 weeks ago by genomax71k

hi genomax, I want head and length column. tr command is printing one after another. sorry for mistake.

ADD REPLYlink written 4 weeks ago by baurumon10
1

See RamRS's solution on: Sequence length from Fasta

ADD REPLYlink written 4 weeks ago by Sej Modha4.4k

i asked my colleague to install seqkit but it going to take time. is there any way to do it with sed or awk?

ADD REPLYlink written 4 weeks ago by baurumon10
1

It is advisable to search for this sort of problems on Google first before it is posted on this platform, please take a look at Brief Reminder On How To Ask A Good Question.

A simple Google search provided this and it could be the solution you're after - https://www.danielecook.com/generate-fasta-sequence-lengths/

ADD REPLYlink modified 4 weeks ago • written 4 weeks ago by Sej Modha4.4k
2
gravatar for kloetzl
4 weeks ago by
kloetzl1.0k
European Union
kloetzl1.0k wrote:

This should do it:

awk '/^>/{if (l!="") print l; print; l=0; next}{l+=length($0)}END{print l}' seq.fasta | paste - -
ADD COMMENTlink written 4 weeks ago by kloetzl1.0k
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: 689 users visited in the last hour