Skip to content
Prev 6313 / 21312 Next

[Bioc-devel] GenomicFiles: some random issues

Just to support Kasper's proposal, I see this as being broadly useful.


It's really common to be dealing with an object (say, a
SummarizedExperiment-derived doohickey, or a transcriptDb-looking whatzit,
or "bumps", or "dmrcoutput") that has metadata which "looks like" a
GRanges.  More often than not, a generic like

## standardGeneric for "granges" defined from package "GenomicRanges"
granges <- function (x, use.mcols = FALSE, ...) { ... }

gets defined in some derived class and the GenomicRanges generic
specialized to the class.  Or sometimes because of S3-to-S4 impedance
mismatch you instead get

## DMRcate results
setClass('dmrcate.output')
setMethod('granges', 'dmrcate.output', function(x, ...) extractRanges(x) )

but the bottom line is that for all of these "things", if they contain a
virtual class like "bsseq::hasGRanges", it enables semi-automatic
extraction of their associated GRanges via the already-in-GenomicRanges
granges() generic.  It seems handy to me, after writing some ungodly number
of kludges to do similar things (see above).

So if ::hasGranges could go into GenomicRanges or biobase or whatever as an
abstract/virtual base class from which to inherit, with a mandatory method
(is it possible to mandate a method for an S4 class?  been a while for me),
then people who just want their intervals could reliably get them from
output that hasGranges.

## what usually seems to happen
foo <- emitWackyClassThatHasSomethingResemblingAGRangesAttachedToIt(x, y, z)

## the part that would be nice
granges(foo) ## since the author made WackyClass contain "hasGranges"

bsseq::hasGranges already defines a number of methods along these lines.
More concretely, and stolen directly from bsseq/R/BSseqTstat_class.R:

setClass("BSseqTstat", contains = "hasGRanges",
         representation(stats = "matrix",
                        parameters = "list")
         )
setValidity("BSseqTstat", function(object) {
    msg <- NULL
    if(length(object at gr) != nrow(object at stats))
        msg <- c(msg, "length of 'gr' is different from the number of rows
of 'stats'")
    if(is.null(msg)) TRUE else msg
})

That's pretty handy and could stand to be in a very fundamental library
IMHO.



Statistics is the grammar of science.
Karl Pearson <http://en.wikipedia.org/wiki/The_Grammar_of_Science>
On Mon, Sep 29, 2014 at 12:58 PM, Martin Morgan <mtmorgan at fhcrc.org> wrote: