def _align_pairwise(s1, s2, mprobs, psub, TM, local, return_alignment=True, return_score=False, **kw): """Generic alignment with any substitution model and indel model""" [p1, p2] = [makeLikelihoodTreeLeaf(seq) for seq in [s1, s2]] [p1, p2] = [pairwise.AlignableSeq(leaf) for leaf in [p1, p2]] pair = pairwise.Pair(p1, p2) EP = pair.makeSimpleEmissionProbs(mprobs, [psub]) hmm = EP.makePairHMM(TM) vpath = hmm.getViterbiPath(local=local, **kw) score = vpath.getScore() if return_alignment: alignment = vpath.getAlignment() if return_score: return (alignment, score) else: return alignment else: return score
def countMotifs(self, alignment, include_ambiguity=False, recode_gaps=True): result = None for seq_name in alignment.getSeqNames(): sequence = alignment.getGappedSeq(seq_name, recode_gaps) leaf = makeLikelihoodTreeLeaf(sequence, self.getCountedAlphabet(), seq_name) count = leaf.getMotifCounts(include_ambiguity=include_ambiguity) if result is None: result = count.copy() else: result += count return result
def _align_pairwise(s1, s2, mprobs, psub, TM, local, return_score=False, **kw): """Generic alignment with any substitution model and indel model""" [p1, p2] = [makeLikelihoodTreeLeaf(seq) for seq in [s1, s2]] [p1, p2] = [pairwise.AlignableSeq(leaf) for leaf in [p1, p2]] pair = pairwise.Pair(p1, p2) EP = pair.makeSimpleEmissionProbs(mprobs, [psub]) hmm = EP.makePairHMM(TM) if local: (score, alignment) = hmm.getLocalViterbiScoreAndAlignment(**kw) else: (score, alignment) = hmm.getViterbiScoreAndAlignment(**kw) if return_score: return alignment, score else: return alignment
def convertSequence(self, sequence, name): # makeLikelihoodTreeLeaf, sort of an indexed profile where duplicate # columns stored once, so likelihoods only calc'd once return makeLikelihoodTreeLeaf(sequence, self.getAlphabet(), name)