1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
M1 <- matrix(1, 5, 3, dimnames=list(NULL, NULL))
M2 <- matrix(1, 3, 3, dimnames=list(NULL, NULL))
assaysList <- list(gr=SimpleList(m=M1), grl=SimpleList(m=M2))
rowRangesList <-
list(gr=GRanges("chr1", IRanges(1:5, 10)),
grl=split(GRanges("chr1", IRanges(1:5, 10)), c(1,1,2,2,3)))
names(rowRangesList[["grl"]]) <- NULL
colData <- DataFrame(x=letters[1:3])
## a list of one SE with GRanges and one with GRangesList
rseList <-
list(SummarizedExperiment(
assays=assaysList[["gr"]],
rowRanges=rowRangesList[["gr"]],
colData=colData),
SummarizedExperiment(
assays=assaysList[["grl"]],
rowRanges=rowRangesList[["grl"]],
colData=colData))
test_SummarizedExperiment_GenomicRanges_coercion <- function()
{
eset1 <- ExpressionSet()
checkTrue(validObject(eset1))
se1 <- as(eset1, "RangedSummarizedExperiment")
checkTrue(validObject(se1))
data("sample.ExpressionSet", package = "Biobase")
eset2 <- sample.ExpressionSet
checkTrue(validObject(eset2))
se2 <- as(eset2, "RangedSummarizedExperiment")
checkTrue(validObject(se2))
checkIdentical(experimentData(eset2),
metadata(se2)$experimentData)
checkIdentical(annotation(eset2),
metadata(se2)$annotation)
checkIdentical(protocolData(eset2),
metadata(se2)$protocolData)
eset2Assays <- SimpleList(as.list(assayData(eset2)))
se2Assays <- assays(se2)
checkIdentical(eset2Assays$exprs, se2Assays$exprs)
checkIdentical(eset2Assays$se.exprs, se2Assays$se.exprs)
checkIdentical(featureNames(eset2), rownames(se2))
checkIdentical(sampleNames(eset2), colnames(se2))
}
test_GenomicRanges_SummarizedExperiment_coercion <- function()
{
## empty SE
simpleSE <- SummarizedExperiment()
eset1 <- as(simpleSE, "ExpressionSet")
checkTrue(validObject(eset1))
## Back and forth empty ES
simpleES <- ExpressionSet()
simpleES2 <- as(as(simpleES, "RangedSummarizedExperiment"),
"ExpressionSet")
checkTrue(validObject(simpleES2))
checkEquals(as.list(assayData(simpleES)),
as.list(assayData(simpleES2)))
## Simple SE
simpleSE <- rseList[[1]]
assayNames(simpleSE) <- "exprs" # No warning 'No assay named exprs..."
eset2 <- as(simpleSE, "ExpressionSet")
checkTrue(validObject(eset2))
## The ExpressionSet features should have the data from the
## SummarizedExperiment rows if they are from GRanges.
checkIdentical(pData(featureData(eset2)),
as.data.frame(rowRanges(rseList[[1]])))
# the rowRanges are retained if the object has them to begin with.
se2_2 <- as(eset2, "RangedSummarizedExperiment")
rr_se2_2 <- unname(rowRanges(se2_2))
rr_eset2 <- rowRanges(rseList[[1]])
checkEquals(rr_se2_2, rr_eset2)
simpleSE <- rseList[[2]]
assayNames(simpleSE) <- "exprs" # No warning 'No assay named exprs..."
eset3 <- as(simpleSE, "ExpressionSet")
checkTrue(validObject(eset3))
## The ExpressionSet features should not have the data from the
## SummarizedExperiment rows if they are from GRangesList, but they
## should be empty and the same length as the number of ranges.
checkEquals(unname(NROW(featureData(eset3))),
unname(length(rowRanges(rseList[[2]]))))
data("sample.ExpressionSet", package = "Biobase")
eset4 <- sample.ExpressionSet
eset5 <- as(as(eset4, "RangedSummarizedExperiment"), "ExpressionSet")
checkTrue(validObject(eset5))
## this is necessary because the order in environments is undefined.
compareLists <- function(x, y) {
nmsX <- names(x)
nmsY <- names(y)
reorderY <- match(nmsY, nmsX)
checkIdentical(x, y[reorderY])
}
compareLists(as.list(assayData(eset4)),
as.list(assayData(eset5)))
checkIdentical(experimentData(eset4),
experimentData(eset5))
checkIdentical(annotation(eset4),
annotation(eset5))
checkIdentical(protocolData(eset4),
protocolData(eset5))
checkIdentical(featureNames(eset4),
featureNames(eset5))
checkIdentical(sampleNames(eset4),
sampleNames(eset5))
}
|