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

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

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.

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

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

1 answer

This should do it:

awk '/^>/{if (l!="") print l; print; l=0; next}{l+=length($0)}END{print l}' seq.fasta | paste - -

Log in to answer this question.