Skip to content
Snippets Groups Projects
Commit d2aefee3 authored by Nathalie Vialaneix's avatar Nathalie Vialaneix
Browse files

fixed a few bugs in checks, improved documentation and added DESCRIPTION

parent e472c499
No related branches found
No related tags found
No related merge requests found
Package: treediff
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Title: Testing Differences Between Families of Trees
Version: 0.1
Date: 2023-02-24
Authors@R:
person("First", "Last", , "first.last@example.com", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
Imports: dplyr, limma, reshape2, stats
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
c(person("Nathalie", "Vialaneix", , "nathalie.vialaneix@inrae.fr",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1156-0639")),
person("Gwendaelle", "Cardenac", , , role = "aut"),
person("Marie", "Chavent", , "marie.chavent@u-bordeaux.fr", role = "aut"),
person("Sylvain", "Foissac", , "sylvain.foissac@inrae.fr", role = "aut"),
person("Pierre", "Neuvial", , "pierre.neuvial@math.univ-toulouse.fr",
role = "aut"),
person("Nathanael", "Randriamihamison", , , role = "aut"))
Description: This package implements a method based on cophenetic distances
and designed to perform a test to detect differences in structure
between families of trees.
Depends: R (>= 4.0.0)
Imports: dplyr, limma, stats, reshape2, testthat, rlang
Suggest: adjclust
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
URL: https://forgemia.inra.fr/scales/treediff
BugReports: https://forgemia.inra.fr/scales/treediff/-/issues
......@@ -3,10 +3,12 @@
S3method(print,treeTest)
S3method(summary,treeTest)
export(treediff)
import(testthat)
importFrom(dplyr,"%>%")
importFrom(dplyr,group_by)
importFrom(dplyr,summarise)
importFrom(limma,squeezeVar)
importFrom(reshape2,colsplit)
importFrom(rlang,.data)
importFrom(stats,cophenetic)
importFrom(stats,pt)
......@@ -19,10 +19,12 @@
#' different from that of \code{trees1}.
#' @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 rescalled to have a
#' minimum height equal to 0 and a maximum height equal to 1.
#' @param order_labels Logical. If \code{TRUE}, take a reference tree and keep
#' track of leave order.
#' @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
#' \code{FALSE}.
#' @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}.
#'
#' @return An object of class \code{treeTest} with the following entries:
#' \itemize{
......@@ -58,6 +60,8 @@
#' @importFrom reshape2 colsplit
#' @importFrom stats cophenetic
#' @importFrom stats pt
#' @importFrom rlang .data
#' @import testthat
#'
#' @examples
#' leaves <- c(100, 120, 50, 80)
......@@ -98,7 +102,7 @@ treediff <- function(trees1, trees2, replicates, scale = FALSE,
order_labels = FALSE) {
# Check if `replicates` is numeric vector
if (inherits(replicates, "numeric") != TRUE) {
if (!is.numeric(replicates)) {
stop("`replicates` is not a numeric vector")
}
......@@ -169,13 +173,14 @@ treediff <- function(trees1, trees2, replicates, scale = FALSE,
# Aggregate p-values
out_aggr <- suppressWarnings(outp %>%
group_by(cluster) %>%
summarise("p.value" = min(sort(p.value) / (1:p)) * p, .groups = "keep") %>%
group_by(.data$cluster) %>%
summarise("p.value" = min(sort(.data$p.value) / (1:.data$p)) * .data$p,
.groups = "keep") %>%
unique())
# Store results in a list
data_name <- paste(substitute(trees1), "and", substitute(trees2))
out <- list("method" = "Tree test based on t-test",
out <- list("method" = "Tree test based on aggregated t-tests",
"data.name" = data_name,
"p.value" = out_aggr$p.value,
"statistic" = outp$statistics,
......@@ -189,6 +194,8 @@ treediff <- function(trees1, trees2, replicates, scale = FALSE,
}
#' @export
#' @param x a \code{treeTest} object to print
#' @param ... not used
#' @rdname treediff
print.treeTest <- function(x, ...) {
......@@ -199,17 +206,18 @@ print.treeTest <- function(x, ...) {
cat("\n")
# Print the name of the data used in the test
cat("data : ", x$data.name, "\n", sep = "")
cat("data: ", x$data.name, "\n", sep = "")
# print alternative hypothesis
cat("alternative hypothesis : sets of trees are different.")
cat("alternative hypothesis: the two sets of trees have different structure.")
cat ("\n\n")
# print the first 5 p-values
print(colsplit(x$p.value, " ", "p.values :"), max = 5)
print(colsplit(x$p.value, " ", "p-values:"), max = 5)
}
#' @method summary treeTest
#' @param object a \code{treeTest} object to print
#' @export
#' @rdname treediff
......@@ -219,7 +227,7 @@ summary.treeTest <- function(object, ...) {
cat("\nSummary\n")
# Print the class of the object
cat("\tClass : ", class(object))
cat("\tClass: ", class(object))
cat("\n")
# Print the test output
......@@ -227,13 +235,14 @@ summary.treeTest <- function(object, ...) {
cat("\n")
# Print a summary of the p.value
cat("p.value\n")
cat(" p-value summary:\n")
print(summary(object$p.value))
cat("\n")
# Print a summary of the `statistic` and `p.value.indiv`
summary(data.frame("statistic" = object$statistic,
"p.value.indiv" = object$p.value.indiv))
summary(data.frame("indiv. statistics" = object$statistic,
"indiv. p-values" = object$p.value.indiv,
check.names = FALSE))
}
compute_squeeze <- function(dist_coph, replicates) {
......
......@@ -26,24 +26,32 @@ different from that of \code{trees1}.}
\item{replicates}{A numeric vector of length 2 with the number of replicates
for each condition.}
\item{scale}{Logical. If \code{TRUE}, the trees are all rescalled to have a
minimum height equal to 0 and a maximum height equal to 1.}
\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
\code{FALSE}.}
\item{order_labels}{Logical. If \code{TRUE}, take a reference tree and keep
track of leave order.}
\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}.}
\item{x}{a \code{treeTest} object to print}
\item{...}{not used}
\item{object}{a \code{treeTest} object to print}
}
\value{
An object of class \code{treeTest} with the following entries:
\itemize{
\item{p.value}{ the p-value for the treediff test.}
\item{statistic}{ the value of the Student's statistic of each leaf pair of
the tree test.}
\item{p.value.indiv}{ the p-value of the Student's test for each leaf pair
of the tree test.}
\item{method}{ a character string indicating what type of test was
performed.}
\item{data.name}{ a character string giving the names of the tree
conditions.}
\item{p.value}{ the p-value for the treediff test.}
\item{statistic}{ the value of the Student's statistic of each leaf pair of
the tree test.}
\item{p.value.indiv}{ the p-value of the Student's test for each leaf pair
of the tree test.}
\item{method}{ a character string indicating what type of test was
performed.}
\item{data.name}{ a character string giving the names of the tree
conditions.}
}
}
\description{
......
......@@ -29,7 +29,7 @@ trees1 <- unlist(trees[1,], recursive = FALSE)
trees2 <- unlist(trees[2,], recursive = FALSE)
# Set the number of replicates
replicates = c(4, 6)
replicates <- c(4, 6)
test_that("'treediff' works for simple cases", {
......@@ -70,25 +70,24 @@ test_that("'treediff' works for simple cases", {
})
## Test errors
test_that("Test errors", {
# Test if replicates is numeric vector
expect_error(treediff(trees1 = trees1, trees2 = trees2, replicates = "abc"),
"`replicates` is not a numeric vector")
# Test if replicates is a vector of length 2
expect_error(treediff(trees1 = trees1, trees2 = trees2, replicates = c(1,2,3)),
expect_error(treediff(trees1 = trees1, trees2 = trees2, replicates = 1:3),
"`replicates` must be a vector of length 2.")
# Test if output is a list with class treeTest
out <- treediff(trees1, trees2, c(4,6))
out <- treediff(trees1, trees2, c(4, 6))
expect_true(inherits(out, "treeTest"))
# 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)), "the number of leaves in one or more clusters is different between the two sets of trees.")
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.")
})
......
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