#NEWLINE# def countSubstitutions( pi , Q ) : #NEWLINE# #INDENT# 'count substitituions given a matrix Q and frequencies pi.' #NEWLINE# ( rI , rV , rS , rN ) = ( 0 , 0 , 0 , 0 ) #NEWLINE# codon_table = Bio . Data . CodonTable . standard_dna_table #NEWLINE# codons = codon_table . forward_table . keys ( ) #NEWLINE# for codon_i in codons : #NEWLINE# #INDENT# for codon_j in codons : #NEWLINE# #INDENT# if ( codon_i == codon_j ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ( is_single , is_synonymous , is_transition ) = evaluateCodonPair ( codon_i , codon_j ) #NEWLINE# v = ( Q [ codon_i ] [ codon_j ] * pi [ codon_i ] ) #NEWLINE# if is_transition : #NEWLINE# #INDENT# rI += v #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rV += v #NEWLINE# #UNINDENT# if is_synonymous : #NEWLINE# #INDENT# rS += v #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rN += v #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( rI , rV , is_transition , rN )