Skip to content
Snippets Groups Projects
Commit 98805182 authored by CARDENAS GWENDAELLE's avatar CARDENAS GWENDAELLE
Browse files

add tests scale and order_labels

parent d2aefee3
No related branches found
No related tags found
No related merge requests found
......@@ -20,9 +20,9 @@
#' @param replicates A numeric vector of length 2 with the number of replicates
#' for each condition.
#' @param scale Logical. If \code{TRUE}, the trees are all rescaled to have a
#' minimum height equal to 0 and a maximum height equal to 1. Default to
#' minimum height equal to 0 and a maximum height equal to 1. Default to
#' \code{FALSE}.
#' @param order_labels Logical. If \code{TRUE}, align leaves ordering in all
#' @param order_labels Logical. If \code{TRUE}, align leaves ordering in all
#' trees (required if your trees don't have their leaves ordered identically).
#' Default to \code{FALSE}.
#'
......@@ -142,7 +142,7 @@ treediff <- function(trees1, trees2, replicates, scale = FALSE,
coph_dist <- sapply(trees, cophenetic, simplify = FALSE)
# Normalize
if (scale) {
if (scale == TRUE) {
coph_dist <- normalize_trees(coph_dist)
}
......@@ -174,7 +174,7 @@ treediff <- function(trees1, trees2, replicates, scale = FALSE,
# Aggregate p-values
out_aggr <- suppressWarnings(outp %>%
group_by(.data$cluster) %>%
summarise("p.value" = min(sort(.data$p.value) / (1:.data$p)) * .data$p,
summarise("p.value" = min(sort(.data$p.value) / (1:.data$p)) * .data$p,
.groups = "keep") %>%
unique())
......
......@@ -27,10 +27,10 @@ different from that of \code{trees1}.}
for each condition.}
\item{scale}{Logical. If \code{TRUE}, the trees are all rescaled to have a
minimum height equal to 0 and a maximum height equal to 1. Default to
minimum height equal to 0 and a maximum height equal to 1. Default to
\code{FALSE}.}
\item{order_labels}{Logical. If \code{TRUE}, align leaves ordering in all
\item{order_labels}{Logical. If \code{TRUE}, align leaves ordering in all
trees (required if your trees don't have their leaves ordered identically).
Default to \code{FALSE}.}
......
......@@ -86,7 +86,7 @@ test_that("Test errors", {
# Test if the number of leaves in each cluster is the same between the two
# sets of trees
trees2[[5]]$order <- c(trees2[[5]]$order, 101)
expect_error(treediff(trees1, trees2, c(4, 6)),
expect_error(treediff(trees1, trees2, c(4, 6)),
"the number of leaves in one or more clusters is different between the two sets of trees.")
})
......@@ -129,3 +129,44 @@ test_that("Test for compute_pvalue", {
expect_length(pvals$p.value, 1225)
expect_length(pvals, 4)
})
# Test for the scale argument
test_that("Test for the scale argument", {
# Perform the treediff test with scaling
res <- treediff(trees1, trees2, replicates, scale = TRUE)
# Check the output object has the expected names
expect_named(res, c("method", "data.name", "p.value",
"statistic", "p.value.indiv"))
# Perform the treediff test without scaling
result1 <- treediff(trees1, trees2, replicates)
result2 <- treediff(trees1, trees2, replicates, scale = FALSE)
result3 <- treediff(trees1, trees2, replicates, scale = 5)
expect_equal(result1, result2)
expect_equal(result1, result3)
})
# Test for the order_labels argument
test_that("Test for the order_labels argument", {
# Perform the treediff test with ordering the labels without labels
expect_error(treediff(trees1, trees2, replicates, order_labels = TRUE))
# Create a set of trees with different leaf orders
trees1 <- list(hclust(dist(mtcars[, 1:2]), method = "ward.D2"),
hclust(dist(mtcars[, 3:4]), method = "ward.D2"))
trees2 <- list(hclust(dist(mtcars[, 5:6]), method = "ward.D2"),
hclust(dist(mtcars[, 7:8]), method = "ward.D2"))
# Perform the treediff test with and without ordering the labels
res1 <- treediff(trees1, trees2, c(2,2), order_labels = TRUE)
res2 <- treediff(trees1, trees2, c(2,2), order_labels = FALSE)
# Test that the p-values are the same for both tests
expect_equal(res1, res2)
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment