Bioconductor / SummarizedExperiment

SummarizedExperiment container
https://bioconductor.org/packages/SummarizedExperiment
29 stars 9 forks source link

`combineCols` should keep names in metadata with `use.names=TRUE` #66

Open LTLA opened 1 year ago

LTLA commented 1 year ago

I'm not quite sure why I did this, but the current code at

https://github.com/Bioconductor/SummarizedExperiment/blob/8df97720354bdeecaf947f574dddd09da02d55b2/R/combine-methods.R#L244

wipes out the names of the metadata list, e.g.,

example(SummarizedExperiment, verbose=FALSE)
metadata(se) <- list(A=1, B=2, C=3)
rownames(se) <- seq_len(nrow(se))
combined <- combineCols(se, se)
metadata(combined)
## [[1]]
## [1] 1
## 
## [[2]]
## [1] 2
## 
## [[3]]
## [1] 3
## 
## [[4]]
## [1] 1
## 
## [[5]]
## [1] 2
## 
## [[6]]
## [1] 3

Oops. Same issue affects both SEs and RSEs at their respective methods.

It should be easily fixable by just doing something like this:

all.meta <- lapply(all.se, metadata)
names(all.meta) <- NULL # or unname, I suppose
combined.meta <- unlist(all.meta, recursive=FALSE)

And then using that in the args list. This eliminates the names from the argument list of combineCols(...), while preserving the list names inside the metadata() for each SE. This gives a relatively nicer:

metadata(combined)
## $A
## [1] 1
## 
## $B
## [1] 2
## 
## $C
## [1] 3
## 
## $A
## [1] 1
## 
## $B
## [1] 2
## 
## $C
## [1] 3

Duplicate names... oh well, we'll just have to put up with it.