# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}
# 
# CODON_TO_AA = []
# 
# INDEX_TO_CODON = {}
# 
# INDEX_TO_AA = dict(enumerate('ACDEFGHIKLMNPQRSTVWY'))
# 
# CODON_SINGLEMUT = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_TRANSITION = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_NONSYN = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# N_NT = len(INDEX_TO_NT)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)


import random
import unittest
import numpy
import scipy.linalg
import scipy.optimize
import sympy
import phydmslib.models
from phydmslib.constants import (N_CODON, NT_TO_INDEX, CODON_TO_AA,
                                 INDEX_TO_CODON, INDEX_TO_AA, CODON_SINGLEMUT,
                                 CODON_TRANSITION, CODON_NONSYN, N_NT,
                                 AA_TO_INDEX, N_AA)
                pirAx = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[x]]]
                for y in [yy for yy in range(N_CODON) if yy != x]:
                    pirAy = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[y]]]
                    if not CODON_SINGLEMUT[x][y]:
                        Prxy = 0
                    else:
                        w = NT_TO_INDEX[
                            [ynt for (xnt, ynt) in zip(INDEX_TO_CODON[x],
                                                       INDEX_TO_CODON[y])
                             if xnt != ynt][0]]
                        if w == 0:
                            phiw = 1 - eta0
                        elif w == 1:
                            phiw = eta0 * (1 - eta1)
                        elif w == 2:
                            phiw = eta0 * eta1 * (1 - eta2)
                        elif w == 3:
                            phiw = eta0 * eta1 * eta2
                        else:
                            raise ValueError("Invalid w")
                        self.assertTrue(
                            numpy.allclose(float(phiw.subs(values)),
                                           self.expcm.phi[w]))
                        if CODON_TRANSITION[x][y]:
                            Qxy = kappa * phiw
                        else:
                            Qxy = phiw
                        self.assertTrue(
                            numpy.allclose(
                                float(Qxy.subs(values)), self.expcm.Qxy[x][y]))

# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}
# 
# CODON_TO_AA = []
# 
# INDEX_TO_CODON = {}
# 
# INDEX_TO_AA = dict(enumerate('ACDEFGHIKLMNPQRSTVWY'))
# 
# CODON_SINGLEMUT = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_TRANSITION = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_NONSYN = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# N_NT = len(INDEX_TO_NT)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)


# Path: tests/test_expcm.py
import random
import unittest
import numpy
import scipy.linalg
import scipy.optimize
import sympy
import phydmslib.models
from phydmslib.constants import (N_CODON, NT_TO_INDEX, CODON_TO_AA,
                                 INDEX_TO_CODON, INDEX_TO_AA, CODON_SINGLEMUT,
                                 CODON_TRANSITION, CODON_NONSYN, N_NT,
                                 AA_TO_INDEX, N_AA)

                pirAx = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[x]]]
                for y in [yy for yy in range(N_CODON) if yy != x]:
                    pirAy = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[y]]]
                    if not CODON_SINGLEMUT[x][y]:
                        Prxy = 0
                    else:
                        w = NT_TO_INDEX[
                            [ynt for (xnt, ynt) in zip(INDEX_TO_CODON[x],
                                                       INDEX_TO_CODON[y])
                             if xnt != ynt][0]]
                        if w == 0:
                            phiw = 1 - eta0
                        elif w == 1:
                            phiw = eta0 * (1 - eta1)
                        elif w == 2:
                            phiw = eta0 * eta1 * (1 - eta2)
                        elif w == 3:
                            phiw = eta0 * eta1 * eta2
                        else:
                            raise ValueError("Invalid w")
                        self.assertTrue(
                            numpy.allclose(float(phiw.subs(values)),
                                           self.expcm.phi[w]))
                        if CODON_TRANSITION[x][y]:
                            Qxy = kappa * phiw
                        else:
                            Qxy = phiw
                        self.assertTrue(
                            numpy.allclose(
                                float(Qxy.subs(values)), self.expcm.Qxy[x][y]))

                        if CODON_NONSYN[x][y]: