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?
$\begingroup$
$\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$– llrsCommented Nov 15, 2017 at 14:47
-
$\begingroup$ Most tools that calculate genome assembly summary stats will report total length. I use assembly-stats $\endgroup$– heathobrienCommented Nov 15, 2017 at 15:06
Add a comment
|
2 Answers
$\begingroup$
$\endgroup$
grep -v ">" multi.fasta | tr -d '\n' | wc -c
grep -v ">"
find all non header lines (i.e. without ">")tr -d '\n'
delete all newlineswc -c
count all characters
$\begingroup$
$\endgroup$
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)