diff --git a/NAMESPACE b/NAMESPACE index dcc03e14..f5ad3e26 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ S3method(.DollarNames,affine2d) S3method(.DollarNames,dimObj) +S3method(.DollarNames,giotto) S3method(.DollarNames,metaData) S3method(.DollarNames,spatEnrObj) S3method(.DollarNames,spatLocsObj) diff --git a/R/methods-extract.R b/R/methods-extract.R index 0914eaea..72d5b333 100644 --- a/R/methods-extract.R +++ b/R/methods-extract.R @@ -131,6 +131,13 @@ NULL #' This may remove some unexpected information. For specifically splitting the #' `giotto` object by spatial unit and/or feature type while keeping all #' expected information, use [sliceGiotto()] +#' @param x giotto object +#' @param spat_unit spatial unit (e.g. "cell") +#' @param feat_type feature type to use (e.g. "rna", "protein") +#' @param i character. Indicates the slot name +#' @param j character. Indicates the subobject name +#' @param drop logical. Default = TRUE +#' @param \dots additional arguments #' @examples #' g <- GiottoData::loadGiottoMini("vizgen") #' force(g) @@ -1277,8 +1284,6 @@ setMethod( #' @rdname subset_giotto -#' @param feat_ids feature IDs to select -#' @param cell_ids cell/spatial IDs to select #' @param subset Logical expression evaluated in expression values #' @param negate logical. if `TRUE` all IDs that are **not** in the `subset` #' are selected @@ -1480,6 +1485,9 @@ sliceGiotto <- function( #' @param x the object to coerce #' @param slots character vector. Which data slots to include in list. See #' details +#' @param spat_unit spatial unit (e.g. "cell") +#' @param feat_type feature type to use (e.g. "rna", "protein") +#' @param name name of the elements to select from the slot #' @param \dots additional arguments #' @details #' * Giotto method - the slots argument currently accepts any or multiple of: @@ -1530,4 +1538,4 @@ setMethod("as.list", signature("giotto"), function( } .dbrkt_on_filter <- function(x, y) { x[objName(x) %in% y] -} \ No newline at end of file +} diff --git a/R/save_load.R b/R/save_load.R index 679d7364..0bc9a90e 100644 --- a/R/save_load.R +++ b/R/save_load.R @@ -92,7 +92,7 @@ saveGiotto <- function(gobject, ) terra::writeVector( x = gobject@feat_info[[feat]]@spatVector, - filename = filename + filename = filename, overwrite = TRUE ) } @@ -134,7 +134,7 @@ saveGiotto <- function(gobject, ) terra::writeVector( gobject@spatial_info[[spatinfo]]@spatVector, - filename = filename + filename = filename, overwrite = TRUE ) } @@ -162,7 +162,7 @@ saveGiotto <- function(gobject, ) terra::writeVector( gobject@spatial_info[[spatinfo]]@spatVectorCentroids, - filename = filename + filename = filename, overwrite = TRUE ) } @@ -197,7 +197,7 @@ saveGiotto <- function(gobject, ) terra::writeVector( gobject@spatial_info[[spatinfo]]@overlaps[[feature]], - filename = filename + filename = filename, overwrite = TRUE ) } } diff --git a/man/as.list.Rd b/man/as.list.Rd index 4795bde8..602635e0 100644 --- a/man/as.list.Rd +++ b/man/as.list.Rd @@ -12,6 +12,12 @@ \item{slots}{character vector. Which data slots to include in list. See details} +\item{spat_unit}{spatial unit (e.g. "cell")} + +\item{feat_type}{feature type to use (e.g. "rna", "protein")} + +\item{name}{name of the elements to select from the slot} + \item{\dots}{additional arguments} } \description{ diff --git a/man/subset_giotto.Rd b/man/subset_giotto.Rd index 17867686..929ad547 100644 --- a/man/subset_giotto.Rd +++ b/man/subset_giotto.Rd @@ -56,10 +56,6 @@ are selected} \code{substitute()}. Set this to \code{FALSE} when calling from a function, although that may not be recommended since NSE output can be unexpected when not used interactively.} - -\item{feat_ids}{feature IDs to select} - -\item{cell_ids}{cell/spatial IDs to select} } \description{ Subset a giotto object with \code{[} or \code{subset()} generic. The diff --git a/man/subset_giotto_subobjects.Rd b/man/subset_giotto_subobjects.Rd index 06f2240e..144c16c1 100644 --- a/man/subset_giotto_subobjects.Rd +++ b/man/subset_giotto_subobjects.Rd @@ -17,6 +17,21 @@ \S4method{[[}{giotto,character,character}(x, i, j, spat_unit = NULL, feat_type = NULL, drop = TRUE, ...) } +\arguments{ +\item{x}{giotto object} + +\item{spat_unit}{spatial unit (e.g. "cell")} + +\item{feat_type}{feature type to use (e.g. "rna", "protein")} + +\item{drop}{logical. Default = TRUE} + +\item{\dots}{additional arguments} + +\item{i}{character. Indicates the slot name} + +\item{j}{character. Indicates the subobject name} +} \description{ Subset a \code{giotto} object with \code{[[} to disassemble it into a list of Giotto S4 subobjects. If \code{drop} is \code{FALSE}, the selected subobjects diff --git a/tests/testthat/test-GiottoInstructions.R b/tests/testthat/test-GiottoInstructions.R index 8c9bf152..0a8fd645 100644 --- a/tests/testthat/test-GiottoInstructions.R +++ b/tests/testthat/test-GiottoInstructions.R @@ -41,35 +41,31 @@ test_that("Instructions are created", { expect_type(instrs, "list") }) -# readGiottoInstructions -test_that("readGiottoInstructions reads a few giotto object params correctly", { - expect_type(readGiottoInstructions(gobject, param = "show_plot"), "logical") - expect_type(readGiottoInstructions(gobject, param = "plot_format"), "character") - expect_type(readGiottoInstructions(gobject, param = "dpi"), "double") +# read GiottoInstructions +test_that("instructions reads a few giotto object params correctly", { + expect_type(instructions(gobject, param = "show_plot"), "logical") + expect_type(instructions(gobject, param = "plot_format"), "character") + expect_type(instructions(gobject, param = "dpi"), "double") }) -# showGiottoInstructions -test_that("showGiottoInstructions returns expected list", { - expect_type(showGiottoInstructions(gobject), "list") +# show GiottoInstructions +test_that("instructions returns expected list", { + expect_type(instructions(gobject), "list") }) -# changeGiottoInstructions -gobject <- changeGiottoInstructions( - gobject, - params = c("show_plot", "save_plot"), - new_values = c(FALSE, TRUE), - return_gobject = TRUE -) +# change GiottoInstructions +instructions(gobject, + param = c("show_plot", "save_plot")) <- list(FALSE, TRUE) -test_that("changeGiottoInstructions changes instruction params in object", { - expect_false(readGiottoInstructions(gobject, param = "show_plot")) - expect_true(readGiottoInstructions(gobject, param = "save_plot")) +test_that("change GiottoInstructions changes instruction params in object", { + expect_false(instructions(gobject, param = "show_plot")) + expect_true(instructions(gobject, param = "save_plot")) }) -# replaceGiottoInstructions -gobject <- replaceGiottoInstructions(gobject, instrs) +# replace GiottoInstructions +instructions(gobject) <- instrs -test_that("replaceGiottoInstructions returns object instructions to original", { - expect_true(readGiottoInstructions(gobject, param = "show_plot")) - expect_false(readGiottoInstructions(gobject, param = "save_plot")) +test_that("instructions returns object instructions to original", { + expect_true(instructions(gobject, param = "show_plot")) + expect_false(instructions(gobject, param = "save_plot")) }) diff --git a/tests/testthat/test-interoperability.R b/tests/testthat/test-interoperability.R index 16b9f3ab..df9e944c 100644 --- a/tests/testthat/test-interoperability.R +++ b/tests/testthat/test-interoperability.R @@ -6,9 +6,6 @@ giotto_obj <- GiottoData::loadGiottoMini("visium") seurat_obj <- giottoToSeuratV5(giotto_obj) spe_obj <- giottoToSpatialExperiment(giotto_obj) -Seurat_obj2 <- SeuratData::LoadData("stxBrain", type = "anterior1" ) -giotto_obj2 <- seuratToGiottoV5(Seurat_obj2) - giotto_obj_roundtrip <- seuratToGiottoV5(seurat_obj, "rna") test_that("giottotoseurat function handles basic conversion", { @@ -66,4 +63,4 @@ test_that("Giotto to SpatialExperiment Conversion Works",{ #TODO #spe -#annData \ No newline at end of file +#annData diff --git a/tests/testthat/test-save_load.R b/tests/testthat/test-save_load.R index 79142a4e..839d19a9 100644 --- a/tests/testthat/test-save_load.R +++ b/tests/testthat/test-save_load.R @@ -17,3 +17,20 @@ test_that("gobject an be ovewritten and loaded - qs", { expect_true(methods::validObject(g3)) }) + +test_that("gobject can be saved and loaded - RDS", { + rlang::local_options(lifecycle_verbosity = "quiet") + saveGiotto(g, dir = test, overwrite = TRUE, verbose = FALSE) + g2 <<- loadGiotto(file.path(test, "saveGiottoDir")) + + expect_true(methods::validObject(g2)) +}) + +test_that("gobject an be ovewritten and loaded - RDS", { + rlang::local_options(lifecycle_verbosity = "quiet") + saveGiotto(g2, dir = test, overwrite = TRUE, verbose = FALSE) + g3 <- loadGiotto(file.path(test, "saveGiottoDir")) + + expect_true(methods::validObject(g3)) +}) +