waldronlab / MultiAssayExperiment

Bioconductor package for management of multi-assay data
https://waldronlab.io/MultiAssayExperiment/
69 stars 32 forks source link

`MultiAssayExperiment()` allows construction of an empty `sampleMap` with non-empty experiments #324

Closed LTLA closed 1 year ago

LTLA commented 1 year ago
se <- SummarizedExperiment(matrix(runif(100), 10, 10))
mae <- MultiAssayExperiment(list(foo=se))
## Warning messages:
## 1: In .sampleMapFromData(colData, experiments) :
##   colData rownames and ExperimentList colnames are empty
## 2: In MultiAssayExperiment(list(foo = se)) :
##   An empty 'sampleMap' may cause unexpected behavior

Arguably this should just be an outright error, as subsequent operations are indeed unexpected:

dim(mae[[1]])
## [1] 10 10

getWithColData(mae, 1)
## Error in `colData<-`(`*tmp*`, value = expanded) :
##   nrow of supplied 'colData' must equal ncol of object

Or more specifically: if the sampleMap is empty, and there is at least one non-empty experiment, the constructor should raise an error. Few users even notice warnings, so this kind of object-breaking issue should be a straight-up error.

On the other hand, if the sampleMap is empty and all experiments are also empty, everything is fine and no error/warning should be raised, as any such warning would certainly be a false positive.

Session information ``` R version 4.3.0 Patched (2023-05-04 r84398) Platform: aarch64-apple-darwin22.3.0 (64-bit) Running under: macOS Ventura 13.2.1 Matrix products: default BLAS: /Users/luna/Software/R/R-4-3-branch/lib/libRblas.dylib LAPACK: /Users/luna/Software/R/R-4-3-branch/lib/libRlapack.dylib; LAPACK version 3.11.0 locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 time zone: America/Los_Angeles tzcode source: internal attached base packages: [1] stats4 stats graphics grDevices utils datasets methods [8] base other attached packages: [1] MultiAssayExperiment_1.27.0 SummarizedExperiment_1.31.1 [3] Biobase_2.61.0 GenomicRanges_1.53.1 [5] GenomeInfoDb_1.37.2 IRanges_2.35.2 [7] S4Vectors_0.39.1 BiocGenerics_0.47.0 [9] MatrixGenerics_1.13.0 matrixStats_1.0.0 loaded via a namespace (and not attached): [1] BiocBaseUtils_1.3.0 SparseArray_1.1.10 zlibbioc_1.47.0 [4] Matrix_1.5-4.1 lattice_0.21-8 GenomeInfoDbData_1.2.10 [7] S4Arrays_1.1.4 XVector_0.41.1 RCurl_1.98-1.12 [10] bitops_1.0-7 grid_4.3.0 DelayedArray_0.27.6 [13] compiler_4.3.0 tools_4.3.0 crayon_1.5.2 ```
lwaldron commented 1 year ago

Adding that I agree with @LTLA 's expected behavior of the constructor.

LiNk-NY commented 1 year ago

Thanks, this should be resolved in 1.27.1