I found out a possible bug from SE constructor.
library(SummarizedExperiment)
# assay data
counts <- rbind(rep(0, 3), matrix(1:9, nrow = 3))
colnames(counts) <- paste0("sample", 1:3)
rownames(counts) <- paste0("OTU", seq_len(4))
# row data
rowData <- data.frame(Species = rep(c("S1", "S2"), each = 2),
row.names = rownames(counts),
stringsAsFactors = FALSE)
# col data
colData <- DataFrame(Treatment=c("X", "X", "Y"),
row.names=colnames(counts))
# Modify the order of samples in assay data
counts_sample_mod <- counts[, c("sample2", "sample3", "sample1")]
# Modify the order of features in assay data
counts_feat_mod <- counts[c( "OTU2", "OTU4", "OTU1", "OTU3"), ]
# Create three different SE objects, which have differently ordered assay data
se <- SummarizedExperiment(assays=SimpleList(counts=counts),
colData=colData,
rowData = rowData)
se_sample_mod <- SummarizedExperiment(assays=SimpleList(counts=counts_sample_mod),
colData=colData,
rowData = rowData)
se_feat_mod <- SummarizedExperiment(assays=SimpleList(counts=counts_feat_mod),
colData=colData,
rowData = rowData)
# Sample and feature names are ordered based on colData and rowData.
# However, values are not ordered correspondingly.
# Original
counts
assay(se, "counts")
# Samples modified
counts_sample_mod
assay(se_sample_mod, "counts")
# Features modified
counts_feat_mod
assay(se_feat_mod, "counts")
> # Original
> counts
sample1 sample2 sample3
OTU1 0 0 0
OTU2 1 4 7
OTU3 2 5 8
OTU4 3 6 9
> assay(se, "counts")
sample1 sample2 sample3
OTU1 0 0 0
OTU2 1 4 7
OTU3 2 5 8
OTU4 3 6 9
> # Samples modified
> counts_sample_mod
sample2 sample3 sample1
OTU1 0 0 0
OTU2 4 7 1
OTU3 5 8 2
OTU4 6 9 3
> assay(se_sample_mod, "counts")
sample1 sample2 sample3
OTU1 0 0 0
OTU2 4 7 1
OTU3 5 8 2
OTU4 6 9 3
> # Features modified
> counts_feat_mod
sample1 sample2 sample3
OTU2 1 4 7
OTU4 3 6 9
OTU1 0 0 0
OTU3 2 5 8
> assay(se_feat_mod, "counts")
sample1 sample2 sample3
OTU1 1 4 7
OTU2 3 6 9
OTU3 0 0 0
OTU4 2 5 8