# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# 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)
# 
# CODON_TO_INDEX = {}


import os
import re
import math
import unittest
import random
import copy
import numpy
import scipy.optimize
import Bio.Phylo
import phydmslib.models
import phydmslib.treelikelihood
import phydmslib.simulate
import pyvolve
from phydmslib.constants import (N_CODON, N_NT, AA_TO_INDEX,
                                 N_AA, CODON_TO_INDEX)
        info = "_temp_info.txt"
        rates = "_temp_ratefile.txt"
        evolver = pyvolve.Evolver(partitions=partitions, tree=pyvolvetree)
        evolver(seqfile=alignment, infofile=info, ratefile=rates)
        self.alignment = [(s.description, str(s.seq))
                          for s in Bio.SeqIO.parse(alignment, "fasta")]
        for f in [alignment, info, rates]:
            os.remove(f)
        assert len(self.alignment[0][1]) == self.nsites * 3
        assert len(self.alignment) == self.nseqs
        self.codons = {}  # indexed by node, site, gives codon index
        for node in self.tree.get_terminals():
            node = node.name
            i = int(node[-1])
            self.codons[i] = {}
            seq = [seq for (head, seq) in self.alignment if node == head][0]
            for r in range(self.nsites):
                codon = seq[3 * r: 3 * r + 3]
                self.codons[i][r] = CODON_TO_INDEX[codon]

        # define model
        prefs = []
        minpref = 0.02
        g = numpy.random.dirichlet([5] * N_NT)
        g[g < 0.1] = 0.1
        g /= g.sum()
        for _r in range(self.nsites):
            rprefs = numpy.random.dirichlet([0.5] * N_AA)
            rprefs[rprefs < minpref] = minpref
            rprefs /= rprefs.sum()

# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# 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)
# 
# CODON_TO_INDEX = {}


# Path: tests/test_treelikelihood.py
import os
import re
import math
import unittest
import random
import copy
import numpy
import scipy.optimize
import Bio.Phylo
import phydmslib.models
import phydmslib.treelikelihood
import phydmslib.simulate
import pyvolve
from phydmslib.constants import (N_CODON, N_NT, AA_TO_INDEX,
                                 N_AA, CODON_TO_INDEX)

        info = "_temp_info.txt"
        rates = "_temp_ratefile.txt"
        evolver = pyvolve.Evolver(partitions=partitions, tree=pyvolvetree)
        evolver(seqfile=alignment, infofile=info, ratefile=rates)
        self.alignment = [(s.description, str(s.seq))
                          for s in Bio.SeqIO.parse(alignment, "fasta")]
        for f in [alignment, info, rates]:
            os.remove(f)
        assert len(self.alignment[0][1]) == self.nsites * 3
        assert len(self.alignment) == self.nseqs
        self.codons = {}  # indexed by node, site, gives codon index
        for node in self.tree.get_terminals():
            node = node.name
            i = int(node[-1])
            self.codons[i] = {}
            seq = [seq for (head, seq) in self.alignment if node == head][0]
            for r in range(self.nsites):
                codon = seq[3 * r: 3 * r + 3]
                self.codons[i][r] = CODON_TO_INDEX[codon]

        # define model
        prefs = []
        minpref = 0.02
        g = numpy.random.dirichlet([5] * N_NT)
        g[g < 0.1] = 0.1
        g /= g.sum()
        for _r in range(self.nsites):
            rprefs = numpy.random.dirichlet([0.5] * N_AA)
            rprefs[rprefs < minpref] = minpref
            rprefs /= rprefs.sum()

            prefs.append(dict(zip(sorted(AA_TO_INDEX.keys()), rprefs)))