def _get_Q(pi, k, w, codon_lst, codon_table):
 import numpy as np
 codon_num = len(codon_lst)
 Q = np.zeros((codon_num, codon_num))
 for i in range(codon_num):
  for j in range(codon_num):
   if (i != j):
    Q[(i, j)] = _q(codon_lst[i], codon_lst[j], pi, k, w, codon_table=codon_table)
 nucl_substitutions = 0
 for i in range(codon_num):
  Q[(i, i)] = (- sum(Q[i, :]))
  try:
   nucl_substitutions += (pi[codon_lst[i]] * (- Q[(i, i)]))
  except KeyError:
   pass
 Q = (Q / nucl_substitutions)
 return Q

def _get_Q ( pi , k , w , codon_lst , codon_table ) : import numpy as np codon_num = len ( codon_lst ) Q = np . zeros ( ( codon_num , codon_num ) ) for i in range ( codon_num ) : for j in range ( codon_num ) : if ( i != j ) : Q [ ( i , j ) ] = _q ( codon_lst [ i ] , codon_lst [ j ] , pi , k , w , codon_table = codon_table ) nucl_substitutions = 0 for i in range ( codon_num ) : Q [ ( i , i ) ] = ( - sum ( Q [ i , : ] ) ) try : nucl_substitutions += ( pi [ codon_lst [ i ] ] * ( - Q [ ( i , i ) ] ) ) except KeyError : pass Q = ( Q / nucl_substitutions ) return Q
q matrix for codon substitution .