def Edge(seq1, seq2, length, bin_data, switch=1.0, bprobs=None): # one sequence pair in, potentialy, a tree bins = len(bin_data) pair = pairwise.Pair(seq1, seq2) EP = pair.makeReversibleEmissionProbs([(bin.mprobs, bin.Qd) for bin in bin_data], length) tms = [bin.indel.calcTransitionMatrix(length) for bin in bin_data] if bins == 1: TM = tms[0] else: assert bprobs R = SiteClassTransitionMatrix(switch, bprobs) TM = R.nestTransitionMatricies(tms) assert min(TM.Matrix.flat) >=0, bin_data return EP.makePairHMM(TM)
class PatchSiteDistribution(object): def __init__(self, switch, bprobs): half = len(bprobs) // 2 self.alloc = [0] * half + [1] * (len(bprobs)-half) pprobs = numpy.zeros([max(self.alloc)+1], Float) for (b,p) in zip(self.alloc, bprobs): pprobs[b] += p self.bprobs = [p/pprobs[self.alloc[i]] for (i,p) in enumerate(bprobs)] self.transition_matrix = SiteClassTransitionMatrix(switch, pprobs) def getWeightedSumLhs(self, lhs): result = numpy.zeros((2,)+lhs[0].shape, lhs[0].dtype.char) temp = numpy.empty(lhs[0].shape, result.dtype.char) for (patch, weight, lh) in zip(self.alloc, self.bprobs, lhs): temp[:] = lh temp *= weight result[patch] += temp return result def __call__(self, root): return SiteHmm(self, root) def emit(self, length, random_series): bprobs = [[p for (patch,p) in zip(self.alloc, self.bprobs) if patch==a] for a in [0,1]] source = self.transition_matrix.emit(random_series) result = numpy.zeros([length], int) for i in range(length): patch = source.next() - 1 result[i] = argpick(bprobs[patch], random_series) return result
def __init__(self, switch, bprobs): half = len(bprobs) // 2 self.alloc = [0] * half + [1] * (len(bprobs)-half) pprobs = numpy.zeros([max(self.alloc)+1], Float) for (b,p) in zip(self.alloc, bprobs): pprobs[b] += p self.bprobs = [p/pprobs[self.alloc[i]] for (i,p) in enumerate(bprobs)] self.transition_matrix = SiteClassTransitionMatrix(switch, pprobs)
class PatchSiteDistribution(object): def __init__(self, switch, bprobs): half = len(bprobs) // 2 self.alloc = [0] * half + [1] * (len(bprobs) - half) pprobs = numpy.zeros([max(self.alloc) + 1], Float) for (b, p) in zip(self.alloc, bprobs): pprobs[b] += p self.bprobs = [ p / pprobs[self.alloc[i]] for (i, p) in enumerate(bprobs) ] self.transition_matrix = SiteClassTransitionMatrix(switch, pprobs) def getWeightedSumLhs(self, lhs): result = numpy.zeros((2, ) + lhs[0].shape, lhs[0].dtype.char) temp = numpy.empty(lhs[0].shape, result.dtype.char) for (patch, weight, lh) in zip(self.alloc, self.bprobs, lhs): temp[:] = lh temp *= weight result[patch] += temp return result def __call__(self, root): return SiteHmm(self, root) def emit(self, length, random_series): bprobs = [[ p for (patch, p) in zip(self.alloc, self.bprobs) if patch == a ] for a in [0, 1]] source = self.transition_matrix.emit(random_series) result = numpy.zeros([length], int) for i in range(length): patch = source.next() - 1 result[i] = argpick(bprobs[patch], random_series) return result