Beispiel #1
0
 def test_convert_q_to_p(self):
     q = models.goldman_Q()
     p = models.convert_q_to_p(q, t=0)
     self.assertEqual(p.shape, (61, 61))
     self.assertTrue((p==identity(61)).all())
     p = models.convert_q_to_p(q, t=1)
     self.assertTrue((p.max() <= 1.0))
Beispiel #2
0
 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)
Beispiel #3
0
 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, [])
Beispiel #4
0
def evolve_sequence_with_q(sequence, q, t=1e-2, lmbda=1e-4, ti_td=0.1, indel_codon_freq=None):
    if not 0 <= lmbda <= 1:
        raise ValueError('lmbda must be in range 0-1')
    if not ti_td >= 0:
        raise ValueError('ti_td must be positive')

    new_sequence = deepcopy(sequence)
    p = models.convert_q_to_p(q, t=t)
    p_cumsum, p_codons, p_cumsum_dict = models.get_cumulative_p(p, return_dict=True)
    for locus in new_sequence.loci:
        models.make_subs_in_locus(locus, p_cumsum_dict)
        for i in range(len(locus.codons)):
            if uniform(0, 1) <= lmbda:
                models.make_indel(locus, index=i, ti_td=ti_td, codon_freq=indel_codon_freq)
    return new_sequence
Beispiel #5
0
def evolve_sequence_with_q(sequence,
                           q,
                           t=1e-2,
                           lmbda=1e-4,
                           ti_td=0.1,
                           indel_codon_freq=None):
    if not 0 <= lmbda <= 1:
        raise ValueError('lmbda must be in range 0-1')
    if not ti_td >= 0:
        raise ValueError('ti_td must be positive')

    new_sequence = deepcopy(sequence)
    p = models.convert_q_to_p(q, t=t)
    p_cumsum, p_codons, p_cumsum_dict = models.get_cumulative_p(
        p, return_dict=True)
    for locus in new_sequence.loci:
        models.make_subs_in_locus(locus, p_cumsum_dict)
        for i in range(len(locus.codons)):
            if uniform(0, 1) <= lmbda:
                models.make_indel(locus,
                                  index=i,
                                  ti_td=ti_td,
                                  codon_freq=indel_codon_freq)
    return new_sequence
Beispiel #6
0
 def test_get_mutation_from_cumulative_p(self):
     q = models.goldman_Q(scale_q=False)
     p = models.convert_q_to_p(q, t=10)
     pc, pcod, pcdict = models.get_cumulative_p(p, return_dict=True)
     old_codon = 'aaa'
     new_codon = models.get_mutation_from_cumulative_p(old_codon, pcdict)
Beispiel #7
0
 def test_get_cumulative_p(self):
     q = models.goldman_Q(scale_q=False)
     p = models.convert_q_to_p(q, t=10)
     pc, pcod = models.get_cumulative_p(p)
     for i in pc:
         self.assertTrue(isclose(i[-1], 1))