Exemplo n.º 1
0
def prob_locus_coal_recon_topology_samples(
    coal_tree, coal_recon,
    locus_tree, locus_recon, locus_events, locus_popsizes,
    stree, stimes,
    daughters,
    birth, death, nsamples, pretime=None, premean=100.0):

    if pretime is None:
        pretime = -1
    

    ptree, nodes, nodelookup = dlcoal.make_ptree(coal_tree)
    pltree, lnodes, lnodelookup = dlcoal.make_ptree(locus_tree)
    pstree, snodes, snodelookup = dlcoal.make_ptree(stree)
    
    crecon2 = dlcoal.make_recon_array(
        coal_tree, coal_recon, nodes, lnodelookup)
    lrecon2 = dlcoal.make_recon_array(
        locus_tree, locus_recon, lnodes, snodelookup)
    levents2 = dlcoal.make_events_array(lnodes, locus_events)

    locus_popsizes = compbio.coal.init_popsizes(locus_tree, locus_popsizes)
    popsizes2 = [locus_popsizes[lnode.name] for lnode in lnodes]

    stimes2 = [stimes[snode] for snode in snodes]

    daughters2 = [lnodelookup[lnode] for lnode in daughters]
    
    p = dlcoal.dlcoalc.prob_locus_coal_recon_topology_samples(
        c_list(c_int, ptree), len(nodes), c_list(c_int, crecon2),
        c_list(c_int, pltree), len(lnodes),
        c_list(c_int, lrecon2), c_list(c_int, levents2),
        c_list(c_double, popsizes2),
        c_list(c_int, pstree), len(snodes), c_list(c_double, stimes2),
        c_list(c_int, daughters2), len(daughters),
        birth, death, nsamples, pretime, premean)

    return p
Exemplo n.º 2
0
def prob_multicoal_recon_topology(tree, recon, stree, n,
                                  lineages=None, top_stats=None):

    ptree, nodes, nodelookup = dlcoal.make_ptree(tree)
    pstree, snodes, snodelookup = dlcoal.make_ptree(stree)
    recon2 = dlcoal.make_recon_array(tree, recon, nodes, snodelookup)

    popsizes = compbio.coal.init_popsizes(stree, n)
    popsizes2 = [popsizes[snode.name] for snode in snodes]
    sdists = [snode.dist for snode in snodes]
    
    p = dlcoal.dlcoalc.prob_multicoal_recon_topology(
        c_list(c_int, ptree), len(nodes), c_list(c_int, recon2),
        c_list(c_int, pstree), len(snodes), c_list(c_double, sdists),
        c_list(c_double, popsizes2))
    
    return p
Exemplo n.º 3
0
def prob_locus_coal_recon_topology(tree, recon, locus_tree, n, daughters):

    ptree, nodes, nodelookup = dlcoal.make_ptree(tree)
    pltree, lnodes, lnodelookup = dlcoal.make_ptree(locus_tree)
    recon2 = dlcoal.make_recon_array(tree, recon, nodes, lnodelookup)

    popsizes = compbio.coal.init_popsizes(locus_tree, n)
    popsizes2 = [popsizes[lnode.name] for lnode in lnodes]

    ltimes = treelib.get_tree_timestamps(locus_tree)
    ltimes2 = [ltimes[lnode] for lnode in lnodes]

    daughters2 = [lnodelookup[lnode] for lnode in daughters]
    
    p = dlcoal.dlcoalc.prob_locus_coal_recon_topology(
        c_list(c_int, ptree), len(nodes), c_list(c_int, recon2),
        c_list(c_int, pltree), 0, len(lnodes),
        c_list(c_double, popsizes2), c_list(c_double, ltimes2),
        c_list(c_int, daughters2), len(daughters))
    
    return p
Exemplo n.º 4
0
def prob_dup_loss(tree, stree, recon, events, duprate, lossrate):
    """Returns the topology prior of a gene tree"""

    if dlcoal.dlcoalc:
        if events is None:
            events = phylo.label_events(tree, recon)

        ptree, nodes, nodelookup = dlcoal.make_ptree(tree)
        pstree, snodes, snodelookup = dlcoal.make_ptree(stree)

        ctree = dlcoal.tree2ctree(tree)
        cstree = dlcoal.tree2ctree(stree)
        recon2 = dlcoal.make_recon_array(tree, recon, nodes, snodelookup)
        events2 = dlcoal.make_events_array(nodes, events)

        doomtable = c_list(c_double, [0] * len(stree.nodes))
        dlcoal.dlcoalc.calcDoomTable(cstree, duprate, lossrate, doomtable)

        p = dlcoal.dlcoalc.birthDeathTreePriorFull(ctree, cstree,
                                    c_list(c_int, recon2), 
                                    c_list(c_int, events2),
                                    duprate, lossrate, doomtable)
        dlcoal.dlcoalc.deleteTree(ctree)
        dlcoal.dlcoalc.deleteTree(cstree)

        return p

    else:
        if "dlcoal_python_fallback" not in globals():
            print >>sys.stderr, "warning: using python code instead of native"
            globals()["dlcoal_python_fallback"] = 1
            # spidir libs
            import spidir
            from spidir import topology_prior
            
        return topology_prior.dup_loss_topology_prior(
            tree, stree, recon, duprate, lossrate,
            events=events)