示例#1
0
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
示例#2
0
 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
示例#3
0
 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
示例#4
0
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
示例#5
0
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
示例#6
0
文件: align.py 项目: miklou/pycogent
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 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)
示例#8
0
 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)