Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
treediff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
A compter du 1er avril, attention à vos pipelines :
Nouvelles limitations de Docker Hub
Show more breadcrumbs
SCALES
treediff
Commits
98805182
Commit
98805182
authored
2 years ago
by
CARDENAS GWENDAELLE
Browse files
Options
Downloads
Patches
Plain Diff
add tests scale and order_labels
parent
d2aefee3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
R/treediff.R
+4
-4
4 additions, 4 deletions
R/treediff.R
man/treediff.Rd
+2
-2
2 additions, 2 deletions
man/treediff.Rd
tests/testthat/test-treediff.R
+42
-1
42 additions, 1 deletion
tests/testthat/test-treediff.R
with
48 additions
and
7 deletions
R/treediff.R
+
4
−
4
View file @
98805182
...
...
@@ -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
())
...
...
This diff is collapsed.
Click to expand it.
man/treediff.Rd
+
2
−
2
View file @
98805182
...
...
@@ -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}.}
...
...
This diff is collapsed.
Click to expand it.
tests/testthat/test-treediff.R
+
42
−
1
View file @
98805182
...
...
@@ -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
)
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment