tests/testthat/test_locus_gene.R

# test species tree output is a list of trees with correct length
sim_test_spt_loct <- function(gbr, gdr, lgtr, numLoci, species_tree_len = 5.0){
    tr <- sim_stBD_t(0.1, 0.05, 1, species_tree_len)
    sim_ltBD(tr[[1]],
                      gbr = gbr,
                      gdr = gdr,
                      lgtr = lgtr,
                      num_loci = numLoci)

}

sim_test_spt_loct <- function(gbr, gdr, lgtr, numLoci, species_tree_len = 5.0){
    tr <- sim_stBD_t(0.1, 0.05, 1, species_tree_len)
    sim_ltBD(tr[[1]],
                      gbr = gbr,
                      gdr = gdr,
                      lgtr = lgtr,
                      num_loci = numLoci)

}

sim_test_spt_loct_equality <- function(gene_birth = 0.0, gene_death = 0.0, transfers = 0.0, numLoci){
    tr <- sim_stBD_t(0.1, 0.05, 1, 5.0)
    loctr <- sim_ltBD(tr[[1]],
                               gbr = gene_birth,
                               gdr = gene_death,
                               lgtr = transfers,
                               num_loci = numLoci)
    all(sapply(loctr, ape::all.equal.phylo, current = tr[[1]], use.tip.label = FALSE))
}

test_that("sim_ltBD produces the right number of trees", {
    expect_equal(length(sim_test_spt_loct(0.1, 0.05, 0.05, 10)), 10)
    expect_equal(length(sim_test_spt_loct(0.1, 0.05, 0.05, 5)), 5)
    expect_equal(length(sim_test_spt_loct(0.1, 0.05, 0.05, 50)), 50)
})



# test that input species tree is the same as locus tree if every param is set
# 0.0
test_that("sim_ltBD returns tree concordant with species tree when locus tree parameters are 0.0",{
    expect_true(sim_test_spt_loct_equality(numLoci = 20))
})


get_length_tree <- function(tr){
    max(ape::node.depth.edgelength(tr)) + tr$root.edge
}

get_all_tree_lengths <- function(multiTree){
    min(sapply(multiTree, get_length_tree))
}

Try the treeducken package in your browser

Any scripts or data that you put into this service are public.

treeducken documentation built on March 3, 2021, 1:11 a.m.