Skip to content

Commit 5665b79

Browse files
committed
test
1 parent 1add3e1 commit 5665b79

File tree

8 files changed

+50
-42
lines changed

8 files changed

+50
-42
lines changed

R/bbknn.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bbknnIntegration <- function(
203203
Matrix::t(x = scaled.mat)
204204
),
205205
obs = reticulate::r_to_py(x = groups[, groups.name, drop = FALSE]),
206-
var = reticulate::r_to_py(x = features)
206+
var = r_to_py(data.frame(features = features))
207207
)
208208
adata$X = adata$X$toarray()
209209
adata$obsm["X_pca"] = reticulate::r_to_py(x = X_pca)

R/scANVI.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ scANVIIntegration <- function(
258258
t( GetAssayData(object, layer = layer)[features ,] )
259259
),
260260
obs = r_to_py(groups),
261-
var = r_to_py(features)
261+
var = r_to_py(data.frame(features = features))
262262
)
263263
# ValueError raised if unlabeled_category = NULL/None => use unlikely cell label)
264264
labels.null <- labels.null %||% "Gloubi-boulga"

R/scVI.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ scVIIntegration <- function(
203203
t( GetAssayData(object, layer = layer)[features ,] )
204204
),
205205
obs = r_to_py(groups),
206-
var = r_to_py(features)
206+
var = r_to_py(data.frame(features = features))
207207
)
208208

209209
args.call <- c(list(adata = adata, labels_key = r_to_py(labels.name),

R/trVAE.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ trVAEIntegration <- function(
309309
Matrix::t( GetAssayData(object, layer = layer)[features, ] )
310310
),
311311
obs = reticulate::r_to_py(groups[, c(groups.name, surgery.name), drop = FALSE]),
312-
var = reticulate::r_to_py(features)
312+
var = r_to_py(data.frame(features = features))
313313
)
314314

315315
adata <- sca$dataset$remove_sparsity(adata)

R/utils.R

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -185,34 +185,6 @@ symmetrize.pmin.sparse <- function(i, j, x, height) {
185185

186186
}
187187

188-
#' Normalise a matrix using L2 norm
189-
#'
190-
#' @description
191-
#' Normalise the rows or columns of a matrix using L2 norm
192-
#'
193-
#' @param mat a matrix (sparse or dense)
194-
#' @param MARGIN one of 1 or 2, corresponding to normalisation per rows and
195-
#' columns respectively
196-
#'
197-
#' @return the matrix with normalised rows or columns
198-
#'
199-
#' @importFrom rlang abort
200-
#' @importFrom Matrix rowSums colSums
201-
#' @note
202-
#' Adapted from \href{https://github.com/satijalab/seurat/blob/1549dcb3075eaeac01c925c4b4bb73c73450fc50/R/utilities.R#L1941-L1956}{Seurat:::L2Norm}
203-
#' @export
204-
205-
NormaliseL2 <- function(mat, MARGIN = 1) {
206-
marSums <- switch (MARGIN,
207-
`1` = rowSums,
208-
`2` = colSums,
209-
NULL
210-
) %||% abort(paste(sQuote(MARGIN), "is not a correct value for 'MARGIN'.",
211-
"Possible values are 1 (rows) or 2 (columns)"))
212-
mat.norm <- sweep(mat, MARGIN = MARGIN, STATS = sqrt(marSums(mat^2)), FUN = `/`)
213-
mat.norm[!is.finite(mat.norm)] <- 0
214-
return(mat.norm)
215-
}
216188
################################################################################
217189
################################ NN cut ################################
218190
#' Remove excessive number of neighbours in a knn graph
@@ -364,7 +336,7 @@ setMethod(".cut.knn", "Neighbor",
364336
return(object)
365337
})
366338

