[Bioc-devel] dimnames of multidimensional assays in SummarizedExperiment
Hervé Pagès
hpages at fredhutch.org
Tue Feb 16 08:48:22 CET 2016
Hi Pete,
I'll look into this. Thanks!
H.
On 02/10/2016 12:33 PM, Peter Hickey wrote:
> 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
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fredhutch.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the Bioc-devel
mailing list