def propmat(alignment, num_imp, num_changes, transitions, probs): num_changes = int(num_changes) orlen = len(alignment)-num_imp record = 0 newpd = copy(alignment.pd) newdistarray = copy(alignment.distarray) origlist = [i for i in alignment[:orlen]] implist = [i for i in alignment[orlen:]] # targets = [(random.randint(0,len(implist)-1), random.randint(0,len(alignment[0])-1)) for i in xrange(num_changes)] targets = [(random.randint(0,len(implist)-1), wl_one(probs)) for i in xrange(num_changes)] for t in targets: old = newdistarray[orlen+t[0],t[1]] new = weightselect(transitions[old]) # new = random.choice(AAS) newdistarray[orlen+t[0],t[1]] = new changes = (newdistarray[:,t[1]]==old).astype(int)-(newdistarray[:,t[1]]==new).astype(int) # pdb.set_trace() newpd[orlen+t[0]]+=changes newpd[:,orlen+t[0]]+=changes record += 1 # newpd = np.tril(newpd,-1) # newpd += newpd.transpose() np.fill_diagonal(newpd,0) inds = Counter([t[0] for t in targets]).keys() for ind in inds: seq = implist[ind] implist[ind] = SeqRecord(Seq(''.join(newdistarray[ind+orlen])), id=seq.id, name=seq.name, description=seq.description, annotations=seq.annotations) newalign = MultipleSeqAlignment(origlist+implist) newalign.pd, newalign.distarray = newpd, newdistarray return record, newalign, targets