Exemple #1
0
def sample_arg_dsmc(k, popsize, rho, recombmap=None,
                    start=0.0, end=0.0, times=None, times2=None,
                    init_tree=None, names=None, make_names=True):
    """
    Returns an ARG sampled from the Discrete Sequentially Markov Coalescent

    k   -- chromosomes
    popsize -- effective population size
    rho -- recombination rate (recombinations / site / generation)
    recombmap -- map for variable recombination rate
    start -- staring chromosome coordinate
    end   -- ending chromsome coordinate

    names -- names to use for leaves (default: None)
    make_names -- make names using strings (default: True)
    """
    if times is None:
        maxtime = 160000
        delta = .01
        ntimes = 20
        times = argweaver.get_time_points(ntimes, maxtime, delta)

    it = sample_dsmc_sprs(
        k, popsize, rho, recombmap=recombmap,
        start=start, end=end, times=times, times2=times2,
        init_tree=init_tree, names=names, make_names=make_names)
    tree = it.next()
    arg = arglib.make_arg_from_sprs(tree, it)

    return arg
Exemple #2
0
def sample_arg_dsmc(k, popsize, rho, recombmap=None,
                    start=0.0, end=0.0, times=None,
                    init_tree=None, names=None, make_names=True):
    """
    Returns an ARG sampled from the Discrete Sequentially Markov Coalescent

    k   -- chromosomes
    popsize -- effective population size
    rho -- recombination rate (recombinations / site / generation)
    recombmap -- map for variable recombination rate
    start -- staring chromosome coordinate
    end   -- ending chromsome coordinate

    names -- names to use for leaves (default: None)
    make_names -- make names using strings (default: True)
    """
    if times is None:
        maxtime = 160000
        delta = .01
        ntimes = 20
        times = argweaver.get_time_points(ntimes, maxtime, delta)

    it = sample_dsmc_sprs(
        k, popsize, rho, recombmap=recombmap,
        start=start, end=end, times=times,
        init_tree=init_tree, names=names, make_names=make_names)
    tree = it.next()
    arg = arglib.make_arg_from_sprs(tree, it)

    return arg
Exemple #3
0
def smc2arg(smc):
    """
    Convert SMC to ARG.

    NOTE: SMC is 1-index and ARG is 0-index
    """

    it = smc2sprs(smc)
    tree = it.next()
    arg = arglib.make_arg_from_sprs(tree, it)

    return arg
Exemple #4
0
def smc2arg(smc):
    """
    Convert SMC to ARG.

    NOTE: SMC is 1-index and ARG is 0-index
    """

    it = smc2sprs(smc)
    tree = it.next()
    arg = arglib.make_arg_from_sprs(tree, it)

    return arg
Exemple #5
0
def treeset2arg(ptrees, ages, sprs, blocks, names, times):
    """
    Converts a ptree representation into an ARG.
    """

    seqlen = blocks[-1][1]
    arg = arglib.ARG(0, seqlen)

    # build first tree
    lookup = {}
    for i, p in enumerate(ptrees[0]):
        if i < len(names):
            # make leaf
            lookup[i] = arg.new_node(names[i], age=times[ages[0][i]],
                                     event="gene")
        else:
            lookup[i] = arg.new_node(age=times[ages[0][i]], event="coal")

    # set parents of new tree
    for i, p in enumerate(ptrees[0]):
        node = lookup[i]
        if p != -1:
            node.parents.append(lookup[p])
            node.parents[0].children.append(node)
        else:
            arg.root = node

    # convert sprs
    sprs2 = []
    for i, (rinode, ritime, cinode, citime) in enumerate(sprs):
        pos = blocks[i][0]  # - 1

        # check for null spr
        if rinode == -1:
            continue

        # make local tree
        ptree = ptrees[i-1]
        tree = treelib.Tree()
        lookup = []
        for j in range(len(ptree)):
            if j < len(names):
                lookup.append(tree.new_node(names[j]))
            else:
                lookup.append(tree.new_node())
        for j in range(len(ptree)):
            if ptree[j] != -1:
                parent = lookup[ptree[j]]
                tree.add_child(parent, lookup[j])
            else:
                tree.root = lookup[j]

        # get leaf sets
        rleaves = lookup[rinode].leaf_names()
        cleaves = lookup[cinode].leaf_names()
        assert ritime >= ages[i-1][rinode], (pos, ritime, ages[i-1][rinode])
        assert citime >= ages[i-1][cinode], (pos, citime, ages[i-1][cinode])

        sprs2.append((pos, (rleaves, times[ritime]), (cleaves, times[citime])))

    arglib.make_arg_from_sprs(arg, sprs2)
    return arg