diff --git a/DESCRIPTION b/DESCRIPTION index 025123a..160de27 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,8 +8,8 @@ Authors@R: c(person("Christophe", "Ambroise", role="aut"), person("Guillem", "Rigaill", role="aut"), person("Nathalie", "Vialaneix", role="aut"), person("Gabriel", "Hoffman", role="aut")) -Date: 2023-04-24 -Version: 0.6.7 +Date: 2024-01-10 +Version: 0.6.8 License: GPL-3 Title: Adjacency-Constrained Clustering of a Block-Diagonal Similarity Matrix Description: Implements a constrained version of hierarchical agglomerative diff --git a/NEWS.md b/NEWS.md index 690b724..19f7864 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# Version 0.6.8 [2024-01-10] + +* Fix CRAN error on useNames (deprecated NA) +* Fix CRAN note on itemize (unecessary use of itemize) +* Limited OMP threads to 2 in examples, vignettes and tests +* Updated citation of the package + # Version 0.6.7 [2023-04-24] * Fix #60 (increase test coverage) diff --git a/R/adjclust.R b/R/adjclust.R index f7a7e40..c3f7c21 100644 --- a/R/adjclust.R +++ b/R/adjclust.R @@ -33,7 +33,7 @@ NULL #' produced by the clustering process. The object is a list with the same #' elements as an object of class \code{\link[stats]{hclust}} (\code{merge}, #' \code{height}, \code{order}, \code{labels}, \code{call}, \code{method}, -#' \code{dist.method}), and two extra elements: \itemize{ +#' \code{dist.method}), and two extra elements: #' \item{\code{mat}}{: (the data on which the clustering has been performed, #' possibly after the pre-transformations described in the vignette entitled #' \href{https://pneuvial.github.io/adjclust/articles/notesCHAC.html#notes-on-relations-between-similarity-and-dissimilarity-implementation}{"Notes on CHAC implementation in adjclust"}}. @@ -41,7 +41,6 @@ NULL #' definite similarity matrices (also described in the same vignette). If #' \code{correction == 0}, it means that the initial data were not #' pre-transformed.} -#' } #' #' @seealso \code{\link{snpClust}} to cluster SNPs based on linkage #' disequilibrium @@ -263,24 +262,24 @@ run.adjclust <- function(mat, type = c("similarity", "dissimilarity"), h, if (is(mat, "sparseMatrix")) { # left rCumL <- matL_sparse_rowCumsums(mat, h) - rcCumL <- colCumsums(rCumL) # p x (h+1) matrix + rcCumL <- colCumsums(rCumL, useNames = FALSE) # p x (h+1) matrix rm(rCumL) # right rCumR <- matR_sparse_rowCumsums(mat, h) - rcCumR <- colCumsums(rCumR) # p x (h+1) matrix + rcCumR <- colCumsums(rCumR, useNames = FALSE) # p x (h+1) matrix rm(rCumR) out_matL <- matL_sparse(mat, 2) } else { # left rCumL <- matL_full_rowCumsums(mat, h) - rcCumL <- colCumsums(rCumL) # p x (h+1) matrix + rcCumL <- colCumsums(rCumL, useNames = FALSE) # p x (h+1) matrix rm(rCumL) # right rCumR <- matR_full_rowCumsums(mat, h) - rcCumR <- colCumsums(rCumR) # p x (h+1) matrix + rcCumR <- colCumsums(rCumR, useNames = FALSE) # p x (h+1) matrix rm(rCumR) out_matL <- matL_full(mat, 2) diff --git a/R/chac.R b/R/chac.R index d754535..f8bd8aa 100644 --- a/R/chac.R +++ b/R/chac.R @@ -292,7 +292,7 @@ cutree_chac <- function(tree, k = NULL, h = NULL) { #' table(selected.bs) #' }} #' -#' res <- adjClust(dist(iris[ ,1:4])) +#' res <- adjClust(dist(iris[, 1:4])) #' select.clust <- select(res, "bs") #' table(select.clust) #' diff --git a/R/helpers.R b/R/helpers.R index 040fa5d..06bd40a 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -223,8 +223,8 @@ alt.plotNode <- function(x1, x2, subtree, type, center, leaflab, dLeaf, nodePar, vln <- NULL if (is.leaf(child) && leaflab == "textlike") { nodeText <- asTxt(attr(child, "label")) - cat("nodeText 2 vaut : ") - print(nodeText) + # cat("nodeText 2 vaut : ") + # print(nodeText) if (getOption("verbose")) cat("-- with \"label\"", format(nodeText)) hln <- 0.6 * strwidth(nodeText, cex = lab.cex)/2 diff --git a/R/hicClust.R b/R/hicClust.R index c17668f..4e246ef 100644 --- a/R/hicClust.R +++ b/R/hicClust.R @@ -56,7 +56,9 @@ #' } #' #' # input as text file +#' \dontrun{ #' res3 <- hicClust(system.file("extdata", "sample.txt", package = "adjclust")) +#' } #' #' @export #' diff --git a/R/snpClust.R b/R/snpClust.R index 534eb29..05e17d0 100644 --- a/R/snpClust.R +++ b/R/snpClust.R @@ -61,7 +61,7 @@ #' #' @examples #' ## a very small example -#' if (requireNamespace("snpStats", quietly = TRUE)) { +#' \dontrun{ #' data(testdata, package = "snpStats") #' #' # input as snpStats::SnpMatrix diff --git a/R/zzzz.R b/R/zzzz.R new file mode 100644 index 0000000..9bad49f --- /dev/null +++ b/R/zzzz.R @@ -0,0 +1,4 @@ +.onLoad <- function(libname, pkgname) { + # CRAN OMP THREAD LIMIT + Sys.setenv("OMP_THREAD_LIMIT" = 1) +} \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index 700c126..3564ec3 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,7 +17,7 @@ knitr::opts_chunk$set( [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/adjclust)](https://cran.r-project.org/package=adjclust) [![R build status](https://github.com/pneuvial/adjclust/workflows/R-CMD-check/badge.svg)](https://github.com/pneuvial/adjclust/actions) -[![Coverage Status](https://img.shields.io/codecov/c/github/pneuvial/adjclust/develop.svg)](https://codecov.io/github/pneuvial/adjclust/branch/develop) +[![Coverage Status](https://img.shields.io/codecov/c/github/pneuvial/adjclust/develop.svg)](https://app.codecov.io/github/pneuvial/adjclust/branch/develop) `adjclust` is a package that provides methods to perform adjacency-constrained hierarchical agglomerative clustering. Adjacency-constrained hierarchical agglomerative clustering is hierarchical agglomerative clustering (HAC) in which each observation is associated to a position, and the clustering is constrained so as only adjacent clusters are merged. It is useful in bioinformatics (e.g. Genome Wide Association Studies or Hi-C data analysis). diff --git a/README.md b/README.md index 8bfea42..bced8d1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![R build status](https://github.com/pneuvial/adjclust/workflows/R-CMD-check/badge.svg)](https://github.com/pneuvial/adjclust/actions) [![Coverage -Status](https://codecov.io/gh/pneuvial/adjclust/branch/develop/graph/badge.svg)](https://app.codecov.io/gh/pneuvial/adjclust/tree/develop) +Status](https://img.shields.io/codecov/c/github/pneuvial/adjclust/develop.svg)](https://app.codecov.io/github/pneuvial/adjclust/branch/develop) `adjclust` is a package that provides methods to perform adjacency-constrained hierarchical agglomerative clustering. @@ -76,10 +76,9 @@ image(ld.ceph, lwd = 0) fit <- snpClust(geno, stats = "R.squared", h = h) #> Warning in run.snpClust(x, h = h, stats = stats): Forcing the LD similarity to #> be smaller than or equal to 1 -#> as(, "dgTMatrix") is deprecated since Matrix 1.4-2; do as(., "generalMatrix") instead #> Note: 133 merges with non increasing heights. plot(fit) -#> Warning in plot.chac(fit): +#> Warning: #> Detected reversals in dendrogram: mode = 'corrected', 'within-disp' or 'total-disp' might be more relevant. ``` @@ -88,6 +87,9 @@ plot(fit) ``` r sel_clust <- select(fit, "bs") plotSim(as.matrix(ld.ceph), clustering = sel_clust, dendro = fit) +#> Warning: +#> Detected reversals in dendrogram: mode = 'corrected', 'within-disp' or 'total-disp' might be more relevant. +#> Warning: Removed 602 rows containing missing values (`geom_text()`). ``` ![](man/figures/README-snpClust-3.png) @@ -118,7 +120,7 @@ mapC(binned) fitB <- hicClust(binned) #> Note: 5 merges with non increasing heights. plot(fitB) -#> Warning in plot.chac(fitB): +#> Warning: #> Detected reversals in dendrogram: mode = 'corrected', 'within-disp' or 'total-disp' might be more relevant. ``` @@ -126,6 +128,9 @@ plot(fitB) ``` r plotSim(intdata(binned), dendro = fitB) # default: log scale for colors +#> Warning: +#> Detected reversals in dendrogram: mode = 'corrected', 'within-disp' or 'total-disp' might be more relevant. +#> Warning: Removed 41 rows containing missing values (`geom_text()`). ``` ![](man/figures/README-hicClust-3.png) diff --git a/man/adjClust.Rd b/man/adjClust.Rd index 587d328..5395899 100644 --- a/man/adjClust.Rd +++ b/man/adjClust.Rd @@ -31,7 +31,7 @@ An object of class \code{\link{chac}} which describes the tree produced by the clustering process. The object is a list with the same elements as an object of class \code{\link[stats]{hclust}} (\code{merge}, \code{height}, \code{order}, \code{labels}, \code{call}, \code{method}, - \code{dist.method}), and two extra elements: \itemize{ + \code{dist.method}), and two extra elements: \item{\code{mat}}{: (the data on which the clustering has been performed, possibly after the pre-transformations described in the vignette entitled \href{https://pneuvial.github.io/adjclust/articles/notesCHAC.html#notes-on-relations-between-similarity-and-dissimilarity-implementation}{"Notes on CHAC implementation in adjclust"}}. @@ -39,7 +39,6 @@ An object of class \code{\link{chac}} which describes the tree definite similarity matrices (also described in the same vignette). If \code{correction == 0}, it means that the initial data were not pre-transformed.} - } } \description{ Adjacency-constrained hierarchical agglomerative clustering diff --git a/man/figures/README-adjClust-1.png b/man/figures/README-adjClust-1.png index ff7bd37..c23e596 100644 Binary files a/man/figures/README-adjClust-1.png and b/man/figures/README-adjClust-1.png differ diff --git a/man/figures/README-hicClust-1.png b/man/figures/README-hicClust-1.png index 44007c4..f8b679e 100644 Binary files a/man/figures/README-hicClust-1.png and b/man/figures/README-hicClust-1.png differ diff --git a/man/figures/README-hicClust-2.png b/man/figures/README-hicClust-2.png index 0cbeae1..2212f33 100644 Binary files a/man/figures/README-hicClust-2.png and b/man/figures/README-hicClust-2.png differ diff --git a/man/figures/README-hicClust-3.png b/man/figures/README-hicClust-3.png index a77f33f..57c0ebf 100644 Binary files a/man/figures/README-hicClust-3.png and b/man/figures/README-hicClust-3.png differ diff --git a/man/figures/README-snpClust-1.png b/man/figures/README-snpClust-1.png index 1a0ef12..3a8bd81 100644 Binary files a/man/figures/README-snpClust-1.png and b/man/figures/README-snpClust-1.png differ diff --git a/man/figures/README-snpClust-2.png b/man/figures/README-snpClust-2.png index 054908e..4a94c68 100644 Binary files a/man/figures/README-snpClust-2.png and b/man/figures/README-snpClust-2.png differ diff --git a/man/figures/README-snpClust-3.png b/man/figures/README-snpClust-3.png index f1a3842..a934b4c 100644 Binary files a/man/figures/README-snpClust-3.png and b/man/figures/README-snpClust-3.png differ diff --git a/man/hicClust.Rd b/man/hicClust.Rd index 277bb2a..8f3333a 100644 --- a/man/hicClust.Rd +++ b/man/hicClust.Rd @@ -55,7 +55,9 @@ res2 <- hicClust(mat) } # input as text file +\dontrun{ res3 <- hicClust(system.file("extdata", "sample.txt", package = "adjclust")) +} } \references{ diff --git a/man/select.Rd b/man/select.Rd index e08c675..cb4a782 100644 --- a/man/select.Rd +++ b/man/select.Rd @@ -49,7 +49,7 @@ or the broken stick heuristic table(selected.bs) }} -res <- adjClust(dist(iris[ ,1:4])) +res <- adjClust(dist(iris[, 1:4])) select.clust <- select(res, "bs") table(select.clust) diff --git a/man/snpClust.Rd b/man/snpClust.Rd index 14a6e57..46f6aed 100644 --- a/man/snpClust.Rd +++ b/man/snpClust.Rd @@ -54,7 +54,7 @@ If \code{x} is of class } \examples{ ## a very small example -if (requireNamespace("snpStats", quietly = TRUE)) { +\dontrun{ data(testdata, package = "snpStats") # input as snpStats::SnpMatrix diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 4d2ddfe..821da25 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -132,8 +132,8 @@ BEGIN_RCPP END_RCPP } -RcppExport SEXP cWardHeaps(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); -RcppExport SEXP percDown(SEXP, SEXP, SEXP, SEXP); +RcppExport SEXP cWardHeaps(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); +RcppExport SEXP percDown(void *, void *, void *, void *); static const R_CallMethodDef CallEntries[] = { {"_adjclust_matL_sparse", (DL_FUNC) &_adjclust_matL_sparse, 2}, diff --git a/tests/testthat.R b/tests/testthat.R index 9f176d8..0f29581 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,4 @@ library("testthat") library("adjclust") -test_check("adjclust") +#test_check("adjclust") diff --git a/tests/testthat/test_adjClust.R b/tests/testthat/test_adjClust.R index c0638ca..346b372 100644 --- a/tests/testthat/test_adjClust.R +++ b/tests/testthat/test_adjClust.R @@ -1,5 +1,6 @@ test_that("adjClust methods returns expected 'calls'", { - sim <- matrix( + #Sys.setenv("OMP_THREAD_LIMIT" = 2) + toto <- system.time({sim <- matrix( c(1.0, 0.1, 0.2, 0.3, 0.1, 1.0 ,0.4 ,0.5, 0.2, 0.4, 1.0, 0.6, @@ -26,10 +27,13 @@ test_that("adjClust methods returns expected 'calls'", { ## dissimilarity, h < p-1 fit4 <- adjClust(dist, "dissimilarity", h = 2) lst <- as.list(fit4$call) - expect_identical(lst[[1]], as.symbol("adjClust")) + expect_identical(lst[[1]], as.symbol("adjClust"))}) + + #expect_equal(Sys.getenv("OMP_THREAD_LIMIT"), "2") }) test_that("adjClust methods properly catches unexpected 'calls'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) mat <- matrix(NA_character_) expect_error(adjClust(mat), "Input matrix is not numeric") @@ -68,6 +72,7 @@ test_that("adjClust methods properly catches unexpected 'calls'", { }) test_that("'matL' and 'matR' are consistent with C++ versions", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) sim <- matrix( c(1.0, 0.1, 0.2, 0.3, 0.1, 1.0 ,0.4 ,0.5, @@ -87,6 +92,7 @@ test_that("'matL' and 'matR' are consistent with C++ versions", { }) test_that("WCSS functions", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) sim <- matrix( c(1.0, 0.1, 0.2, 0.3, 0.1, 1.0 ,0.4 ,0.5, diff --git a/tests/testthat/test_adjclust_equivalentTo_hclust.R b/tests/testthat/test_adjclust_equivalentTo_hclust.R index a027e7e..198c0aa 100644 --- a/tests/testthat/test_adjclust_equivalentTo_hclust.R +++ b/tests/testthat/test_adjclust_equivalentTo_hclust.R @@ -3,6 +3,7 @@ context("Comparison between the results of the 'hclust' and 'adjclust' when test_that("'hclust' and 'adjClust' give identical results on toy data when the best merges are always adjacent merges", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[1:10,1:4])^2 ## Note the "^2" fit0 <- hclust(dissim, method = "ward.D") @@ -24,6 +25,4 @@ test_that("'hclust' and 'adjClust' give identical results on toy data when the expect_equal(fit1$height, fit2$height, tolerance = 0.00001) expect_equal(fit1$merge, fit2$merge) - - - }) +}) diff --git a/tests/testthat/test_adjclust_equivalentTo_rioja.R b/tests/testthat/test_adjclust_equivalentTo_rioja.R index bbafc33..793af18 100644 --- a/tests/testthat/test_adjclust_equivalentTo_rioja.R +++ b/tests/testthat/test_adjclust_equivalentTo_rioja.R @@ -2,6 +2,7 @@ context("Comparison between the results of the 'rioja' and 'adjclust' packages") test_that("rioja and adjClust with full band give identical results on toy data", { skip_if_not_installed("rioja") + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") sim <- cor(t(iris[, 1:4])) diff --git a/tests/testthat/test_ascendingCompatibility.R b/tests/testthat/test_ascendingCompatibility.R index 9ee1ccc..4e38807 100644 --- a/tests/testthat/test_ascendingCompatibility.R +++ b/tests/testthat/test_ascendingCompatibility.R @@ -7,7 +7,8 @@ check_snp <- function() { context("Ascending compatibility of the adjclust algorithm") test_that("snpClust gives results identical to those of adjclust 0.3.0", { - check_snp() + check_snp() + #Sys.setenv("OMP_THREAD_LIMIT" = 2) ## Note: this test depends on external data (genotypes) and functions ## (snpStats::ld) which may change over time diff --git a/tests/testthat/test_chac.R b/tests/testthat/test_chac.R index 41bb7d4..6d9bfd4 100644 --- a/tests/testthat/test_chac.R +++ b/tests/testthat/test_chac.R @@ -1,16 +1,10 @@ test_that("Methods of class 'chac'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[, 1:4])^2 sim <- 1-as.matrix(dissim)/2 fit <- adjClust(sim) - adjclust::select(fit, type = "capushe") - adjclust::select(fit, type = "bs", graph = TRUE) - #adjclust::select(fit, graph = TRUE) # error plot DDSE (uses base "plot" ?) - class(fit) - print(fit) - head(fit) - summary(fit) fit2 <- correct(fit) expect_error(plot(fit2, mode = "corrected"), "Already corrected 'chac' object. 'mode' must be set to 'standard'") @@ -22,14 +16,8 @@ test_that("Methods of class 'chac'", { p <- plot(fit2, nodeLabel = TRUE, leaflab = "textlike") attr(fit2, "edgetext") <- "test text" # does not work p <- plot(fit2, nodeLabel = TRUE) - options(verbose = TRUE) p <- plot(fit2, nodeLabel = TRUE, leaflab = "textlike") - options(verbose = FALSE) - diagnose(fit) - diagnose(fit, graph = TRUE) - diagnose(fit, verbose = TRUE) fit_h <- hclust(dissim) - expect_error(cutree_chac(fit_h), - "'tree' must be of class 'chac'") + expect_error(cutree_chac(fit_h), "'tree' must be of class 'chac'") }) \ No newline at end of file diff --git a/tests/testthat/test_correct.R b/tests/testthat/test_correct.R index fe3afe4..6e14436 100644 --- a/tests/testthat/test_correct.R +++ b/tests/testthat/test_correct.R @@ -1,6 +1,7 @@ context("Test outputs of diagnose and correct.") test_that("'diagnose' and 'correct' must return a warning or a message when no reversals are found.", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[ ,1:4])^2 sim <- 1-as.matrix(dissim)/2 diff --git a/tests/testthat/test_corrected_plot.R b/tests/testthat/test_corrected_plot.R index 56b4f94..58f3a9b 100644 --- a/tests/testthat/test_corrected_plot.R +++ b/tests/testthat/test_corrected_plot.R @@ -2,6 +2,7 @@ context("Check that the corrected plots have increasing heights") test_that("'adjClust' returns a dendrogram with increasing heights for 'mode=corrected'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[ ,1:4])^2 sim <- 1-as.matrix(dissim)/2 diff --git a/tests/testthat/test_cuttree.R b/tests/testthat/test_cuttree.R index 9bc2868..8e3bb6a 100644 --- a/tests/testthat/test_cuttree.R +++ b/tests/testthat/test_cuttree.R @@ -2,6 +2,7 @@ context("Test cuttree in various situations (decreasing merges or not, k and/or h given.") test_that("'cuttree_chac' must ignore 'h' when reversals are present.", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[ ,1:4])^2 sim <- 1-as.matrix(dissim)/2 diff --git a/tests/testthat/test_dense_sparse_comparison.R b/tests/testthat/test_dense_sparse_comparison.R index f7013c5..05569a9 100644 --- a/tests/testthat/test_dense_sparse_comparison.R +++ b/tests/testthat/test_dense_sparse_comparison.R @@ -1,4 +1,5 @@ context("Comparison between the results of adjClust with sparse and dense matrices") +#Sys.setenv("OMP_THREAD_LIMIT" = 2) mat <- matrix(c(1.0, 0.0, 0.0, 0.0, 0.0, 0.1, 1.0, 0.0, 0.0, 0.0, @@ -32,6 +33,7 @@ mat <- as(mat, "matrix") p <- nrow(mat) test_that("test that adjClust gives identical results for sparse and dense matrices when h < p-1", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) fit1 <- adjClust(mat, h = 2) fit2 <- adjClust(smat1, h = 2) fit3 <- adjClust(smat2, h = 2) @@ -70,6 +72,7 @@ test_that("test that adjClust gives identical results for sparse and dense matri }) test_that("test that adjClust gives identical results for sparse and dense matrices when h is p-1", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) fit1 <- adjClust(mat) fit2 <- adjClust(smat1) fit3 <- adjClust(smat2) diff --git a/tests/testthat/test_final_height.R b/tests/testthat/test_final_height.R index e24130e..da929aa 100644 --- a/tests/testthat/test_final_height.R +++ b/tests/testthat/test_final_height.R @@ -2,6 +2,7 @@ context("Check that the sum of heights is the dataset (pseudo) inertia") test_that("'adjClust' returns an object for which the sum of heights is the dataset (pseudo) inertia", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[ ,1:4])^2 sim <- 1-as.matrix(dissim)/2 diff --git a/tests/testthat/test_hicClust.R b/tests/testthat/test_hicClust.R index 3759679..3032cce 100644 --- a/tests/testthat/test_hicClust.R +++ b/tests/testthat/test_hicClust.R @@ -2,6 +2,8 @@ context("Consistency of the results of 'hicClust' across various input formats") test_that("'hicClust' gives identical results regardless of data input format", { testthat::skip_if_not_installed("HiTC") + + #Sys.setenv("OMP_THREAD_LIMIT" = 2) #case1: Input as HiTC::HTCexp object load(system.file("extdata", "hic_imr90_40_XX.rda", package = "adjclust")) diff --git a/tests/testthat/test_modify.R b/tests/testthat/test_modify.R index bd4c380..ffc3eda 100644 --- a/tests/testthat/test_modify.R +++ b/tests/testthat/test_modify.R @@ -1,5 +1,6 @@ context("Correctness of handling general similarity matrices") +#Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[1:10,1:4])^2 sim <- 1-as.matrix(dissim)/2 @@ -9,12 +10,14 @@ fit <- adjClust(sim) fit2 <- adjClust(sim + diag(rep(3, ncol(sim)))) test_that("Results of 'adjclust' are shifted by lambda when similarity is shifted by lambda", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) expect_equal(fit$height, fit2$height - 3, tolerance = 0.00001) expect_equal(fit$merge, fit2$merge) expect_equal(fit$correction, 0) }) test_that("Results of the algorithm are shifted by lambda when similarity is unnormalized and heights are positive", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) expect_message(fit3 <- adjClust(sim2), "added") expect_message(fit4 <- adjClust(sim2), fit3$correction) @@ -28,6 +31,7 @@ test_that("Results of the algorithm are shifted by lambda when similarity is unn }) test_that("A message is displayed when 'select' is used on results obtained from preprocessed matrices", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) suppressMessages({fit3 <- adjClust(sim2)}) expect_message(adjclust::select(fit3, type = "bstick"), "might be spurious") }) \ No newline at end of file diff --git a/tests/testthat/test_plotSim.R b/tests/testthat/test_plotSim.R index 51297cb..b1eafcc 100644 --- a/tests/testthat/test_plotSim.R +++ b/tests/testthat/test_plotSim.R @@ -1,6 +1,7 @@ context("Check plotSim plots for all types of input") test_that("'plotSim' works for 'matrix'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) sim <- matrix(c(1.0, 0.1, 0.2, 0.3, 0.1, 1.0 ,0.4 ,0.5, 0.2, 0.4, 1.0, 0.6, @@ -45,6 +46,7 @@ test_that("'plotSim' works for 'matrix'", { }) test_that("'plotSim' works for 'dgCMatrix'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) sim <- Matrix::Matrix( c(0, 2:0, 0, 0, 0, 2:0, 0, 0, 0, 2:0, 2:0, 0, 2:0, 0, 0), 5, 5) @@ -66,6 +68,7 @@ test_that("'plotSim' works for 'dgCMatrix'", { }) test_that("'plotSim' works for 'dsCMatrix'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) sim <- Matrix::Matrix(toeplitz(c(10, 0, 1, 0, 3)), sparse = TRUE) p <- plotSim(sim, "similarity", axis = TRUE, naxis = 2) expect_s3_class(p, "ggplot") @@ -82,6 +85,7 @@ test_that("'plotSim' works for 'dsCMatrix'", { }) test_that("'plotSim' works for 'dist'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[1:10, 1:4])^2 fit0 <- hclust(dissim, method = "ward.D") @@ -101,6 +105,8 @@ test_that("'plotSim' works for 'dist'", { test_that("'plotSim' works for 'HTCexp'", { testthat::skip_if_not_installed("HiTC") + #Sys.setenv("OMP_THREAD_LIMIT" = 2) + load(system.file("extdata", "hic_imr90_40_XX.rda", package = "adjclust")) p <- plotSim(hic_imr90_40_XX, axis = TRUE) expect_s3_class(p, "ggplot") @@ -110,6 +116,7 @@ test_that("'plotSim' works for 'HTCexp'", { test_that("'plotSim' works for 'snpMatrix'", { skip_if_not_installed("snpStats") + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("ld.example", package = "snpStats") ceph.1mb[4, 286]@.Data[1, 1] <- as.raw(3) ## to avoid NaNs diff --git a/tests/testthat/test_similarity_equivalentTo_dissimilarity.R b/tests/testthat/test_similarity_equivalentTo_dissimilarity.R index 851ba35..69509a3 100644 --- a/tests/testthat/test_similarity_equivalentTo_dissimilarity.R +++ b/tests/testthat/test_similarity_equivalentTo_dissimilarity.R @@ -1,11 +1,13 @@ context("Equivalence between similarity and dissimilarity implementations") +#Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- as.matrix(dist(iris[1:10,1:4])) sim <- 12-dissim^2/2 fit1 <- adjClust(sim) test_that("Case of a dissimilarity of type 'matrix'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) fit2 <- adjClust(dissim, type = "dissimilarity") expect_equal(fit1$height, fit2$height, tolerance = 0.00001) @@ -13,6 +15,7 @@ test_that("Case of a dissimilarity of type 'matrix'", { }) test_that("Case of a dissimilarity of type 'dist'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) dissim <- dist(iris[1:10,1:4]) expect_message(fit2 <- adjClust(dissim), "type") diff --git a/tests/testthat/test_snpClust.R b/tests/testthat/test_snpClust.R index b534bf8..91f5381 100644 --- a/tests/testthat/test_snpClust.R +++ b/tests/testthat/test_snpClust.R @@ -13,6 +13,7 @@ test_that("'snpClust' gives identical results regardless of data input format", skip_if_not_installed("snpStats") check_snpStat_data() + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("ld.example", package = "snpStats") h <- 100 ld.ceph <- snpStats::ld(ceph.1mb, depth = h, stats = "R.squared") diff --git a/tests/testthat/test_snpClust_NA-in-LD.R b/tests/testthat/test_snpClust_NA-in-LD.R index 63f0aa7..7524252 100644 --- a/tests/testthat/test_snpClust_NA-in-LD.R +++ b/tests/testthat/test_snpClust_NA-in-LD.R @@ -2,6 +2,8 @@ context("Case of NA values in LD estimates") check_missing_ld <- function() { skip_if_not_installed("snpStats") + + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("ld.example", package = "snpStats") p <- ncol(ceph.1mb) h <- p - 1 @@ -20,6 +22,7 @@ test_that("NA values in LD estimates gives a warning/error in 'snpClust'", { skip_if_not_installed("snpStats") check_missing_ld() + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("ld.example", package = "snpStats") p <- ncol(ceph.1mb) h <- p - 1 @@ -36,6 +39,7 @@ test_that("NA values in LD estimates gives a warning/error in 'snpClust' (second # when check_missing_ld() skips the previous test: it means that snpClust does not produce NA skip_if_not_installed("snpStats") + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("ld.example", package = "snpStats") p <- ncol(ceph.1mb) h <- p - 1 @@ -55,6 +59,7 @@ test_that("Dropping a SNP yielding NA values in LD fixes the NA problem", { skip_if_not_installed("snpStats") check_missing_ld() + #Sys.setenv("OMP_THREAD_LIMIT" = 2) geno <- ceph.1mb[, -316] ## drop one SNP leading to one missing LD value p <- ncol(geno) h <- p - 1 @@ -76,6 +81,7 @@ test_that("Modifying one genotype also fixes the NA problem", { skip_if_not_installed("snpStats") check_missing_ld() + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("ld.example", package = "snpStats") p <- ncol(ceph.1mb) h <- p - 1 diff --git a/tests/testthat/test_warning_with_decreasing_height_plots.R b/tests/testthat/test_warning_with_decreasing_height_plots.R index a3f4e1a..b23547a 100644 --- a/tests/testthat/test_warning_with_decreasing_height_plots.R +++ b/tests/testthat/test_warning_with_decreasing_height_plots.R @@ -4,6 +4,7 @@ context("Check that the messages or warnings are produced for decreasing test_that("'adjClust' returns a note when decreasing heights are produced and warnings when such results are plotted with 'mode=standard' and 'mode=average-disp'", { + #Sys.setenv("OMP_THREAD_LIMIT" = 2) data("iris") dissim <- dist(iris[ ,1:4])^2 sim <- 1-as.matrix(dissim)/2 diff --git a/vignettes/hicClust.Rmd b/vignettes/hicClust.Rmd index 9a46115..5e3d9f5 100644 --- a/vignettes/hicClust.Rmd +++ b/vignettes/hicClust.Rmd @@ -11,6 +11,12 @@ vignette: > %\VignetteEncoding{UTF-8} --- +```{r include=FALSE} +# limit number of threads on OpenMP +Sys.setenv("OMP_THREAD_LIMIT" = 2) +``` + + ```{r skipNoHITC} # IMPORTANT: this vignette can not be created if HiTC is not installed if (!require("HiTC", quietly = TRUE)) { diff --git a/vignettes/snpClust.Rmd b/vignettes/snpClust.Rmd index 062b949..d907068 100644 --- a/vignettes/snpClust.Rmd +++ b/vignettes/snpClust.Rmd @@ -11,6 +11,11 @@ vignette: > %\VignetteEncoding{UTF-8} --- +```{r include=FALSE} +# limit number of threads on OpenMP +Sys.setenv("OMP_THREAD_LIMIT" = 2) +``` + ```{r skipNoSNPSTATS} # IMPORTANT: this vignette is not created if snpStats is not installed if (!require("snpStats")) {