class Test_Model(Model): def __init__(self, args, rng): super(Test_Model, self).__init__(args, rng) def get_summary(self): print "Running test model" def get_output(self): print self.evolver.current_code print "Model done" def run(self): trnas = 8 aarss = 8 phi = 0.9 mu = .01 msg_mu = .1 pop = 100 trna_names = ["tra_" + str(i) for i in xrange(trnas)] codon_names = ["codon_" + str(i) for i in xrange(trnas)] aars_names = ["aars_" + str(i) for i in xrange(aarss)] aa_names = ["aa_" + str(i) for i in xrange(aarss)] site_names = ["site_" + str(i) for i in xrange(aarss)] trna_space = Bit_TRNA_Space(trna_names, codon_names) aars_space = Id_AARS_Space(aars_names, aa_names) trna = range(trnas) trna[1] = 0 trna[2] = 0 code = Code(trna, range(aarss), trna_space, aars_space) site_types = Ring_Site_Types(phi, zip(aa_names, np.arange(0, 1, .125)), zip(site_names, np.arange(0, 1, .125)), [1] * len(site_names)) self.evolver = Evolver( code, site_types, mu, get_ring_mutation_matrix(len(codon_names), msg_mu), pop, self.rng) mut = Code_Mutator(code, mu) trna[0] = 1 code2 = Code(trna, range(aarss), trna_space, aars_space) #print mut.mutation_probability(code2) #print [trna_space.mutation_probability(0, i, mu) for i in xrange(8)] # mut = Code_Mutator(code, mu) # code_dict = mut.get_one_gene_mutation_probabilities() #for code in code_dict: # print code, code_dict[code] for i in xrange(10000): self.evolver.step_time()
class Test_Model(Model): def __init__(self, args, rng): super(Test_Model, self).__init__(args, rng) def get_summary(self): print "Running test model" def get_output(self): print self.evolver.current_code print "Model done" def run(self): trnas = 8 aarss = 8 phi = 0.9 mu = .01 msg_mu = .1 pop = 100 trna_names = ["tra_" + str(i) for i in xrange(trnas)] codon_names = ["codon_" + str(i) for i in xrange(trnas)] aars_names = ["aars_" + str(i) for i in xrange(aarss)] aa_names = ["aa_" + str(i) for i in xrange(aarss)] site_names = ["site_" + str(i) for i in xrange(aarss)] trna_space = Bit_TRNA_Space(trna_names, codon_names) aars_space = Id_AARS_Space(aars_names, aa_names) trna = range(trnas) trna[1] = 0 trna[2] = 0 code = Code(trna, range(aarss), trna_space, aars_space) site_types = Ring_Site_Types(phi, zip(aa_names, np.arange(0, 1, .125)), zip(site_names, np.arange(0, 1, .125)), [1] * len(site_names)) self.evolver = Evolver(code, site_types, mu, get_ring_mutation_matrix(len(codon_names), msg_mu), pop, self.rng) mut = Code_Mutator(code, mu) trna[0] = 1 code2 = Code(trna, range(aarss), trna_space, aars_space) #print mut.mutation_probability(code2) #print [trna_space.mutation_probability(0, i, mu) for i in xrange(8)] # mut = Code_Mutator(code, mu) # code_dict = mut.get_one_gene_mutation_probabilities() #for code in code_dict: # print code, code_dict[code] for i in xrange(10000): self.evolver.step_time()
class Evolver_Test(unittest.TestCase): def setUp(self): self.aars_space = AARS_Space(range(2), np.diag([1] * 2), get_uniform_mutation_matrix(2, .01)) # mu is zero so that there is only 3 potential codes available # and so the code is forced to handle mutants with a fixation # probability of zero. self.trna_space = TRNA_Space(range(2), np.diag([1] * 2), np.diag([1] * 2), get_uniform_mutation_matrix(2, .01)) pchem_vals = [.30, .70] self.site_types = Ring_Site_Types(.05, zip(range(2), pchem_vals), zip(range(2), pchem_vals), [1] * 2) message_mutation_matrix = get_uniform_mutation_matrix(2, .01) #print message_mutation_matrix.shape #print np.matrix([[.5, .5], [.5, .5]]).shape self.code = Code([1], [1], self.trna_space, self.aars_space) rng = Random() rng.seed(42) self.evolver = Evolver(self.code, self.site_types, message_mutation_matrix, 100, rng) def test_overall_fitness(self): """ Check if Eq5 SellaArdell 06 is implemented correctly. """ self.assertAlmostEqual(.5 ** 2, self.evolver._overall_fitness([.5, .5])) def test_transition_probabilities(self): self.assertTrue(False, "Still need to implement this test.") def test_step_time(self): self.evolver.step_time() self.assertEqual(self.evolver._current_code, self.code)