Example #1
0
def test_emit():
    """
    Calculate emission probabilities
    """

    k = 10
    n = 1e4
    rho = 1.5e-8 * 20
    mu = 2.5e-8 * 20
    length = int(1e3) / 20
    times = argweaver.get_time_points(ntimes=20, maxtime=200000)

    arg = argweaver.sample_arg_dsmc(k,
                                    2 * n,
                                    rho,
                                    start=0,
                                    end=length,
                                    times=times)

    muts = argweaver.sample_arg_mutations(arg, mu, times)
    seqs = argweaver.make_alignment(arg, muts)

    new_name = "n%d" % (k - 1)
    arg = argweaver.remove_arg_thread(arg, new_name)

    trees, names = argweaverc.arg2ctrees(arg, times)
    seqs2, nseqs, seqlen = argweaverc.seqs2cseqs(seqs, names + [new_name])

    assert argweaverc.argweaver_assert_emit(trees, len(times), times, mu,
                                            seqs2, nseqs, seqlen)
Example #2
0
def test_emit():
    """
    Calculate emission probabilities
    """

    k = 10
    n = 1e4
    rho = 1.5e-8 * 20
    mu = 2.5e-8 * 20
    length = int(1e3) / 20
    times = argweaver.get_time_points(ntimes=20, maxtime=200000)

    arg = argweaver.sample_arg_dsmc(k, 2*n, rho, start=0, end=length,
                                    times=times)

    muts = argweaver.sample_arg_mutations(arg, mu, times)
    seqs = argweaver.make_alignment(arg, muts)

    new_name = "n%d" % (k-1)
    arg = argweaver.remove_arg_thread(arg, new_name)

    trees, names = argweaverc.arg2ctrees(arg, times)
    seqs2, nseqs, seqlen = argweaverc.seqs2cseqs(seqs, names + [new_name])

    assert argweaverc.argweaver_assert_emit(trees, len(times), times, mu,
                                            seqs2, nseqs, seqlen)
Example #3
0
def test_forward():

    k = 4
    n = 1e4
    rho = 1.5e-8 * 20
    mu = 2.5e-8 * 20
    length = int(100e3 / 20)
    times = argweaver.get_time_points(ntimes=100)

    arg = arglib.sample_arg_smc(k, 2 * n, rho, start=0, end=length)
    muts = arglib.sample_arg_mutations(arg, mu)
    seqs = arglib.make_alignment(arg, muts)

    print "muts", len(muts)
    print "recomb", len(arglib.get_recomb_pos(arg))

    argweaver.discretize_arg(arg, times)

    # remove chrom
    new_name = "n%d" % (k - 1)
    arg = argweaver.remove_arg_thread(arg, new_name)

    carg = argweaverc.arg2ctrees(arg, times)

    util.tic("C fast")
    probs1 = argweaverc.argweaver_forward_algorithm(carg, seqs, times=times)
    util.toc()

    util.tic("C slow")
    probs2 = argweaverc.argweaver_forward_algorithm(carg,
                                                    seqs,
                                                    times=times,
                                                    slow=True)
    util.toc()

    for i, (col1, col2) in enumerate(izip(probs1, probs2)):
        for a, b in izip(col1, col2):
            fequal(a, b, rel=.0001)
Example #4
0
def test_forward():

    k = 4
    n = 1e4
    rho = 1.5e-8 * 20
    mu = 2.5e-8 * 20
    length = int(100e3 / 20)
    times = argweaver.get_time_points(ntimes=100)

    arg = arglib.sample_arg_smc(k, 2*n, rho, start=0, end=length)
    muts = arglib.sample_arg_mutations(arg, mu)
    seqs = arglib.make_alignment(arg, muts)

    print "muts", len(muts)
    print "recomb", len(arglib.get_recombs(arg))

    argweaver.discretize_arg(arg, times)

    # remove chrom
    new_name = "n%d" % (k - 1)
    arg = argweaver.remove_arg_thread(arg, new_name)

    carg = argweaverc.arg2ctrees(arg, times)

    util.tic("C fast")
    probs1 = argweaverc.argweaver_forward_algorithm(carg, seqs, times=times)
    util.toc()

    util.tic("C slow")
    probs2 = argweaverc.argweaver_forward_algorithm(carg, seqs, times=times,
                                                    slow=True)
    util.toc()

    for i, (col1, col2) in enumerate(izip(probs1, probs2)):
        for a, b in izip(col1, col2):
            fequal(a, b, rel=.0001)