Esempio n. 1
0
def ls_viterbi_tree(h, alleles, ts, rho, mu, precision=30, use_lib=True):
    """
    Viterbi path computation based on a tree sequence.
    """
    if use_lib:
        acgt_alleles = tuple(alleles) == tskit.ALLELES_ACGT
        ls_hmm = _tskit.LsHmm(
            ts.ll_tree_sequence, recombination_rate=rho, mutation_rate=mu,
            precision=precision, acgt_alleles=acgt_alleles)
        vm = _tskit.ViterbiMatrix(ts.ll_tree_sequence)
        ls_hmm.viterbi_matrix(h, vm)
        return vm
    else:
        va = ViterbiAlgorithm(ts, rho, mu, alleles, precision=precision)
        return va.run(h)
Esempio n. 2
0
def ls_forward_tree(h, alleles, ts, rho, mu, precision=30, use_lib=True):
    """
    Forward matrix computation based on a tree sequence.
    """
    if use_lib:
        acgt_alleles = tuple(alleles) == tskit.ALLELES_ACGT
        ls_hmm = _tskit.LsHmm(
            ts.ll_tree_sequence, recombination_rate=rho, mutation_rate=mu,
            precision=precision, acgt_alleles=acgt_alleles)
        cm = _tskit.CompressedMatrix(ts.ll_tree_sequence)
        ls_hmm.forward_matrix(h, cm)
        return cm
    else:
        fa = ForwardAlgorithm(ts, rho, mu, alleles, precision=precision)
        return fa.run(h)