Skip to main content
. 2022 Dec 13;29(12):1346–1352. doi: 10.1089/cmb.2022.0254
Algorithm 1: calc_probs computes the complete set of paths that can be reached within n mutational steps from codon. The parameter path_prob is the probability of reaching the current codon via a particular path. After calc_probs is executed, the codons reached by all paths and their associated probabilities are in the paths variable. The codons in this variable are then grouped and summed by the amino acid they encode (omitted below). The initial invocation of calc_probs initializes path_prob to 1. The step_codon function produces all 9 variants of a codon with a single mutated base.
paths []
def cal_probs (codon, path_prob, G, n):
if n = 0:
  return
for next_codon in step_codon(codon):
   mutational_prob G [codon, next_codon]
   next_prob path_prob * mutational_prob
   push(paths, (next_codon, next_prob))
   calc_probs(next_codon, next_prob, G, n − 1)