From cc934977c5dc187b2b2477d1c7bbf1e43430fd30 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Thu, 17 Nov 2022 18:45:31 +0100 Subject: [PATCH 1/9] assure cbind gives unique colnames & barcodes are kept as colData --- ...periment-combine.R => SpatialExperiment-cbind.R} | 5 +++++ R/read10xVisium.R | 8 +++----- tests/testthat/test_SpatialExperiment-cbind.R | 13 ++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) rename R/{SpatialExperiment-combine.R => SpatialExperiment-cbind.R} (95%) diff --git a/R/SpatialExperiment-combine.R b/R/SpatialExperiment-cbind.R similarity index 95% rename from R/SpatialExperiment-combine.R rename to R/SpatialExperiment-cbind.R index 7cd18b3..e59aa78 100644 --- a/R/SpatialExperiment-combine.R +++ b/R/SpatialExperiment-cbind.R @@ -103,6 +103,11 @@ setMethod("cbind", "SpatialExperiment", function(..., deparse.level=1) { out <- do.call( callNextMethod, c(args, list(deparse.level=1))) + if (any(duplicated(colnames(out)))) { + n <- vapply(args, ncol, integer(1)) + n <- rep.int(seq_along(args), n) + colnames(out) <- paste(n, colnames(out), sep="_") + } # merge 'imgData' from multiple samples if (!is.null(imgData(args[[1]]))) { diff --git a/R/read10xVisium.R b/R/read10xVisium.R index 4bc6d82..594279f 100644 --- a/R/read10xVisium.R +++ b/R/read10xVisium.R @@ -190,13 +190,11 @@ read10xVisium <- function(samples="", cnms <- c( "barcode", "in_tissue", "array_row", "array_col", "pxl_row_in_fullres", "pxl_col_in_fullres") - df <- lapply(seq_along(x), function(i) - { - df <- read.csv(x[i], - header=!grepl("list", x[i]), - row.names=1, col.names=cnms) + df <- lapply(seq_along(x), function(i) { + df <- read.csv(x[i], header=!grepl("list", x[i]), col.names=cnms) if (length(x) > 1) rownames(df) <- paste(i, rownames(df), sep="_") if (!is.null(names(x))) cbind(sample_id=names(x)[i], df) + rownames(df) <- df$barcode df }) df <- do.call(rbind, df) diff --git a/tests/testthat/test_SpatialExperiment-cbind.R b/tests/testthat/test_SpatialExperiment-cbind.R index 5100a6c..762a23c 100644 --- a/tests/testthat/test_SpatialExperiment-cbind.R +++ b/tests/testthat/test_SpatialExperiment-cbind.R @@ -8,7 +8,6 @@ test_that("duplicated sample_ids are made unique with a message", { expect_true(nrow(new) == nrow(spe)) expect_true(ncol(new) == 2*ncol(spe)) expect_identical(rownames(new), rownames(spe)) - expect_setequal(colnames(new), colnames(spe)) }) test_that("imgData are combined correctly", { @@ -33,3 +32,15 @@ test_that("imgData are combined correctly", { expect_identical(imgData(spe3)[one, ], imgData(spe1)) expect_identical(imgData(spe3)[two, ], imgData(spe2)) }) + +test_that("unique colnames are left asis,", { + tmp <- spe + colnames(tmp) <- paste0(colnames(tmp), "x") + out <- cbind(spe, tmp) + expect_false(any(duplicated(colnames(out)))) +}) + +test_that("duplicated colnames are made unique", { + out <- cbind(spe, spe) + expect_false(any(duplicated(colnames(out)))) +}) \ No newline at end of file From 8d81990a03e0676d20c678258a54ac13ef1c04bf Mon Sep 17 00:00:00 2001 From: dario righelli Date: Thu, 17 Nov 2022 20:07:40 +0100 Subject: [PATCH 2/9] Update R-cmd-check.yaml --- .github/workflows/R-cmd-check.yaml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/R-cmd-check.yaml b/.github/workflows/R-cmd-check.yaml index 9e083ba..257614d 100644 --- a/.github/workflows/R-cmd-check.yaml +++ b/.github/workflows/R-cmd-check.yaml @@ -19,12 +19,15 @@ jobs: fail-fast: false matrix: config: - - { os: windows-latest, r: '4.2', bioc: 'devel'} - - { os: macOS-latest, r: '4.2', bioc: 'devel'} - - { os: ubuntu-latest, r: '4.2', bioc: 'devel', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } - #- { os: windows-latest, r: '4.2', bioc: '3.15'} - #- { os: macOS-latest, r: '4.2', bioc: '3.15'} - #- { os: ubuntu-latest, r: '4.2', bioc: '3.15', cont: "bioconductor/bioconductor_docker:RELEASE_3_15", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } + - { os: ubuntu-latest, bioc: 'devel'} + - { os: windows-latest, r: 'devel', bioc: 'devel'} + - { os: macOS-latest, r: 'devel', bioc: 'devel'} + #- { os: ubuntu-latest, r: '4.2', bioc: '3.16', cont: "bioconductor/bioconductor_docker:RELEASE_3_16", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } + #- { os: windows-latest, r: '4.2', bioc: '3.16'} + #- { os: macOS-latest, r: '4.2', bioc: '3.16'} + #- { os: ubuntu-latest, r: '4.2', bioc: 'devel', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" } + #- { os: windows-latest, r: '4.2', bioc: 'devel'} + #- { os: macOS-latest, r: '4.2', bioc: 'devel'} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true @@ -36,14 +39,14 @@ jobs: - name: Check out repo uses: actions/checkout@v2 - - name: Set up R - uses: r-lib/actions/setup-r@master + - name: Set up R and install BiocManager + uses: grimbough/bioc-actions/setup-bioc@v1 if: matrix.config.image == null with: - r-version: ${{ matrix.config.r }} + bioc-version: ${{ matrix.config.bioc }} - name: Set up pandoc - uses: r-lib/actions/setup-pandoc@master + uses: r-lib/actions/setup-pandoc@v2 if: matrix.config.image == null - name: Install windows dependencies From 3ddd2c30f443ca6700c100fa445a80776809e687 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Mon, 21 Nov 2022 20:00:55 +0100 Subject: [PATCH 3/9] +withDimnames arg in spatialCoords getter&setter --- DESCRIPTION | 2 +- R/AllGenerics.R | 4 +- R/SpatialExperiment-methods.R | 63 --------------- R/spatialCoords.R | 76 +++++++++++++++++++ man/SpatialExperiment-methods.Rd | 31 ++++---- .../testthat/test_SpatialExperiment-methods.R | 22 ------ .../test_SpatialExperiment-spatialCoords.R | 36 +++++++++ 7 files changed, 131 insertions(+), 103 deletions(-) create mode 100644 R/spatialCoords.R create mode 100644 tests/testthat/test_SpatialExperiment-spatialCoords.R diff --git a/DESCRIPTION b/DESCRIPTION index c21eb64..1e0465b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,4 +49,4 @@ Suggests: BiocStyle, BumpyMatrix VignetteBuilder: knitr -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.2 diff --git a/R/AllGenerics.R b/R/AllGenerics.R index a1f9601..e4f5d64 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -48,10 +48,10 @@ setGeneric("spatialDataNames", function(x) standardGeneric("spatialDataNames")) setGeneric("spatialDataNames<-", function(x, value) standardGeneric("spatialDataNames<-")) #' @export -setGeneric("spatialCoords", function(x, ...) standardGeneric("spatialCoords")) +setGeneric("spatialCoords", function(x, withDimnames=TRUE, ...) standardGeneric("spatialCoords")) #' @export -setGeneric("spatialCoords<-", function(x, value) standardGeneric("spatialCoords<-")) +setGeneric("spatialCoords<-", function(x, value, withDimnames=TRUE) standardGeneric("spatialCoords<-")) #' @export setGeneric("spatialCoordsNames", function(x) standardGeneric("spatialCoordsNames")) diff --git a/R/SpatialExperiment-methods.R b/R/SpatialExperiment-methods.R index 0e5ac36..60bbbc5 100644 --- a/R/SpatialExperiment-methods.R +++ b/R/SpatialExperiment-methods.R @@ -183,69 +183,6 @@ setReplaceMethod("spatialDataNames", } ) -# spatialCoords ---------------------------------------------------------------- - -#' @rdname SpatialExperiment-methods -#' @importFrom SingleCellExperiment int_colData<- -#' @export -setMethod("spatialCoords", - "SpatialExperiment", - function(x) int_colData(x)$spatialCoords) - -#' @rdname SpatialExperiment-methods -#' @importFrom SingleCellExperiment int_colData<- -#' @export -setReplaceMethod("spatialCoords", - c("SpatialExperiment", "matrix"), - function(x, value) { - stopifnot( - is.numeric(value), - nrow(value) == ncol(x)) - int_colData(x)$spatialCoords <- value - return(x) - } -) - -#' @rdname SpatialExperiment-methods -#' @export -setReplaceMethod("spatialCoords", - c("SpatialExperiment", "NULL"), - function(x, value) { - value <- matrix(numeric(), ncol(x), 0) - `spatialCoords<-`(x, value) - } -) - -# spatialCoordsNames ----------------------------------------------------------- - -#' @rdname SpatialExperiment-methods -#' @importFrom SingleCellExperiment int_colData -#' @export -setMethod("spatialCoordsNames", - "SpatialExperiment", - function(x) colnames(int_colData(x)$spatialCoords)) - -#' @rdname SpatialExperiment-methods -#' @importFrom SingleCellExperiment int_colData<- -#' @export -setReplaceMethod("spatialCoordsNames", - c("SpatialExperiment", "character"), - function(x, value) { - colnames(int_colData(x)$spatialCoords) <- value - return(x) - } -) - -#' @rdname SpatialExperiment-methods -#' @export -setReplaceMethod("spatialCoordsNames", - c("SpatialExperiment", "NULL"), - function(x, value) { - value <- character() - `spatialCoordsNames<-`(x, value) - } -) - # scaleFactors ----------------------------------------------------------------- #' @rdname SpatialExperiment-methods diff --git a/R/spatialCoords.R b/R/spatialCoords.R new file mode 100644 index 0000000..0d9827b --- /dev/null +++ b/R/spatialCoords.R @@ -0,0 +1,76 @@ + +# spatialCoords ---------------------------------------------------------------- + +#' @rdname SpatialExperiment-methods +#' @importFrom SingleCellExperiment int_colData<- +#' @export +setMethod("spatialCoords", + "SpatialExperiment", + function(x, withDimnames=TRUE) { + out <- int_colData(x)$spatialCoords + if (withDimnames) + rownames(out) <- colnames(x) + return(out) + }) + +#' @rdname SpatialExperiment-methods +#' @importFrom SingleCellExperiment int_colData<- +#' @export +setReplaceMethod("spatialCoords", + c("SpatialExperiment", "matrix"), + function(x, value, withDimnames=TRUE) { + stopifnot( + is.numeric(value), + nrow(value) == ncol(x)) + new <- rownames(value) + if (!is.null(new) && withDimnames) { + if (!identical(new, colnames(x))) { + stop("Non-NULL 'rownames(value)' should be the", + " same as 'colnames(x)' for 'spatialCoords<-'.", + " Use 'withDimnames=FALSE' to force replacement.") + } + } + int_colData(x)$spatialCoords <- value + return(x) + } +) + +#' @rdname SpatialExperiment-methods +#' @export +setReplaceMethod("spatialCoords", + c("SpatialExperiment", "NULL"), + function(x, value, withDimnames=TRUE) { + value <- matrix(numeric(), ncol(x), 0) + `spatialCoords<-`(x, value) + } +) + +# spatialCoordsNames ----------------------------------------------------------- + +#' @rdname SpatialExperiment-methods +#' @importFrom SingleCellExperiment int_colData +#' @export +setMethod("spatialCoordsNames", + "SpatialExperiment", + function(x) colnames(int_colData(x)$spatialCoords)) + +#' @rdname SpatialExperiment-methods +#' @importFrom SingleCellExperiment int_colData<- +#' @export +setReplaceMethod("spatialCoordsNames", + c("SpatialExperiment", "character"), + function(x, value) { + colnames(int_colData(x)$spatialCoords) <- value + return(x) + } +) + +#' @rdname SpatialExperiment-methods +#' @export +setReplaceMethod("spatialCoordsNames", + c("SpatialExperiment", "NULL"), + function(x, value) { + value <- character() + `spatialCoordsNames<-`(x, value) + } +) diff --git a/man/SpatialExperiment-methods.Rd b/man/SpatialExperiment-methods.Rd index d66d106..2bdc80f 100644 --- a/man/SpatialExperiment-methods.Rd +++ b/man/SpatialExperiment-methods.Rd @@ -1,5 +1,6 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/SpatialExperiment-methods.R, R/imgData.R +% Please edit documentation in R/SpatialExperiment-methods.R, R/imgData.R, +% R/spatialCoords.R \name{SpatialExperiment-methods} \alias{SpatialExperiment-methods} \alias{spatialData} @@ -19,16 +20,16 @@ \alias{spatialDataNames,SpatialExperiment-method} \alias{spatialDataNames<-,SpatialExperiment,character-method} \alias{spatialDataNames<-,SpatialExperiment,NULL-method} +\alias{scaleFactors,SpatialExperiment-method} +\alias{imgData,SpatialExperiment-method} +\alias{imgData<-,SpatialExperiment,DataFrame-method} +\alias{imgData<-,SpatialExperiment,NULL-method} \alias{spatialCoords,SpatialExperiment-method} \alias{spatialCoords<-,SpatialExperiment,matrix-method} \alias{spatialCoords<-,SpatialExperiment,NULL-method} \alias{spatialCoordsNames,SpatialExperiment-method} \alias{spatialCoordsNames<-,SpatialExperiment,character-method} \alias{spatialCoordsNames<-,SpatialExperiment,NULL-method} -\alias{scaleFactors,SpatialExperiment-method} -\alias{imgData,SpatialExperiment-method} -\alias{imgData<-,SpatialExperiment,DataFrame-method} -\alias{imgData<-,SpatialExperiment,NULL-method} \title{Methods for spatial attributes} \usage{ \S4method{spatialData}{SpatialExperiment}(x) @@ -43,25 +44,25 @@ \S4method{spatialDataNames}{SpatialExperiment,`NULL`}(x) <- value -\S4method{spatialCoords}{SpatialExperiment}(x) +\S4method{scaleFactors}{SpatialExperiment}(x, sample_id = TRUE, image_id = TRUE) -\S4method{spatialCoords}{SpatialExperiment,matrix}(x) <- value +\S4method{imgData}{SpatialExperiment}(x) -\S4method{spatialCoords}{SpatialExperiment,`NULL`}(x) <- value +\S4method{imgData}{SpatialExperiment,DataFrame}(x) <- value -\S4method{spatialCoordsNames}{SpatialExperiment}(x) +\S4method{imgData}{SpatialExperiment,`NULL`}(x) <- value -\S4method{spatialCoordsNames}{SpatialExperiment,character}(x) <- value +\S4method{spatialCoords}{SpatialExperiment}(x, withDimnames = TRUE) -\S4method{spatialCoordsNames}{SpatialExperiment,`NULL`}(x) <- value +\S4method{spatialCoords}{SpatialExperiment,matrix}(x, withDimnames = TRUE) <- value -\S4method{scaleFactors}{SpatialExperiment}(x, sample_id = TRUE, image_id = TRUE) +\S4method{spatialCoords}{SpatialExperiment,`NULL`}(x, withDimnames = TRUE) <- value -\S4method{imgData}{SpatialExperiment}(x) +\S4method{spatialCoordsNames}{SpatialExperiment}(x) -\S4method{imgData}{SpatialExperiment,DataFrame}(x) <- value +\S4method{spatialCoordsNames}{SpatialExperiment,character}(x) <- value -\S4method{imgData}{SpatialExperiment,`NULL`}(x) <- value +\S4method{spatialCoordsNames}{SpatialExperiment,`NULL`}(x) <- value } \arguments{ \item{x}{A \code{\link{SpatialExperiment}} object.} diff --git a/tests/testthat/test_SpatialExperiment-methods.R b/tests/testthat/test_SpatialExperiment-methods.R index ffe1b46..c863c05 100644 --- a/tests/testthat/test_SpatialExperiment-methods.R +++ b/tests/testthat/test_SpatialExperiment-methods.R @@ -45,28 +45,6 @@ test_that("spatialDataNames()<-,NULL", { expect_identical(new, character(0)) }) -test_that("spatialCoordsNames()", { - expect_identical( - spatialCoordsNames(spe), - colnames(int_colData(spe)$spatialCoords)) -}) - -test_that("spatialCoordsNames<-,character", { - old <- spatialCoordsNames(spe) - new <- sample(letters, length(old)) - spatialCoordsNames(spe) <- new - expect_identical(spatialCoordsNames(spe), new) - expect_identical(spatialCoordsNames(spe), - colnames(int_colData(spe)$spatialCoords)) -}) - -test_that("spatialCoordsNames<-,NULL", { - old <- spatialCoords(spe) - spatialCoordsNames(spe) <- NULL - expect_null(spatialCoordsNames(spe)) - expect_equivalent(spatialCoords(spe), old) -}) - test_that("scaleFactors()", { sfs <- scaleFactors(spe, sample_id=TRUE, image_id=TRUE) expect_is(sfs, "numeric") diff --git a/tests/testthat/test_SpatialExperiment-spatialCoords.R b/tests/testthat/test_SpatialExperiment-spatialCoords.R new file mode 100644 index 0000000..9f3e47b --- /dev/null +++ b/tests/testthat/test_SpatialExperiment-spatialCoords.R @@ -0,0 +1,36 @@ +example(read10xVisium, echo = FALSE) + +test_that("spatialCoordsNames()", { + expect_identical( + spatialCoordsNames(spe), + colnames(int_colData(spe)$spatialCoords)) +}) + +test_that("spatialCoordsNames<-,character", { + old <- spatialCoordsNames(spe) + new <- sample(letters, length(old)) + spatialCoordsNames(spe) <- new + expect_identical(spatialCoordsNames(spe), new) + expect_identical(spatialCoordsNames(spe), + colnames(int_colData(spe)$spatialCoords)) +}) + +test_that("spatialCoordsNames<-,NULL", { + old <- spatialCoords(spe) + spatialCoordsNames(spe) <- NULL + expect_null(spatialCoordsNames(spe)) + expect_equivalent(spatialCoords(spe), old) +}) + +test_that("spatialCoords<-,matrix", { + # no 'rownames(value)' passes + rownames(xyz) <- NULL + expect_silent(spatialCoords(spe) <- xyz) + # shuffle coordinates + xyz <- spatialCoords(spe) + xyz <- xyz[sample(ncol(spe)), ] + # rownames(value) != colnames(x) fails + expect_error(spatialCoords(spe) <- xyz) + # but passes with 'withDimnames=FALSE' + expect_silent(spatialCoords(spe, withDimnames=FALSE) <- xyz) +}) From d8aabf650b00b3b5d0aa4343f51403827b72b488 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Mon, 21 Nov 2022 20:10:08 +0100 Subject: [PATCH 4/9] add doc for param 'withDimnames' --- R/SpatialExperiment-methods.R | 6 ++++++ man/SpatialExperiment-methods.Rd | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/R/SpatialExperiment-methods.R b/R/SpatialExperiment-methods.R index 60bbbc5..84c7f11 100644 --- a/R/SpatialExperiment-methods.R +++ b/R/SpatialExperiment-methods.R @@ -22,6 +22,12 @@ #' identifier(s) for \code{scaleFactors}. Default = \code{TRUE} (all samples). #' @param image_id Logical value or character vector specifying image #' identifier(s) for \code{scaleFactors}. Default = \code{TRUE} (all images). +#' @param withDimnames Logical value indicating whether dimnames of the +#' \code{spatialExperiment} should be applied or checked against. +#' If \code{withDimnames=TRUE}, non-\code{NULL} \code{rownames(value)} +#' are checked against \code{colnames(x)}, and an error occurs if these +#' don't match. Else, discrepancies in rownames are ignored. +#' (see also \code{\link[SingleCellExperiment]{reducedDims}}) #' #' @details #' Additional details for each type of data attribute are provided below. diff --git a/man/SpatialExperiment-methods.Rd b/man/SpatialExperiment-methods.Rd index 2bdc80f..9d9e180 100644 --- a/man/SpatialExperiment-methods.Rd +++ b/man/SpatialExperiment-methods.Rd @@ -74,6 +74,13 @@ identifier(s) for \code{scaleFactors}. Default = \code{TRUE} (all samples).} \item{image_id}{Logical value or character vector specifying image identifier(s) for \code{scaleFactors}. Default = \code{TRUE} (all images).} + +\item{withDimnames}{Logical value indicating whether dimnames of the +\code{spatialExperiment} should be applied or checked against. +If \code{withDimnames=TRUE}, non-\code{NULL} \code{rownames(value)} +are checked against \code{colnames(x)}, and an error occurs if these +don't match. Else, discrepancies in rownames are ignored. +(see also \code{\link[SingleCellExperiment]{reducedDims}})} } \value{ Return value varies depending on method, as described below. From 1b4fad47547d5020a5411748d125e76bb3358b32 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Tue, 22 Nov 2022 14:43:26 +0100 Subject: [PATCH 5/9] version bump to v1.9.4 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1e0465b..896ed6c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: SpatialExperiment -Version: 1.7.2 +Version: 1.9.4 Title: S4 Class for Spatially Resolved Transcriptomics Data Description: Defines an S4 class for storing data from spatially resolved transcriptomics (ST) experiments. The class extends SingleCellExperiment to From fe40c8f98cfc06277b2d3a6e3116593ab67843eb Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Tue, 22 Nov 2022 14:43:54 +0100 Subject: [PATCH 6/9] fix bug in unit tests (uninitialized variable) --- tests/testthat/test_SpatialExperiment-spatialCoords.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test_SpatialExperiment-spatialCoords.R b/tests/testthat/test_SpatialExperiment-spatialCoords.R index 9f3e47b..6f84597 100644 --- a/tests/testthat/test_SpatialExperiment-spatialCoords.R +++ b/tests/testthat/test_SpatialExperiment-spatialCoords.R @@ -23,9 +23,6 @@ test_that("spatialCoordsNames<-,NULL", { }) test_that("spatialCoords<-,matrix", { - # no 'rownames(value)' passes - rownames(xyz) <- NULL - expect_silent(spatialCoords(spe) <- xyz) # shuffle coordinates xyz <- spatialCoords(spe) xyz <- xyz[sample(ncol(spe)), ] @@ -33,4 +30,7 @@ test_that("spatialCoords<-,matrix", { expect_error(spatialCoords(spe) <- xyz) # but passes with 'withDimnames=FALSE' expect_silent(spatialCoords(spe, withDimnames=FALSE) <- xyz) + # no 'rownames(value)' passes + rownames(xyz) <- NULL + expect_silent(spatialCoords(spe) <- xyz) }) From 8842c22489cb0ccd4c76927a63d7329290da6912 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Thu, 24 Nov 2022 09:11:42 +0100 Subject: [PATCH 7/9] update NEWS file v1.9.4 --- inst/NEWS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inst/NEWS b/inst/NEWS index 2ba29b3..f966420 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,3 +1,9 @@ +changes in version 1.9.4 (2022-11-24) ++ avoid duplicated colnames when cbinding SPEs ++ read10xVisium keeps original barcodes as colData ++ added withDimnames argument for spatialCoords/<- + (analogous to SCE's reducedDim(s)/<-) + changes in version 1.7.2 (2022-10-07) + support for seeing colData names with $ in RStudio From fc2e6af5b2b59dc1635f7336374da863f22c7297 Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Thu, 24 Nov 2022 09:11:55 +0100 Subject: [PATCH 8/9] fix generic/method defintiions --- R/AllGenerics.R | 4 ++-- R/SpatialExperiment-methods.R | 1 + R/spatialCoords.R | 11 ++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index e4f5d64..f22fc73 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -48,10 +48,10 @@ setGeneric("spatialDataNames", function(x) standardGeneric("spatialDataNames")) setGeneric("spatialDataNames<-", function(x, value) standardGeneric("spatialDataNames<-")) #' @export -setGeneric("spatialCoords", function(x, withDimnames=TRUE, ...) standardGeneric("spatialCoords")) +setGeneric("spatialCoords", function(x, ...) standardGeneric("spatialCoords")) #' @export -setGeneric("spatialCoords<-", function(x, value, withDimnames=TRUE) standardGeneric("spatialCoords<-")) +setGeneric("spatialCoords<-", function(x, ..., value) standardGeneric("spatialCoords<-")) #' @export setGeneric("spatialCoordsNames", function(x) standardGeneric("spatialCoordsNames")) diff --git a/R/SpatialExperiment-methods.R b/R/SpatialExperiment-methods.R index 8499cb6..ca227e6 100644 --- a/R/SpatialExperiment-methods.R +++ b/R/SpatialExperiment-methods.R @@ -29,6 +29,7 @@ #' don't match. Else, discrepancies in rownames are ignored. #' (see also \code{\link[SingleCellExperiment]{reducedDims}}) #' @param name The name of the \code{colData} column to extract. +#' @param ... Further arguments passed to and from other methods. #' #' @details #' Additional details for each type of data attribute are provided below. diff --git a/R/spatialCoords.R b/R/spatialCoords.R index 0d9827b..c22c0ac 100644 --- a/R/spatialCoords.R +++ b/R/spatialCoords.R @@ -6,7 +6,7 @@ #' @export setMethod("spatialCoords", "SpatialExperiment", - function(x, withDimnames=TRUE) { + function(x, withDimnames=TRUE, ...) { out <- int_colData(x)$spatialCoords if (withDimnames) rownames(out) <- colnames(x) @@ -18,7 +18,7 @@ setMethod("spatialCoords", #' @export setReplaceMethod("spatialCoords", c("SpatialExperiment", "matrix"), - function(x, value, withDimnames=TRUE) { + function(x, withDimnames=TRUE, ..., value) { stopifnot( is.numeric(value), nrow(value) == ncol(x)) @@ -39,9 +39,10 @@ setReplaceMethod("spatialCoords", #' @export setReplaceMethod("spatialCoords", c("SpatialExperiment", "NULL"), - function(x, value, withDimnames=TRUE) { - value <- matrix(numeric(), ncol(x), 0) - `spatialCoords<-`(x, value) + function(x, withDimnames=TRUE, ..., value) { + `spatialCoords<-`(x, + withDimnames=withDimnames, ..., + value=matrix(numeric(), ncol(x), 0)) } ) From 253e5e43ac7eddfa9a01d5183410142d59943ada Mon Sep 17 00:00:00 2001 From: HelenaLC Date: Thu, 24 Nov 2022 09:12:18 +0100 Subject: [PATCH 9/9] add doc for ... param --- man/SpatialExperiment-methods.Rd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/man/SpatialExperiment-methods.Rd b/man/SpatialExperiment-methods.Rd index 8eeb9ef..804e407 100644 --- a/man/SpatialExperiment-methods.Rd +++ b/man/SpatialExperiment-methods.Rd @@ -55,11 +55,11 @@ \S4method{imgData}{SpatialExperiment,`NULL`}(x) <- value -\S4method{spatialCoords}{SpatialExperiment}(x, withDimnames = TRUE) +\S4method{spatialCoords}{SpatialExperiment}(x, withDimnames = TRUE, ...) -\S4method{spatialCoords}{SpatialExperiment,matrix}(x, withDimnames = TRUE) <- value +\S4method{spatialCoords}{SpatialExperiment,matrix}(x, withDimnames = TRUE, ...) <- value -\S4method{spatialCoords}{SpatialExperiment,`NULL`}(x, withDimnames = TRUE) <- value +\S4method{spatialCoords}{SpatialExperiment,`NULL`}(x, withDimnames = TRUE, ...) <- value \S4method{spatialCoordsNames}{SpatialExperiment}(x) @@ -86,6 +86,8 @@ If \code{withDimnames=TRUE}, non-\code{NULL} \code{rownames(value)} are checked against \code{colnames(x)}, and an error occurs if these don't match. Else, discrepancies in rownames are ignored. (see also \code{\link[SingleCellExperiment]{reducedDims}})} + +\item{...}{Further arguments passed to and from other methods.} } \value{ Return value varies depending on method, as described below.