0
$\begingroup$

I have a multifasta file containing several genes from a genomic island. I want to know the total length of this island. How can I do this?

$\endgroup$
2
  • 3
    $\begingroup$ What have you tried? How many sequences do you have? How are the position of each sequence stored in your multifasta or elsewhere? $\endgroup$
    – llrs
    Nov 15, 2017 at 14:47
  • $\begingroup$ Most tools that calculate genome assembly summary stats will report total length. I use assembly-stats $\endgroup$ Nov 15, 2017 at 15:06

2 Answers 2

5
$\begingroup$
grep -v ">" multi.fasta | tr -d '\n' | wc -c
  • grep -v ">" find all non header lines (i.e. without ">")
  • tr -d '\n' delete all newlines
  • wc -c count all characters
$\endgroup$
2
$\begingroup$

Here’s a function that I keep around for calculating the individual lengths of fasta sequences

falens(){
awk '/^>/ {if (seqlen){print seqlen}; print ;seqlen=0;next; } { seqlen += length($0)}END{print seqlen}' $1
}

And one I use for summing a column of numbers

sum(){
awk '{ sum += $1 } END { print sum}'
}

You can combine these by piping the output to do the sum for you:

falens myseqs.fa | grep -v “>” | awk '{ sum += $1 } END { print sum}'

(Can’t test this myself currently as I’m not at my laptop, but it’s based on 2 functions that work normally)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.