Bioconductor / DelayedArray

A unified framework for working transparently with on-disk and in-memory array-like datasets
https://bioconductor.org/packages/DelayedArray
24 stars 9 forks source link

rowRanges/colRanges not preserving row/col names #106

Closed PeteHaitch closed 1 year ago

PeteHaitch commented 1 year ago

Hi Hervé,

I'm updating DelayedMatrixStats in BioC-devel to work against the matrixStats v1.0 API and found this discrepancy was tickled by the DelayedMatrixStats unit tests. I'm unsure if this affects other matrixStats-like functions defined in DelayedArray.

Cheers, Pete

suppressPackageStartupMessages(library(DelayedArray))
suppressPackageStartupMessages(library(MatrixGenerics))
suppressPackageStartupMessages(library(DelayedMatrixStats))

x <- matrix(
  -5:6,
  nrow = 3,
  dimnames = list(c("R1", "R2", "R3"), c("C1", "C2", "C3", "C4")))
X <- DelayedArray(x)

# rowRanges,DelayedMatrix-method is defined in DelayedArray rather than 
# DelayedMatrixStats.
selectMethod("rowRanges", class(X))
#> Method Definition:
#> 
#> function (x, ...) 
#> {
#>     .local <- function (x, rows = NULL, cols = NULL, na.rm = FALSE) 
#>     {
#>         .check_rows_cols(rows, cols, "rowRanges")
#>         BLOCK_rowRanges(x, na.rm = na.rm)
#>     }
#>     .local(x, ...)
#> }
#> <bytecode: 0x10cfaa288>
#> <environment: namespace:DelayedArray>
#> 
#> Signatures:
#>         x              
#> target  "DelayedMatrix"
#> defined "DelayedMatrix"

# Has rownames (i.e. new default of `useNames = TRUE` is being followed).
rowRanges(x)
#>    [,1] [,2]
#> R1   -5    4
#> R2   -4    5
#> R3   -3    6
# No rownames (i.e. new default `useNames = TRUE` is being ignored).
rowRanges(X)
#>      [,1] [,2]
#> [1,]   -5    4
#> [2,]   -4    5
#> [3,]   -3    6

# colRanges,DelayedMatrix-method is defined in DelayedArray rather than 
# DelayedMatrixStats.
selectMethod("colRanges", class(X))
#> Method Definition:
#> 
#> function (x, rows = NULL, cols = NULL, na.rm = FALSE, ..., useNames = TRUE) 
#> {
#>     .local <- function (x, rows = NULL, cols = NULL, na.rm = FALSE) 
#>     {
#>         .check_rows_cols(rows, cols, "colRanges")
#>         BLOCK_rowRanges(t(x), na.rm = na.rm)
#>     }
#>     .local(x, rows, cols, na.rm, ...)
#> }
#> <bytecode: 0x10b93abd8>
#> <environment: namespace:DelayedArray>
#> 
#> Signatures:
#>         x              
#> target  "DelayedMatrix"
#> defined "DelayedMatrix"

# Has rownames (i.e. new default of `useNames = TRUE` is being followed).
colRanges(x)
#>    [,1] [,2]
#> C1   -5   -3
#> C2   -2    0
#> C3    1    3
#> C4    4    6
# No rownames (i.e. new default `useNames = TRUE` is being ignored).
colRanges(X)
#>      [,1] [,2]
#> [1,]   -5   -3
#> [2,]   -2    0
#> [3,]    1    3
#> [4,]    4    6

Created on 2023-07-04 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.1 (2023-06-16) #> os macOS Ventura 13.4.1 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Australia/Melbourne #> date 2023-07-04 #> pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> BiocGenerics * 0.47.0 2023-04-25 [1] Bioconductor #> cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) #> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) #> DelayedArray * 0.27.8 2023-07-02 [1] Bioconductor #> DelayedMatrixStats * 1.23.0 2023-04-25 [1] Bioconductor #> digest 0.6.31 2022-12-11 [1] CRAN (R 4.3.0) #> evaluate 0.21 2023-05-05 [1] CRAN (R 4.3.0) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) #> fs 1.6.2 2023-04-25 [1] CRAN (R 4.3.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0) #> htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.3.0) #> IRanges * 2.35.2 2023-06-23 [1] Bioconductor #> knitr 1.43 2023-05-25 [1] CRAN (R 4.3.0) #> lattice 0.21-8 2023-04-05 [1] CRAN (R 4.3.1) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0) #> Matrix * 1.5-4.1 2023-05-18 [1] CRAN (R 4.3.1) #> MatrixGenerics * 1.13.1 2023-06-09 [1] Github (Bioconductor/MatrixGenerics@8ecd537) #> matrixStats * 1.0.0 2023-06-02 [1] CRAN (R 4.3.0) #> Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.3.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.3.0) #> rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0) #> rmarkdown 2.23 2023-07-01 [1] CRAN (R 4.3.0) #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.3.0) #> S4Arrays * 1.1.4 2023-05-14 [1] Bioconductor #> S4Vectors * 0.39.1 2023-05-03 [1] Bioconductor #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) #> SparseArray * 1.1.10 2023-06-11 [1] Bioconductor #> sparseMatrixStats 1.13.1 2023-07-03 [1] Github (const-ae/sparseMatrixStats@e3039ed) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0) #> xfun 0.39 2023-04-20 [1] CRAN (R 4.3.0) #> XVector 0.41.1 2023-05-03 [1] Bioconductor #> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0) #> zlibbioc 1.47.0 2023-04-25 [1] Bioconductor #> #> [1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
hpages commented 1 year ago

Thanks Pete. This is now fixed in DelayedArray 0.27.9 (see commit 23eb37061feab9af9cafc499609263a7fe620f9f).

PeteHaitch commented 1 year ago

Thanks!