diff --git a/.gitignore b/.gitignore index d65339ec..1fbeec99 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ inst/doc .git_old .vscode/* .Rprofile -docs codecov.yml -pkgdown cell_rna* +docs +pkgdown \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 414f2f51..37d8334d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,7 +42,8 @@ Imports: reticulate (>= 1.25), stats, terra (>= 1.8-21) -Suggests: +Suggests: + GiottoDB, Biobase, chihaya, DelayedArray, diff --git a/R/aggregate.R b/R/aggregate.R index f0f401e7..c1260bfc 100644 --- a/R/aggregate.R +++ b/R/aggregate.R @@ -516,6 +516,17 @@ setMethod( feat_subset_ids = deprecated(), count_info_column = deprecated(), ...) { + is_db_x <- inherits(x@spatVector, "dbSpatial") + is_db_y <- inherits(y@spatVector, "dbSpatial") + + if (xor(is_db_x, is_db_y)) { + stop( + "calculateOverlap: dbSpatial-backed and terra-backed inputs ", + "are not both supported", + call. = FALSE + ) + } + # deprecations feat_subset_values <- GiottoUtils::deprecate_param( feat_subset_ids, feat_subset_values, @@ -538,6 +549,50 @@ setMethod( feat_count_column <- NULL } + # ------------------------------------------------------------------ + # dbSpatial-backed path: keep results dbSpatial-native + # ------------------------------------------------------------------ + if (isTRUE(is_db_x)) { + # GiottoDB defines the method for this generic + if (!base::requireNamespace("GiottoDB", quietly = TRUE)) { + stop( + "calculateOverlap: dbSpatial-backed inputs require the ", + "GiottoDB package. Install it, or load it via `library(GiottoDB)`.", + call. = FALSE + ) + } + + if (!methods::hasMethod( + "calculateOverlap", + signature = signature(x = "dbSpatial", y = "dbSpatial") + )) { + stop( + "calculateOverlap: dbSpatial-backed giottoPolygon or ", + "giottoPoints method missing. Load the GiottoDB package.", + call. = FALSE + ) + } + + # The method is defined in GiottoDB + res <- calculateOverlap( + x = x@spatVector, + y = y@spatVector, + poly_subset_ids = poly_subset_ids, + feat_subset_column = feat_subset_column, + feat_subset_values = feat_subset_values, + feat_count_column = feat_count_column, + verbose = verbose, + ... + ) + + if (isTRUE(return_gpolygon)) { + if (is.null(name_overlap)) name_overlap <- objName(y) + x@overlaps[[name_overlap]] <- res + return(x) + } + return(res) + } + # return an overlap info object res <- calculateOverlap( x = x[], diff --git a/R/data_input.R b/R/data_input.R index aab53ea7..aa6caad8 100644 --- a/R/data_input.R +++ b/R/data_input.R @@ -28,11 +28,20 @@ readExprMatrix <- function( cores = determine_cores(), transpose = FALSE, feat_type = "rna", - expression_matrix_class = c("dgCMatrix", "DelayedArray"), - ...) { + expression_matrix_class = c( + "dgCMatrix", + "DelayedArray", + "dbSparseMatrix" + )) { # check if path is a character vector and exists if (!is.character(path)) stop("path needs to be character vector") if (!file.exists(path)) stop("the path: ", path, " does not exist") + + expression_matrix_class <- match.arg(expression_matrix_class) + if (identical(expression_matrix_class, "dbSparseMatrix")) { + stop("File conversion to dbMatrix is not yet supported") + } + data.table::setDTthreads(threads = cores) # read and convert