367-
#' Very similar to .cut.knn.Matrix, but doesn't contruct the trimmed knn network
339+
#' Very similar to .cut.knn.Matrix, but doesn't construct the trimmed knn network
368340
#' @description
369341
#' Requires that all cells have at least k.max neighbors
370342
#'
@@ -554,7 +526,7 @@ setMethod("GetNeighborsPerBatch", c("Seurat", "data.frame"),
554526
#' @usage NULL
555527
setMethod("GetNeighborsPerBatch", "Graph",
556528
function(object, batch.var, count.self) {
557-
knnmat <- as.dgcmatrix(object > 0)
529+
knnmat <- as.dgcmatrix(as(object > 0, 'dsparseMatrix'))
558530
GetNeighborsPerBatch(object = knnmat, batch.var = batch.var,
559531
count.self = count.self)
560532
})
@@ -753,17 +725,48 @@ n_zeros_mat <- function(mat) {
753725
#' @noRd
754726
choose_matrix_format <- function(mat) {
755727
max_int_32bit <- 2^31 - 1
756-
if (all(c(ncol(mat), nrow(mat)) <= max_int_32bit)) { # should always be TRUE
728+
if (all(c(ncol(mat), nrow(mat)) <= max_int_32bit) & length(mat) > 0) { # should always be TRUE
757729
n_0s <- n_zeros_mat(mat = mat)
758-
if ( (n_0s > max_int_32bit) | (n_0s/length(mat) < .35) ) {
730+
n_not0s <- length(mat) - n_0s
731+
if ( (n_not0s > max_int_32bit) | (n_0s/length(mat) < .35) ) {
759732
mat <- as.matrix(mat)
760733
} else {
761-
as.dgcmatrix(mat)
734+
mat <- as.dgcmatrix(mat)
762735
}
763736
}
764737
return(mat)
765738
}
766739

740+
################################################################################
741+
########################### Seurat extensions ############################
742+
#' Normalise a matrix using L2 norm
743+
#'
744+
#' @description
745+
#' Normalise the rows or columns of a matrix using L2 norm
746+
#'
747+
#' @param mat a matrix (sparse or dense)
748+
#' @param MARGIN one of 1 or 2, corresponding to normalisation per rows and
749+
#' columns respectively
750+
#'
751+
#' @return the matrix with normalised rows or columns
752+
#'
753+
#' @importFrom rlang abort
754+
#' @importFrom Matrix rowSums colSums
755+
#' @note
756+
#' Adapted from \href{https://github.com/satijalab/seurat/blob/1549dcb3075eaeac01c925c4b4bb73c73450fc50/R/utilities.R#L1941-L1956}{Seurat:::L2Norm}
757+
#' @export
758+
759+
NormaliseL2 <- function(mat, MARGIN = 1) {
760+
marSums <- switch (MARGIN,
761+
`1` = rowSums,
762+
`2` = colSums,
763+
NULL
764+
) %||% abort(paste(sQuote(MARGIN), "is not a correct value for 'MARGIN'.",
765+
"Possible values are 1 (rows) or 2 (columns)"))
766+
mat.norm <- sweep(mat, MARGIN = MARGIN, STATS = sqrt(marSums(mat^2)), FUN = `/`)
767+
mat.norm[!is.finite(mat.norm)] <- 0
768+
return(mat.norm)
769+
}
767770

768771
# Creates data.frame with cell group assignments for integration
769772
# uses SCT models if SCTAssay and layers otherwise
@@ -801,3 +804,8 @@ CreateIntegrationGroups <- function(object, layers, scale.layer) {
801804
return(groups)
802805
}
803806
############
807+
808+
#' @method as.Graph Graph
809+
as.Graph.Graph <- function(x, ...) {
810+
return(x)
811+
}

pkgdown/_pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
url: https://cbib.github.io/Seurat-Integrate/
1+
url: https://fspecque.github.io/test/
22
template:
33
bootstrap: 5
44
math-rendering: mathjax

src/RcppExports.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ BEGIN_RCPP
3535
END_RCPP
3636
}
3737
// n_zeros_sparse_mat
38-
int64_t n_zeros_sparse_mat(const arma::sp_mat& mat);
38+
int64_t n_zeros_sparse_mat(arma::sp_mat& mat);
3939
RcppExport SEXP _SeuratIntegrate_n_zeros_sparse_mat(SEXP matSEXP) {
4040
BEGIN_RCPP
4141
Rcpp::RObject rcpp_result_gen;
4242
Rcpp::RNGScope rcpp_rngScope_gen;
43-
Rcpp::traits::input_parameter< const arma::sp_mat& >::type mat(matSEXP);
43+
Rcpp::traits::input_parameter< arma::sp_mat& >::type mat(matSEXP);
4444
rcpp_result_gen = Rcpp::wrap(n_zeros_sparse_mat(mat));
4545
return rcpp_result_gen;
4646
END_RCPP

src/n_zeros_matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ int64_t n_zeros_dense_mat(const arma::mat &mat) {
88
}
99

1010
// [[Rcpp::export]]
11-
int64_t n_zeros_sparse_mat(const arma::sp_mat &mat) {
12-
int64_t count = mat.n_elem - mat.n_nonzero;
11+
int64_t n_zeros_sparse_mat(arma::sp_mat &mat) {
12+
int64_t count = mat.clean(0).n_elem - mat.n_nonzero;
1313
return count;
1414
}
1515

0 commit comments

Comments
 (0)