waldronlab / MultiAssayExperiment

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

Bug in subsetByColData() #316

Closed cvanderaa closed 2 years ago

cvanderaa commented 2 years ago

Hi,

I'm experiencing an issue with subsetByColData(). Here is a minimal example that reproduces the issue:

Generate the data

a1 <- SummarizedExperiment(
    matrix(4, 2, 2, 
           dimnames = list(c("feat1", "feat2"), c("samp1", "samp2"))))
a2 <- SummarizedExperiment(
    matrix(4, 2, 2, 
           dimnames = list(c("feat3", "feat4"), c("samp3", "samp4"))))
el <- ExperimentList(a1 = a1, a2 = a2)
mae <- MultiAssayExperiment(el)

Invoke the error

test1 <- mae
test1$sel <- rep(c(TRUE, FALSE), each = 2)
test1 <- subsetByColData(test1, test1$sel)
validObject(test1)
Error in validObject(test1) : 
  invalid class “MultiAssayExperiment” object: 
    All 'sampleMap[[primary]]' must be in 'rownames(colData)'

Notes

I could not find a solution to the issue, but have 2 observations that may guide debugging:

  1. I have noticed the issue after executing code that previously (a few months ago) ran without issues.
  2. A similar example where assays are not dropped works perfectly.
test2 <- mae
test2$sel <- rep(c(TRUE, FALSE), 2)
test2 <- subsetByColData(test2, test2$sel)
validObject(test2)
[1] TRUE
LiNk-NY commented 2 years ago

Hi @cvanderaa Thanks for reporting. The issue was related to how the sampleMap was generated when no colData rownames were found in the other assay. It should be fixed now and I've added unit tests. Best regards, Marcel

cvanderaa commented 2 years ago

Hi Marcel, As always, thank you very much for the quick fix! :pray: