[Bioc-devel] ExpressionSet and LumiBatch: inheritance problem in S4 methods for union class
Martin Morgan
mtmorgan at fhcrc.org
Tue May 7 18:55:35 CEST 2013
On 05/07/2013 04:04 AM, Renaud Gaujoux wrote:
> Hi,
>
> I am getting an error when calling an S4 method, which is defined for a
> union class that includes ExpressionSet, on a LumiBatch object:
>
> The error prototype is as follows:
>
> - 'A' is Union of 'B' and 'C'
> - 'D' extends 'C'
> - a method myfun() exists for class 'A'
> => myfun('C') works but not myfun('D')
>
> Error is like:
> Error in (function (classes, fdef, mtable) :
> unable to find an inherited method for function ‘myfun’ for signature
> ‘"D"’
>
> This works well on a toy example, but breaks when ExpressionSet are
> involved.
> So, I don't know if this is an R problem or something related to class
> ExpressionSet, or possibly LumiBatch (I Cc Pan Du for this reason). I
> remember that a while ago I was getting such errors even when defining the
> method for ExpressionSet and calling it on LumiBatch objects.
I can replicate this with a simpler example, where PkgA has
setClass("A", representation(x="numeric"))
with NAMESPACE
import(methods)
exportClasses("A")
PkgB has
setClass("B", contains="A")
NAMESPACE
import(methods)
importClassesFrom("PkgA", "A")
exportClasses("B")
and then
library(PkgA); library(PkgB)
setClassUnion("C", c("matrix", "A"))
setGeneric("do", function(x) standardGeneric("do"))
setMethod("do", "C", function(x) "done")
leading to
> do(new("A"))
[1] "done"
> do(new("B"))
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘do’ for signature ‘"B"’
suggesting name space issues rather than something about ExpressionSet. The
sample packages and test script are attached; it would be appropriate to pursue
this on the R-devel mailing list.
Martin
>
> Thank you for any help.
>
> Bests,
> Renaud
>
> ##############################
> # Toy example:
> ##############################
>
> R --vanilla --quiet <<EOF
>
> setClass('B', contains = 'character')
> setClass('C', contains = 'character')
> setClass('D', contains = 'C')
> setClassUnion('A', c('B', 'C'))
>
> setGeneric('myfun', function(x, ...) standardGeneric('myfun'))
> setMethod('myfun', 'A', function(x) print(class(x)) )
>
> # works on C
> myfun(new('C'))
>
> # works on D
> try( myfun(new('D')) )
>
> # seems that inherits does not catch the inheritance
> d <- new('D')
> is(d, 'A')
> inherits(d, 'A')
> extends(class(d), 'A')
> EOF
>
> ## OUTPUT FOR TOY EXAMPLE
>
>> setClass('B', contains = 'character')
>> setClass('C', contains = 'character')
>> setClass('D', contains = 'C')
>> setClassUnion('A', c('B', 'C'))
>>
>> setGeneric('myfun', function(x, ...) standardGeneric('myfun'))
> [1] "myfun"
>> setMethod('myfun', 'A', function(x) print(class(x)) )
> [1] "myfun"
>>
>> # works on C
>> myfun(new('C'))
> [1] "C"
> attr(,"package")
> [1] ".GlobalEnv"
>>
>> # works on D
>> try( myfun(new('D')) )
> [1] "D"
> attr(,"package")
> [1] ".GlobalEnv"
>>
>> # seems that inherits does not catch the inheritance
>> d <- new('D')
>> is(d, 'A')
> [1] TRUE
>> inherits(d, 'A')
> [1] TRUE
>> extends(class(d), 'A')
> [1] TRUE
>>
>
>
> #####################################################
> # Concrete example with ExpressionSet and LumiBatch objects:
> #####################################################
>
> ### RUN
>
> R --vanilla <<EOF
> library(Biobase)
> setGeneric('myfun', function(x, ...) standardGeneric('myfun'))
> setClassUnion('A', c('matrix', 'ExpressionSet'))
> setMethod('myfun', 'A', function(x){
> print(class(x))
> })
>
> # works on ExpressionSet
> data(sample.ExpressionSet)
> myfun(sample.ExpressionSet)
>
> # not working on LumiBatch
> library(lumi)
> data(example.lumi)
> try( myfun(example.lumi) )
>
> # seems that inherits does not catch the inheritance
> is(example.lumi, 'A')
> inherits(example.lumi, 'A')
> extends(class(example.lumi), 'A')
>
> # define method for ExpressionSet ?
> setMethod('myfun', 'ExpressionSet', function(x){
> message('ExpressionSet method')
> print(class(x))
> })
>
> # works well
> myfun(sample.ExpressionSet)
> myfun(example.lumi)
>
> # Session info
> sessionInfo()
> EOF
>
>
> ##################
> #### OUTPUT FOR EXPRESSIONSET
> ##################
>
> R version 3.0.0 (2013-04-03) -- "Masked Marvel"
> Copyright (C) 2013 The R Foundation for Statistical Computing
> Platform: i686-pc-linux-gnu (32-bit)
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
>
> Natural language support but running in an English locale
>
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications.
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
>> library(Biobase)
> Loading required package: BiocGenerics
> Loading required package: parallel
>
> Attaching package: ‘BiocGenerics’
>
> The following objects are masked from ‘package:parallel’:
>
> clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
> clusterExport, clusterMap, parApply, parCapply, parLapply,
> parLapplyLB, parRapply, parSapply, parSapplyLB
>
> The following object is masked from ‘package:stats’:
>
> xtabs
>
> The following objects are masked from ‘package:base’:
>
> anyDuplicated, as.data.frame, cbind, colnames, duplicated, eval,
> Filter, Find, get, intersect, lapply, Map, mapply, match, mget,
> order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
> rbind, Reduce, rep.int, rownames, sapply, setdiff, sort, table,
> tapply, union, unique, unlist
>
> Welcome to Bioconductor
>
> Vignettes contain introductory material; view with
> 'browseVignettes()'. To cite Bioconductor, see
> 'citation("Biobase")', and for packages 'citation("pkgname")'.
>
>> setGeneric('myfun', function(x, ...) standardGeneric('myfun'))
> [1] "myfun"
>> setClassUnion('A', c('matrix', 'ExpressionSet'))
>> setMethod('myfun', 'A', function(x){
> + print(class(x))
> + })
> [1] "myfun"
>>
>> # works on ExpressionSet
>> data(sample.ExpressionSet)
>> myfun(sample.ExpressionSet)
> [1] "ExpressionSet"
> attr(,"package")
> [1] "Biobase"
>>
>> # not working on LumiBatch
>> library(lumi)
> KernSmooth 2.23 loaded
> Copyright M. P. Wand 1997-2009
> Warning messages:
> 1: replacing previous import ‘image’ when loading ‘graphics’
> 2: replacing previous import ‘nleqslv’ when loading ‘nleqslv’
>> data(example.lumi)
>> try( myfun(example.lumi) )
> Error in (function (classes, fdef, mtable) :
> unable to find an inherited method for function ‘myfun’ for signature
> ‘"LumiBatch"’
>>
>> # seems that inherits does not catch the inheritance
>> is(example.lumi, 'A')
> [1] TRUE
>> inherits(example.lumi, 'A')
> [1] FALSE
>> extends(class(example.lumi), 'A')
> [1] TRUE
>>
>> # define method for ExpressionSet ?
>> setMethod('myfun', 'ExpressionSet', function(x){
> + message('ExpressionSet method')
> + print(class(x))
> + })
> [1] "myfun"
>>
>> # works well
>> myfun(sample.ExpressionSet)
> ExpressionSet method
> [1] "ExpressionSet"
> attr(,"package")
> [1] "Biobase"
>> myfun(example.lumi)
> ExpressionSet method
> [1] "LumiBatch"
> attr(,"package")
> [1] "lumi"
>>
>> # Session info
>> sessionInfo()
> R version 3.0.0 (2013-04-03)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=C LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] parallel stats graphics grDevices utils datasets methods
> [8] base
>
> other attached packages:
> [1] lumi_2.12.0 Biobase_2.20.0 BiocGenerics_0.6.0
>
> loaded via a namespace (and not attached):
> [1] affy_1.38.1 affyio_1.28.0 annotate_1.38.0
> [4] AnnotationDbi_1.22.5 beanplot_1.1 BiocInstaller_1.10.1
> [7] Biostrings_2.28.0 colorspace_1.2-2 DBI_0.2-6
> [10] GenomicRanges_1.12.2 grid_3.0.0 illuminaio_0.2.0
> [13] IRanges_1.18.0 KernSmooth_2.23-10 lattice_0.20-15
> [16] limma_3.16.3 MASS_7.3-26 Matrix_1.0-12
> [19] matrixStats_0.8.1 mclust_4.1 methylumi_2.6.1
> [22] mgcv_1.7-22 minfi_1.6.0 multtest_2.16.0
> [25] nleqslv_2.0 nlme_3.1-109 nor1mix_1.1-4
> [28] preprocessCore_1.22.0 RColorBrewer_1.0-5 reshape_0.8.4
> [31] R.methodsS3_1.4.2 RSQLite_0.11.3 siggenes_1.34.0
> [34] splines_3.0.0 stats4_3.0.0 survival_2.37-4
> [37] tools_3.0.0 XML_3.96-1.1 xtable_1.7-1
> [40] zlibbioc_1.6.0
>
> [[alternative HTML version deleted]]
>
>
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109
Location: Arnold Building M1 B861
Phone: (206) 667-2793
More information about the Bioc-devel
mailing list