waldronlab / MultiAssayExperiment

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

Error when combining 2 MAE objects that have 1 column in colData #315

Closed cvanderaa closed 2 years ago

cvanderaa commented 2 years ago

Hello Marcel, @LiNk-NY

I noticed a little bug when trying to combine 2 MAE objects. It works in most cases, but when one of the MAE objects has only 1 column in the colData, I run into an error. See this example:

arraydat <- matrix(data = seq(101, length.out = 20), ncol = 4,
                   dimnames = list(NULL, letters[1:4]))
mae1 <- MultiAssayExperiment(ExperimentList(exp1 = SummarizedExperiment(arraydat),
                                            exp2 = SummarizedExperiment(arraydat)))
mae2 <- MultiAssayExperiment(ExperimentList(exp3 = SummarizedExperiment(arraydat)))

c(mae1, mae2)

This works fine when there is no colData. But when I add a single mock column, it fails:

mae1$foo <- "bar"
c(mae1, mae2)
Error in validObject(.Object) : 
invalid class “MultiAssayExperiment” object: invalid object for slot "colData" in class "MultiAssayExperiment": got class "character", should be or extend class "DataFrame"

But the error disappears when adding a second mock column:

mae1$foo2 <- "bar2"
c(mae1, mae2)

I would say there is a missing drop = FALSE in .mergeMAE(). I could indeed fix the issue on my fork: https://github.com/cvanderaa/MultiAssayExperiment/commit/ee6b70213b869a7556bf8efd7f00b929b8518529

Let me know if you want me to send a PR.

LiNk-NY commented 2 years ago

Hi @cvanderaa

Sorry I didn't see your fork. I added the fix and some unit tests based on your example. Thank you!

Best, Marcel

cvanderaa commented 2 years ago

No problem for the fork. Thanks a lot for the fix and your fast response, as usual!