Skip to content

Commit 99cd40f

Browse files
authored
Merge pull request #80 from pneuvial/develop
version 0.6.9
2 parents 998d52d + 0463617 commit 99cd40f

36 files changed

+138
-304
lines changed

DESCRIPTION

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
Package: adjclust
22
Maintainer: Pierre Neuvial <[email protected]>
3-
Authors@R: c(person("Christophe", "Ambroise", role="aut"),
4-
person("Shubham", "Chaturvedi", role="aut"),
5-
person("Alia", "Dehman", role="aut"),
6-
person("Pierre", "Neuvial", role=c("aut", "cre"),
7-
8-
person("Guillem", "Rigaill", role="aut"),
9-
person("Nathalie", "Vialaneix", role="aut"),
10-
person("Gabriel", "Hoffman", role="aut"))
11-
Date: 2024-01-10
12-
Version: 0.6.8
3+
Authors@R: c(person("Christophe", "Ambroise", role = "aut"),
4+
person("Shubham", "Chaturvedi", role = "aut"),
5+
person("Alia", "Dehman", role = "aut"),
6+
person("Pierre", "Neuvial", role = c("aut", "cre"),
7+
email = "[email protected]",
8+
comment = c(ORCID = "0000-0003-3584-9998")),
9+
person("Guillem", "Rigaill", role = "aut"),
10+
person("Nathalie", "Vialaneix", role = "aut",
11+
email = "[email protected]",
12+
comment = c(ORCID = "0000-0003-1156-0639")),
13+
person("Gabriel", "Hoffman", role = "aut"))
14+
Date: 2024-02-07
15+
Version: 0.6.9
1316
License: GPL-3
1417
Title: Adjacency-Constrained Clustering of a Block-Diagonal Similarity Matrix
1518
Description: Implements a constrained version of hierarchical agglomerative
@@ -48,7 +51,7 @@ biocViews:
4851
VignetteBuilder: knitr
4952
URL: https://pneuvial.github.io/adjclust/
5053
BugReports: https://github.com/pneuvial/adjclust/issues
51-
RoxygenNote: 7.2.3
54+
RoxygenNote: 7.3.1
5255
LinkingTo:
5356
Rcpp,
5457
RcppArmadillo

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Version 0.6.9 [2024-02-07]
2+
3+
* Properly handled OMP threads in C++ code (now default to 1 but with an option
4+
to increase this value)
5+
* Reintroduced tests and examples
6+
* Removed WCSS function that was not exported or documented
7+
* Fixed a problem in S3class for a non exported function
8+
19
# Version 0.6.8 [2024-01-10]
210

311
* Fix CRAN error on useNames (deprecated NA)

R/RcppExports.R

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ matL_full <- function(Csq, h) {
99
.Call(`_adjclust_matL_full`, Csq, h)
1010
}
1111

12-
matL_sparse_rowCumsums <- function(Csq, h) {
13-
.Call(`_adjclust_matL_sparse_rowCumsums`, Csq, h)
12+
matL_sparse_rowCumsums <- function(Csq, h, nthreads) {
13+
.Call(`_adjclust_matL_sparse_rowCumsums`, Csq, h, nthreads)
1414
}
1515

16-
matL_full_rowCumsums <- function(Csq, h) {
17-
.Call(`_adjclust_matL_full_rowCumsums`, Csq, h)
16+
matL_full_rowCumsums <- function(Csq, h, nthreads) {
17+
.Call(`_adjclust_matL_full_rowCumsums`, Csq, h, nthreads)
1818
}
1919

2020
matR_sparse <- function(Csq, h) {
@@ -25,19 +25,11 @@ matR_full <- function(Csq, h) {
2525
.Call(`_adjclust_matR_full`, Csq, h)
2626
}
2727

28-
matR_sparse_rowCumsums <- function(Csq, h) {
29-
.Call(`_adjclust_matR_sparse_rowCumsums`, Csq, h)
28+
matR_sparse_rowCumsums <- function(Csq, h, nthreads) {
29+
.Call(`_adjclust_matR_sparse_rowCumsums`, Csq, h, nthreads)
3030
}
3131

32-
matR_full_rowCumsums <- function(Csq, h) {
33-
.Call(`_adjclust_matR_full_rowCumsums`, Csq, h)
34-
}
35-
36-
wcss_single <- function(C, cluster) {
37-
.Call(`_adjclust_wcss_single`, C, cluster)
38-
}
39-
40-
WCSS <- function(C, clusterMat) {
41-
.Call(`_adjclust_WCSS`, C, clusterMat)
32+
matR_full_rowCumsums <- function(Csq, h, nthreads) {
33+
.Call(`_adjclust_matR_full_rowCumsums`, Csq, h, nthreads)
4234
}
4335

R/adjclust.R

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ NULL
1616
#' band of width \code{h}). The method is fully described in (Dehman, 2015) and
1717
#' based on a kernel version of the algorithm. The different options for the
1818
#' implementation are available in the package vignette entitled
19-
#' \href{https://pneuvial.github.io/adjclust/articles/notesCHAC.html}{"Notes on CHAC implementation in adjclust}.
19+
#' \href{https://pneuvial.github.io/adjclust/articles/notesCHAC.html}{"Notes on CHAC implementation in adjclust"}.
2020
#'
2121
#' @param mat A similarity matrix or a dist object. Most sparse formats from
2222
#' \code{\link[Matrix]{sparseMatrix}} are allowed
@@ -28,6 +28,8 @@ NULL
2828
#' @param strictCheck Logical (default to \code{TRUE}) to systematically check
2929
#' default of positivity in input similarities. Can be disabled to avoid
3030
#' computationally expensive checks when the number of features is large.
31+
#' @param nthreads Integer (default to \code{1L}). Number of threads use for
32+
#' matrix precomputations.
3133
#'
3234
#' @returns An object of class \code{\link{chac}} which describes the tree
3335
#' produced by the clustering process. The object is a list with the same
@@ -82,10 +84,11 @@ NULL
8284
#'
8385
#' @examples
8486
#' sim <- matrix(
85-
#' c(1.0, 0.1, 0.2, 0.3,
86-
#' 0.1, 1.0 ,0.4 ,0.5,
87-
#' 0.2, 0.4, 1.0, 0.6,
88-
#' 0.3, 0.5, 0.6, 1.0), nrow = 4)
87+
#' c(1.0, 0.1, 0.2, 0.3,
88+
#' 0.1, 1.0 ,0.4 ,0.5,
89+
#' 0.2, 0.4, 1.0, 0.6,
90+
#' 0.3, 0.5, 0.6, 1.0),
91+
#' nrow = 4)
8992
#'
9093
#' ## similarity, full width
9194
#' fit1 <- adjClust(sim, "similarity")
@@ -112,112 +115,124 @@ NULL
112115
#' @importFrom Matrix diag
113116
#' @importFrom Matrix t
114117
adjClust <- function(mat, type = c("similarity", "dissimilarity"),
115-
h = ncol(mat) - 1, strictCheck=TRUE) {
118+
h = ncol(mat) - 1, strictCheck = TRUE, nthreads = 1L) {
116119
UseMethod("adjClust")
117120
}
118121

119122
#' @importFrom Matrix isSymmetric forceSymmetric
120123
#' @export
121124
adjClust.matrix <- function(mat, type = c("similarity", "dissimilarity"),
122-
h = ncol(mat) - 1, strictCheck = TRUE) {
125+
h = ncol(mat) - 1, strictCheck = TRUE,
126+
nthreads = 1L) {
123127
if (!is.numeric(mat))
124128
stop("Input matrix is not numeric")
125129
if (!(isSymmetric(mat)))
126130
stop("Input matrix is not symmetric")
127-
res <- run.adjclust(mat, type = type, h = h, strictCheck = strictCheck)
131+
res <- run.adjclust(mat, type = type, h = h, strictCheck = strictCheck,
132+
nthreads = nthreads)
128133
x <- sys.call()
129134
res$call <- update_call(x, "adjClust")
130135
return(res)
131136
}
132137

133138
#' @export
134139
adjClust.dsyMatrix <- function(mat, type = c("similarity", "dissimilarity"),
135-
h = ncol(mat) - 1, strictCheck = TRUE) {
140+
h = ncol(mat) - 1, strictCheck = TRUE,
141+
nthreads = 1L) {
136142
# RcppArmadillo functions don't support dsyMatrix, so convert to matrix
137143
res <- run.adjclust(as.matrix(mat), type = type, h = h,
138-
strictCheck = strictCheck)
144+
strictCheck = strictCheck, nthreads = nthreads)
139145
x <- sys.call()
140146
res$call <- update_call(x, "adjClust")
141147
return(res)
142148
}
143149

144150
#' @export
145151
adjClust.dgeMatrix <- function(mat, type = c("similarity", "dissimilarity"),
146-
h = ncol(mat) - 1, strictCheck = TRUE) {
152+
h = ncol(mat) - 1, strictCheck = TRUE,
153+
nthreads = 1L) {
147154
type <- match.arg(type)
148155
if (!(isSymmetric(mat))) {
149156
stop("Input matrix is not symmetric")
150-
} else {
151-
mat <- forceSymmetric(mat)
152-
}
153-
res <- adjClust(mat, type = type, h = h, strictCheck = strictCheck)
157+
} else mat <- forceSymmetric(mat)
158+
res <- adjClust(mat, type = type, h = h, strictCheck = strictCheck,
159+
nthreads = nthreads)
154160
x <- sys.call()
155161
res$call <- update_call(x, "adjClust")
156162
return(res)
157163
}
158164

159165
#' @export
160166
adjClust.dsCMatrix <- function(mat, type = c("similarity", "dissimilarity"),
161-
h = ncol(mat) - 1, strictCheck = TRUE) {
167+
h = ncol(mat) - 1, strictCheck = TRUE,
168+
nthreads = 1L) {
162169
type <- match.arg(type)
163170
if (type == "dissimilarity")
164171
stop("'type' can only be 'similarity' with sparse Matrix inputs")
165-
res <- run.adjclust(mat, type = type, h = h, strictCheck = strictCheck)
172+
res <- run.adjclust(mat, type = type, h = h, strictCheck = strictCheck,
173+
nthreads = nthreads)
166174
x <- sys.call()
167175
res$call <- update_call(x, "adjClust")
168176
return(res)
169177
}
170178

171179
#' @export
172180
adjClust.dgCMatrix <- function(mat, type = c("similarity", "dissimilarity"),
173-
h = ncol(mat) - 1, strictCheck = TRUE) {
181+
h = ncol(mat) - 1, strictCheck = TRUE,
182+
nthreads = 1L) {
174183
if (!(isSymmetric(mat))) {
175184
stop("Input matrix is not symmetric")
176185
} else {
177186
mat <- forceSymmetric(mat)
178187
}
179-
res <- adjClust(mat, type = type, h = h, strictCheck = strictCheck)
188+
res <- adjClust(mat, type = type, h = h, strictCheck = strictCheck,
189+
nthreads = nthreads)
180190
x <- sys.call()
181191
res$call <- update_call(x, "adjClust")
182192
return(res)
183193
}
184194

185195
#' @export
186196
adjClust.dsTMatrix <- function(mat, type = c("similarity", "dissimilarity"),
187-
h = ncol(mat) - 1, strictCheck = TRUE) {
197+
h = ncol(mat) - 1, strictCheck = TRUE,
198+
nthreads = 1L) {
188199
type <- match.arg(type)
189200
if (type == "dissimilarity")
190201
stop("'type' can only be 'similarity' with sparse Matrix inputs")
191-
res <- run.adjclust(mat, type = type, h = h, strictCheck = strictCheck)
202+
res <- run.adjclust(mat, type = type, h = h, strictCheck = strictCheck,
203+
nthreads = nthreads)
192204
x <- sys.call()
193205
res$call <- update_call(x, "adjClust")
194206
return(res)
195207
}
196208

197209
#' @export
198210
adjClust.dgTMatrix <- function(mat, type = c("similarity", "dissimilarity"),
199-
h = ncol(mat) - 1, strictCheck = TRUE) {
211+
h = ncol(mat) - 1, strictCheck = TRUE,
212+
nthreads = 1L) {
200213
type <- match.arg(type)
201214
if (!(isSymmetric(mat))) {
202215
stop("Input matrix is not symmetric")
203216
} else {
204217
mat <- forceSymmetric(mat)
205218
}
206-
res <- adjClust(mat, type = type, h = h, strictCheck = strictCheck)
219+
res <- adjClust(mat, type = type, h = h, strictCheck = strictCheck,
220+
nthreads = nthreads)
207221
x <- sys.call()
208222
res$call <- update_call(x, "adjClust")
209223
return(res)
210224
}
211225

212226
#' @export
213227
adjClust.dist <- function(mat, type = c("similarity", "dissimilarity"),
214-
h = ncol(mat) - 1, strictCheck = TRUE) {
228+
h = ncol(mat) - 1, strictCheck = TRUE,
229+
nthreads = 1L) {
215230
type <- match.arg(type)
216231
if (type != "dissimilarity")
217232
message("Note: input class is 'dist' so 'type' is supposed to be 'dissimilarity'")
218233
mat <- as.matrix(mat)
219234
res <- adjClust.matrix(mat, type = "dissimilarity", h = h,
220-
strictCheck = strictCheck)
235+
strictCheck = strictCheck, nthreads = nthreads)
221236
x <- sys.call()
222237
res$call <- update_call(x, "adjClust")
223238
return(res)
@@ -226,7 +241,7 @@ adjClust.dist <- function(mat, type = c("similarity", "dissimilarity"),
226241
#' @importFrom methods is
227242
#' @import Rcpp
228243
run.adjclust <- function(mat, type = c("similarity", "dissimilarity"), h,
229-
strictCheck = TRUE) {
244+
strictCheck = TRUE, nthreads = 1L) {
230245
# sanity checks
231246
type <- match.arg(type)
232247
if (any(is.na(mat)))
@@ -261,24 +276,24 @@ run.adjclust <- function(mat, type = c("similarity", "dissimilarity"), h,
261276

262277
if (is(mat, "sparseMatrix")) {
263278
# left
264-
rCumL <- matL_sparse_rowCumsums(mat, h)
279+
rCumL <- matL_sparse_rowCumsums(mat, h, nthreads = nthreads)
265280
rcCumL <- colCumsums(rCumL, useNames = FALSE) # p x (h+1) matrix
266281
rm(rCumL)
267282

268283
# right
269-
rCumR <- matR_sparse_rowCumsums(mat, h)
284+
rCumR <- matR_sparse_rowCumsums(mat, h, nthreads = nthreads)
270285
rcCumR <- colCumsums(rCumR, useNames = FALSE) # p x (h+1) matrix
271286
rm(rCumR)
272287

273288
out_matL <- matL_sparse(mat, 2)
274289
} else {
275290
# left
276-
rCumL <- matL_full_rowCumsums(mat, h)
291+
rCumL <- matL_full_rowCumsums(mat, h, nthreads = nthreads)
277292
rcCumL <- colCumsums(rCumL, useNames = FALSE) # p x (h+1) matrix
278293
rm(rCumL)
279294

280295
# right
281-
rCumR <- matR_full_rowCumsums(mat, h)
296+
rCumR <- matR_full_rowCumsums(mat, h, nthreads = nthreads)
282297
rcCumR <- colCumsums(rCumR, useNames = FALSE) # p x (h+1) matrix
283298
rm(rCumR)
284299

R/hicClust.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656
#' }
5757
#'
5858
#' # input as text file
59-
#' \dontrun{
6059
#' res3 <- hicClust(system.file("extdata", "sample.txt", package = "adjclust"))
61-
#' }
6260
#'
6361
#' @export
6462
#'

R/plotSim.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ plotSim.default <- function(mat, type = c("similarity", "dissimilarity"),
303303
# Coordinate computation ####
304304
if (type == "dissimilarity") mat <- max(mat) - mat
305305

306-
coordinates <- poly_coords(mat)
306+
if (inherits(mat, "dsCMatrix")) {
307+
poly_coords_fun <- poly_coords_dsCMatrix
308+
} else poly_coords_fun <- poly_coords_default
309+
coordinates <- poly_coords_fun(mat)
307310
fake_coords <- make_coords(c(1, d, d), c(1, d, 1), rep(0, 3))
308311

309312

@@ -463,11 +466,7 @@ poly_coords_sparse <- function(mat) {
463466
return(coords)
464467
}
465468

466-
poly_coords <- function(mat) {
467-
UseMethod("poly_coords")
468-
}
469-
470-
poly_coords.default <- function(mat) {
469+
poly_coords_default <- function(mat) {
471470
# extracting coordinates in the matrix (genomic) and IF
472471
p <- ncol(mat)
473472
indi <- row(mat)
@@ -481,7 +480,7 @@ poly_coords.default <- function(mat) {
481480
return(coords)
482481
}
483482

484-
poly_coords.dsCMatrix <- function(mat) {
483+
poly_coords_dsCMatrix <- function(mat) {
485484
p <- ncol(mat)
486485
mat <- as(mat, "TsparseMatrix")
487486
coords <- poly_coords_sparse(mat)

R/snpClust.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#'
6262
#' @examples
6363
#' ## a very small example
64-
#' \dontrun{
64+
#' if (requireNamespace("snpStats", quietly = TRUE)) {
6565
#' data(testdata, package = "snpStats")
6666
#'
6767
#' # input as snpStats::SnpMatrix

R/zzzz.R

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)