示例#1
0
文件: align.py 项目: jbw900/cogent3
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] = [make_likelihood_tree_leaf(seq) for seq in [s1, s2]]
    [p1, p2] = [pairwise.AlignableSeq(leaf) for leaf in [p1, p2]]
    pair = pairwise.Pair(p1, p2)
    EP = pair.make_simple_emission_probs(mprobs, [psub])
    hmm = EP.make_pair_HMM(TM)
    vpath = hmm.get_viterbi_path(local=local, **kw)
    score = vpath.get_score()
    if return_alignment:
        alignment = vpath.get_alignment()
        if return_score:
            return (alignment, score)
        else:
            return alignment
    else:
        return score
示例#2
0
    def count_motifs(self, alignment, include_ambiguity=False, recode_gaps=True):
        result = None
        try:
            mtype = self.alphabet.moltype
        except AttributeError:
            mtype = self.monomer_alphabet.moltype

        for seq_name in alignment.names:
            sequence = alignment.get_gapped_seq(seq_name, recode_gaps, moltype=mtype)
            leaf = make_likelihood_tree_leaf(
                sequence, self.get_counted_alphabet(), seq_name
            )
            count = leaf.get_motif_counts(include_ambiguity=include_ambiguity)
            if result is None:
                result = count.copy()
            else:
                result += count
        return result
示例#3
0
 def convert_sequence(self, sequence, name):
     # make_likelihood_tree_leaf, sort of an indexed profile where duplicate
     # columns stored once, so likelihoods only calc'd once
     return make_likelihood_tree_leaf(sequence, self.get_alphabet(), name)