def test_locus_add_codon(self): c = models.Codon() l = models.Locus() for codon in [c, 'atg']: l.add_codon(codon) self.assertEqual(len(l.codons), 2) self.assertEqual(l.codons[0].seq, '---') self.assertEqual(l.codons[1].seq, 'atg')
def test_locus_init(self): l = models.Locus() self.assertEqual(l.loc, 0) self.assertEqual(l.loc_aa, 1) self.assertEqual(l.__str__(), '<Locus >') l = models.Locus(codons=[models.Codon(), 'atg']) self.assertEqual(len(l.codons), 2) self.assertEqual(l.codons[0].seq, '---') self.assertEqual(l.codons[1].seq, 'atg')
def test_make_sub_from_p(self): q = models.goldman_Q(scale_q=False) p = models.convert_q_to_p(q, t=10) p_cumsum, p_codons, p_cumsum_dict = models.get_cumulative_p(p, return_dict=True) old_codon_seq = 'aaa' old_codon = models.Codon(seq=old_codon_seq) models.make_sub_from_p(old_codon, p_cumsum_dict) self.assertEqual(len(old_codon.seq), 3) allowed_letters = 'atgc' for i in old_codon.seq: self.assertIn(i, allowed_letters)
def test_make_subs_in_locus(self): q = models.goldman_Q(scale_q=False) p = models.convert_q_to_p(q, t=10) p_cumsum, p_codons, p_cumsum_dict = models.get_cumulative_p(p, return_dict=True) old_codon_seq = 'aaa' old_codons = [models.Codon(seq=old_codon_seq)]*2 locus = models.Locus(codons=old_codons) old_seq = locus.sequence while locus.sequence == old_seq: models.make_subs_in_locus(locus, p_cumsum_dict) self.assertNotEqual(locus.history, [])
def test_locus_cannot_add_spurious_codons(self): c = models.Codon() with self.assertRaises(ValueError): l = models.Locus(codons=[c, 'abc'])
def test_codon_delete(self): c = models.Codon(seq='atg') self.assertEqual(c.seq, 'atg') c.delete() self.assertEqual(c.seq, '---')
def test_codon_seq_validation(self): c = models.Codon() c.seq = 'a' self.assertEqual(c.seq, 'a--')
def test_codon_init(self): c = models.Codon() self.assertEqual(c.__str__(), '<Codon --->')
def test_make_indel_force_insertion(self): c = models.Codon(seq='atg') l = models.Locus(codons=[c]) models.make_indel(l, index=0, ti_td=1e12, codon_freq=None) self.assertEqual(len(l.codons), 2) self.assertFalse(any(i.seq == '---' for i in l.codons))
def test_make_indel_force_deletion(self): c = models.Codon(seq='atg') l = models.Locus(codons=[c]) models.make_indel(l, index=0, ti_td=0.0, codon_freq=None) self.assertIn('---', [i.seq for i in l.codons])