R/WindowedSummarizedExperiment.R

Defines functions .valid.WindowedSummarizedExperiment

##' WindowedSummarizedExperiment
##'
##' The WindowedSummarizedExperiment class extends the
##' RangedSummarizedExperiment class and adds a requirement that the
##' rowRanges are windows of specified length. The rowRanges object is
##' a Windows object which is an extension of GRanges.
##'
##' @author Per Unneberg
##'
##' @import SummarizedExperiment
##'
setClass("WindowedSummarizedExperiment", contains = c("RangedSummarizedExperiment"))


.valid.WindowedSummarizedExperiment <- function(object) {
    if (length(object)) {
        if (!inherits(rowRanges(object), "Windows")) {
            txt <- sprintf("The rowRanges of a WindowedSummarizedExperiment must inherit from the Windows class")
            return(txt)
        }
    }
    NULL
}


setValidity("WindowedSummarizedExperiment", .valid.WindowedSummarizedExperiment)


setGeneric("WindowedSummarizedExperiment",
           function(assays, ...) standardGeneric("WindowedSummarizedExperiment"))


##' WindowedSummarizedExperiment
##'
##' WindowedSummarizedExperiment initialization function
##'
##' @param ... options to be passed to RangedSummarizedExperiment
##'
##' @return WindowedSummarizedExperiment object
##'
##' @author Per Unneberg
##'
setMethod("WindowedSummarizedExperiment", "SimpleList",
          function(assays, ...) {
    rse <- SummarizedExperiment(assays, ...)
    if (!is(rse, "RangedSummarizedExperiment"))
        stop("WindowedSummarizedExperiment must be setup as a RangedSummarizedExperiment")
    wse <- as(rse, "WindowedSummarizedExperiment")
    wse
})
percyfal/nonmodelr documentation built on Sept. 11, 2019, 10:38 a.m.