[BioC] Confusion over inconsistencies with showMethods('Rle') when loaded via GenomicRanges

Steve Lianoglou mailinglist.honeypot at gmail.com
Thu Jan 31 13:40:53 CET 2013


Hi Pete,

On Thu, Jan 31, 2013 at 3:22 AM,  <hickey at wehi.edu.au> wrote:
[snip]
> Here's what I'm trying to accomplish with a setClassUnion(). I've based my
> class on the 'BSseq' class in the 'bsseq' package; partly for didactic
> purposes (it always helps me to have something to work-off when getting
> started with a new programming concept) and partly because I'm also dealing
> with BS-seq data. My reason for using a 'setClassUnion("vectorOrNULL'",
> c("vector", "NULL"))' is that for some of the slots the values aren't
> defined (i.e. they are NULL) when my object is first created; rather they
> are defined by a subsequent function call.
>
> In pseudo-code it goes something like this:
>> library(GenomicRanges)
>> setClassUnion("vectorOrNULL'",  c("vector", "NULL"))
>> setClass('MyClass", representation(gr = "GRanges", model_parameters =
>> "vectorOrNULL"))
>> in <- read_input_file(some_input_file)
>> in_gr <- input_file_to_GRanges(in) # Convert 'in' to a GRanges object
>> in_my_class <- MyClass(gr = in_gr, model_parameters = NULL)
> ## At this point, is.null(in_my_class at model_parameters) == TRUE
> ## Now, some modelling is done based on 'in_my_class'.
> in_my_class_modelled <- modeling_function(in_my_class) ## This function
> returns a MyClass object, with the 'model_parameters' slot now filled by a
> vector of model parameters.
> ## At this point, is.null(in_my_class at model_parameters) == TRUE, whereas,
> is.null(in_my_class_modelled at model_parameters) == FALSE
>
> Basically, I'd really like to have the model_parameters in the same MyClass
> object as the raw data (along with some other things, like sampleName etc.)
> but these aren't available at the point when the MyClass object is first
> constructed. The 'modelling_function()' returns a new MyClass object, with
> the 'gr' slot copied from the input 'in_my_class' and the 'model_parameters'
> slot filled by a vector rather than a NULL.

I see what you're trying to do -- and I believe I've done this once or
twice before myself (which is to use NULL as a place holder under a
later call initializes the slot) ... luckily I somehow I never got
kicked by the bug/behavior you found.

Perhaps in this case, you can just set your `model_parameters` slot to
`numeric`, and during the initialization/construction of your object,
assign NA_real_ as its slot value, or more simply `numeric()` (a
zero-length numeric vector).

In this way, you still have a delimiter that indicates this slot is
yet to be initialized w/ a proper variable, but you are still using an
object of a `numeric` class to do so -- no class-union's necessary.

Would that work for you?

HTH,
-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the Bioconductor mailing list