# 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)
                        ("dPrxy_domega", self.expcm.dPrxy["omega"][r][x][y],
                         sympy.diff(Prxy, omega)),
                        ("dPrxy_dbeta", self.expcm.dPrxy["beta"][r][x][y],
                         sympy.diff(Prxy, beta)),
                        ("dPrxy_deta0", self.expcm.dPrxy["eta"][0][r][x][y],
                         sympy.diff(Prxy, eta0)),
                        ("dPrxy_deta1", self.expcm.dPrxy["eta"][1][r][x][y],
                         sympy.diff(Prxy, eta1)),
                        ("dPrxy_deta2", self.expcm.dPrxy["eta"][2][r][x][y],
                         sympy.diff(Prxy, eta2))]:
                        if Prxy == 0:
                            expectval = 0
                        else:
                            expectval = float(expect.subs(values))
                        self.assertTrue(
                            numpy.allclose(actual, expectval, atol=1e-4),
                            "{0}: {1} vs {2}".format(name, actual, expectval))

        # check prx
        qxs = [sympy.Symbol("qx{0}".format(x)) for x in range(N_CODON)]
        frxs = [sympy.Symbol("frx{0}".format(x)) for x in range(N_CODON)]
        prx = sympy.Symbol("prx")
        phixs = [sympy.Symbol("phix{0}".format(w)) for w in range(3)]
        for r in range(self.nsites):
            for x in range(N_CODON):
                pirAx = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[x]]]
                frxs[x] = pirAx ** beta
                xcodon = INDEX_TO_CODON[x]
                assert len(phixs) == len(xcodon)
                for (w, xwnt) in enumerate(xcodon):

# 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)

                        ("dPrxy_domega", self.expcm.dPrxy["omega"][r][x][y],
                         sympy.diff(Prxy, omega)),
                        ("dPrxy_dbeta", self.expcm.dPrxy["beta"][r][x][y],
                         sympy.diff(Prxy, beta)),
                        ("dPrxy_deta0", self.expcm.dPrxy["eta"][0][r][x][y],
                         sympy.diff(Prxy, eta0)),
                        ("dPrxy_deta1", self.expcm.dPrxy["eta"][1][r][x][y],
                         sympy.diff(Prxy, eta1)),
                        ("dPrxy_deta2", self.expcm.dPrxy["eta"][2][r][x][y],
                         sympy.diff(Prxy, eta2))]:
                        if Prxy == 0:
                            expectval = 0
                        else:
                            expectval = float(expect.subs(values))
                        self.assertTrue(
                            numpy.allclose(actual, expectval, atol=1e-4),
                            "{0}: {1} vs {2}".format(name, actual, expectval))

        # check prx
        qxs = [sympy.Symbol("qx{0}".format(x)) for x in range(N_CODON)]
        frxs = [sympy.Symbol("frx{0}".format(x)) for x in range(N_CODON)]
        prx = sympy.Symbol("prx")
        phixs = [sympy.Symbol("phix{0}".format(w)) for w in range(3)]
        for r in range(self.nsites):
            for x in range(N_CODON):
                pirAx = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[x]]]
                frxs[x] = pirAx ** beta
                xcodon = INDEX_TO_CODON[x]
                assert len(phixs) == len(xcodon)
                for (w, xwnt) in enumerate(xcodon):

                    xw = NT_TO_INDEX[xwnt]