From e11dc15e0158758ad7666d3d9b50a8f0eae7c4bc Mon Sep 17 00:00:00 2001 From: josschavezf Date: Tue, 24 Sep 2024 18:14:52 -0400 Subject: [PATCH 1/8] remove calling to inexistent dataset "stxBrain" --- tests/testthat/test-interoperability.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 From 3681f36012276ee07f605c07f6085341ab8e10d1 Mon Sep 17 00:00:00 2001 From: josschavezf Date: Wed, 25 Sep 2024 11:21:07 -0400 Subject: [PATCH 2/8] run devtools::document --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) 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) From a2466485a7e6f55c9d6bc1c61169171db4ac3a19 Mon Sep 17 00:00:00 2001 From: josschavezf Date: Wed, 25 Sep 2024 11:21:42 -0400 Subject: [PATCH 3/8] add params description --- R/methods-extract.R | 14 +++++++++++--- man/subset_giotto_subobjects.Rd | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) 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/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 From e917e560969a2cec51ff368b27a50a16b4e3f644 Mon Sep 17 00:00:00 2001 From: josschavezf Date: Wed, 25 Sep 2024 11:22:03 -0400 Subject: [PATCH 4/8] add params description --- man/as.list.Rd | 6 ++++++ 1 file changed, 6 insertions(+) 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{ From a02130e0237aaf3a13768211ab541785cc8f74f6 Mon Sep 17 00:00:00 2001 From: josschavezf Date: Wed, 25 Sep 2024 11:22:17 -0400 Subject: [PATCH 5/8] remove duplicated params --- man/subset_giotto.Rd | 4 ---- 1 file changed, 4 deletions(-) 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 From 72027b4ba5be4cae95c562e3abfac9d188139bb4 Mon Sep 17 00:00:00 2001 From: josschavezf Date: Wed, 25 Sep 2024 11:22:41 -0400 Subject: [PATCH 6/8] replace readGiottoInstructions -> instructions --- tests/testthat/test-GiottoInstructions.R | 42 +++++++++++------------- 1 file changed, 19 insertions(+), 23 deletions(-) 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")) }) From 9676ca2b99ddd9cdd3aee2eca51bb2988e658b7f Mon Sep 17 00:00:00 2001 From: josschavezf Date: Wed, 25 Sep 2024 11:22:56 -0400 Subject: [PATCH 7/8] add test using RDS method --- tests/testthat/test-save_load.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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)) +}) + From dec7d7d7ee7b50fca390f6ccfd1821872adb38c3 Mon Sep 17 00:00:00 2001 From: josschavezf Date: Wed, 25 Sep 2024 11:23:24 -0400 Subject: [PATCH 8/8] add overwrite = TRUE to solve test error --- R/save_load.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 ) } }