def mutate(parent_seq, model, time): nucs = ('A','C','G','T') new_seq = [] for parent_nuc in parent_seq: probs = [] for child_nuc in nucs: probs.append(model.matrix[parent_nuc][child_nuc](time)) # print probs new_nuc = four_category_dist(1, probs, nucs)[0] new_seq.append(new_nuc) return new_seq
def select_sequence(self, target, topo, t): nucs = ("A", "T", "C", "G") freqs = {"A": 0.0, "T": 0.0, "C": 0.0, "G": 0.0} new_seq = [] parent = target.parent for seq in self.target.sequence: for nuc in nucs: p = self.model.matrix[seq][nuc](parent.time - t) c1 = self.model.matrix[nuc][seq](t - topo[1].time) c2 = self.model.matrix[nuc][seq](t - topo[2].time) freqs[nuc] += (p * c1 * c2) / 4 new_nuc = four_category_dist(1, freqs.values(), nucs)[0] new_seq.append(new_nuc) return new_seq