def test_substitutions_changes(self): """Test that substitions occur at the expected rate.""" cfg = AppSettings() reps = 1000 deltas = [] for _ in range(0, reps): seq = "a" * 100 dna = Chromosome(seq) dna.substitutions() deltas.append(sum(1 for a, b in zip(seq, dna.sequence) if a != b)) # Expand the conf_99 to compensate for repeated mutations in the same place expected_delta = cfg.genetics.mutation_rate * 100 * \ (1 - 1/len(Chromosome.nucleotides())) # Because there is a little slop around synonymous substitions I multiply # the confidence by 10 just to limit the number of failing tests. conf_99 = ((poisson.var(cfg.genetics.mutation_rate * 100) / 1000) **(1 / 2)) * 10 observed_delta = sum(deltas) / reps assert (expected_delta - conf_99) < observed_delta < (expected_delta + conf_99)
def test_substitutions_length(self): """Ensure the substitions don't change sequence length.""" dna = Chromosome("a" * 100) dna.substitutions() assert len(dna.sequence) == 100