# Path: phydmslib/constants.py
# CODON_TO_INDEX = {}
# 
# CODON_TO_AA = []
# 
# N_NT = len(INDEX_TO_NT)
# 
# N_AA = len(INDEX_TO_AA)
# 
# INDEX_TO_CODON = {}
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_CODON = len(CODON_TO_INDEX)


import random
import unittest
import copy
import os
import phydmslib.models
import phydmslib.file_io
import phydmslib.simulate
import phydmslib.treelikelihood
import pyvolve
import numpy
import Bio
from phydmslib.constants import (CODON_TO_INDEX, CODON_TO_AA, N_NT, N_AA,
                                 INDEX_TO_CODON, AA_TO_INDEX, N_CODON)
        for seed in range(3):
            numpy.random.seed(seed)
            if self.MODEL == phydmslib.models.ExpCM_fitprefs:
                tl.paramsarray = numpy.random.uniform(0.1, 0.99,
                                                      len(tl.paramsarray))
            elif self.MODEL == phydmslib.models.ExpCM_fitprefs2:
                tl.paramsarray = numpy.random.uniform(0.5, 5.0,
                                                      len(tl.paramsarray))
            else:
                raise ValueError("Unrecognized MODEL: {0}".format(self.MODEL))
            if firstloglik:
                self.assertFalse(
                    numpy.allclose(firstloglik, tl.loglik, atol=0.02),
                    "loglik matches even with random pi")
            tl.maximizeLikelihood()
            if firstloglik:
                self.assertTrue(
                    numpy.allclose(firstloglik, tl.loglik, atol=0.4),
                    "loglik not the same for different starts:"
                    " {0} versus {1}".format(firstloglik, tl.loglik))
            else:
                firstloglik = tl.loglik
            self.assertTrue(numpy.allclose(tl.model.origpi, self.model.pi))
            # ensure highest prefs are for amino acids with nonzero counts
            for r in range(tl.nsites):
                for (c, nc) in self.codoncounts[r].items():
                    if nc > 0:
                        for (c2, _nc2) in self.codoncounts[r].items():
                            ndiffs = len([i for (i, ci) in
                                          enumerate(c) if ci != c2[i]])

# Path: phydmslib/constants.py
# CODON_TO_INDEX = {}
# 
# CODON_TO_AA = []
# 
# N_NT = len(INDEX_TO_NT)
# 
# N_AA = len(INDEX_TO_AA)
# 
# INDEX_TO_CODON = {}
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_CODON = len(CODON_TO_INDEX)


# Path: tests/test_treelikelihood_fitprefs.py
import random
import unittest
import copy
import os
import phydmslib.models
import phydmslib.file_io
import phydmslib.simulate
import phydmslib.treelikelihood
import pyvolve
import numpy
import Bio
from phydmslib.constants import (CODON_TO_INDEX, CODON_TO_AA, N_NT, N_AA,
                                 INDEX_TO_CODON, AA_TO_INDEX, N_CODON)

        for seed in range(3):
            numpy.random.seed(seed)
            if self.MODEL == phydmslib.models.ExpCM_fitprefs:
                tl.paramsarray = numpy.random.uniform(0.1, 0.99,
                                                      len(tl.paramsarray))
            elif self.MODEL == phydmslib.models.ExpCM_fitprefs2:
                tl.paramsarray = numpy.random.uniform(0.5, 5.0,
                                                      len(tl.paramsarray))
            else:
                raise ValueError("Unrecognized MODEL: {0}".format(self.MODEL))
            if firstloglik:
                self.assertFalse(
                    numpy.allclose(firstloglik, tl.loglik, atol=0.02),
                    "loglik matches even with random pi")
            tl.maximizeLikelihood()
            if firstloglik:
                self.assertTrue(
                    numpy.allclose(firstloglik, tl.loglik, atol=0.4),
                    "loglik not the same for different starts:"
                    " {0} versus {1}".format(firstloglik, tl.loglik))
            else:
                firstloglik = tl.loglik
            self.assertTrue(numpy.allclose(tl.model.origpi, self.model.pi))
            # ensure highest prefs are for amino acids with nonzero counts
            for r in range(tl.nsites):
                for (c, nc) in self.codoncounts[r].items():
                    if nc > 0:
                        for (c2, _nc2) in self.codoncounts[r].items():
                            ndiffs = len([i for (i, ci) in
                                          enumerate(c) if ci != c2[i]])

                            a = CODON_TO_AA[CODON_TO_INDEX[c]]