[Bioc-devel] dimnames of multidimensional assays in SummarizedExperiment

Peter Hickey peter.hickey at gmail.com
Wed Feb 10 21:33:23 CET 2016


The assays slot in a SummarizedExperiment object supports elements
with up to 4 dimensions [*]

library(SummarizedExperiment)
makeSE <- function(n) {
  assay <- array(1:2^n,
                 dim = rep(2, n),
                 dimnames = split(letters[1:(2 * n)], seq_len(n)))
  SummarizedExperiment(assay)
}
x <- makeSE(4)

However, the "higher-order" dimnames of the assays aren't preserved
when calling the `assays` or `assay` getters:

> dimnames(assay(x, withDimnames = TRUE))
[[1]]
[1] "a" "e"

[[2]]
[1] "b" "f"

[[3]]
NULL

[[4]]
NULL

This is despite the data still being available in the assays slot:

> dimnames(x at assays[[1]])
1`
[1] "a" "e"

2`
[1] "b" "f"

3`
[1] "c" "g"

4`
[1] "d" "h"

The following patch fixes this by only touching the rownames and
colnames and not touching the "higher-order" dimnames. Seem
reasonable?

Index: R/SummarizedExperiment-class.R
===================================================================
  --- R/SummarizedExperiment-class.R (revision 113505)
+++ R/SummarizedExperiment-class.R (working copy)
@@ -174,7 +174,10 @@
{
  assays <- as(x at assays, "SimpleList")
  if (withDimnames)
    -        endoapply(assays, "dimnames<-", dimnames(x))
  + endoapply(assays, function(assay) {
    +                    dimnames(assay)[1:2] <- dimnames(x)
    +                    assay
    +                })
  else
    assays
})

[*] In fact, the assay elements can have more than 4 dimensions when
constructed, although subsetting with `[` isn't supported (possibly
things other than subsetting break as well in this case).

# No error
y <- makeSE(5)
y

# Error
y[1, ]

Perhaps there should be a check in the constructor that all assay
elements have < 5 dimensions?

Cheers,
Pete



More information about the Bioc-devel mailing list