Based on your work, you can process fasta file in anyway. But through this post, I am going to present a simple example to find the average sequence length from a fasta file . Reading a fasta file is already discussed.

In order to find mean value, we don’t need header information. Therefore a simple python list is enough to store base pair / amino acid count of each sequence. Total number of items in the list represent total number sequence present in the file.
If we declare a list ‘fasta’ to store base pair / amino acid count from each sequence, then length of ‘fasta’ return the number of sequence present in the file.
fasta = [23,36,54] # sample list after loading file
totalSequence = len(fasta)
print(totalBase) # output : 3
Since ‘fasta’ list store base pair / amino acid count from each sequence, passing ‘fasta’ into python3 sum() function return total base pair / amino acids present in the file.
fasta = [23,36,54]
totalBase = sum(fasta)
print(totalBase) # output : 113
Now its easy to take the mean value.
mean = totalBase / totalSequence
print(mean) # output : 37.666666667
This program will be useful for those who use blast2go like software to calculate mean value from fasta file while purchasing cloud units.
Here is the link to my GitHub Hosted file
Why we need to find the average sequence length from a fasta file? Could you please specify?
LikeLike
Statistics of fasta file including average will be useful while you work with machine learning programs. Also this is just an example. Based on your work you can find various other statistical analysis like assembly size, N50, L50, number of contigs, GC% etc…
By examine the mean sequence length, you can even calculate the time required to process your file.
This Blog post aim to explain the work behind of processing a fasta file in simple way.
LikeLike