[Bioc-devel] conflict rowRanges SummarizedExperiment/matrixStats

Vincent Carey stvjc at channing.harvard.edu
Thu Apr 6 12:11:46 CEST 2017


I am sure there are better responses to come, but here are a few initial
comments.

On Thu, Apr 6, 2017 at 5:42 AM, Maarten van Iterson <mviterson at gmail.com>
wrote:

> Dear all,
>
> SummarizedExperiment and matrixStats both contain a method/function called
> rowRanges one operates on a SummarizedExperiment-object the other on a
> matrix. matrixStats is required by SummarizedExperiment, or a package it is
> depending on, so rowRanges is masked when loading SummarizedExperiment.
>
> I thought a function/method is called depended on the type of the object;
>

There are at least two interpretations of this.  If a function that is an
S3 generic is called on an entity whose class corresponds to an existing
method, that method will be invoked.  If a function that is an S4 generic
is called with (a sequence of) arguments corresponding to a method with
signature equivalent to the sequence of classes of the arguments, that
method will be invoked.  In matrixStats, rowRanges is just a first level
function, and will be invoked directly on anything that is passed -- e.g.,
rowRanges(4) is just an error, when matrixStats alone is loaded.

matrix or SummarizedExperiment-object, such that functions/methods with the
> same name can coexist. However, this doesn't seems to work for rowRanges.
> The only way to access rowRanges from matrixStats when SummarizedExperiment
> is already loaded is using the double colon operator
> matrixStats::rowRanges. Is this intentional or is there a other way to
> solve this?
>
> Regards,
> Maarten
>
> Here is a small example showing the issue:
>
> > library(SummarizedExperiment)
> Loading required package: matrixStats
> matrixStats v0.51.0 (2016-10-08) successfully loaded. See ?matrixStats for
> help.
> Attaching package: ‘matrixStats’
> Attaching package: ‘SummarizedExperiment’
> The following object is masked from ‘package:matrixStats’:
>     rowRanges
> > nrows <- 200; ncols <- 6
> > counts <- matrix(runif(nrows * ncols, 1, 1e4), nrows)
> > rowRanges <- GRanges(rep(c("chr1", "chr2"), c(50, 150)),
> +                      IRanges(floor(runif(200, 1e5, 1e6)), width=100),
> +                      strand=sample(c("+", "-"), 200, TRUE),
> +                      feature_id=sprintf("ID%03d", 1:200))
> > colData <- DataFrame(Treatment=rep(c("ChIP", "Input"), 3),
> +                      row.names=LETTERS[1:6])
> > rse <- SummarizedExperiment(assays=SimpleList(counts=counts),
> +                             rowRanges=rowRanges, colData=colData)
> >
> > rowRanges(rse)
> GRanges object with 200 ranges and 1 metadata column:
>         seqnames           ranges strand |  feature_id
>            <Rle>        <IRanges>  <Rle> | <character>
>     [1]     chr1 [858613, 858712]      - |       ID001
> >
> > rowRanges(counts)
> Error in (function (classes, fdef, mtable)  :
>   unable to find an inherited method for function ‘rowRanges’ for signature
> ‘"matrix"’
> >
> > library(matrixStats) ##it is already loading so this doesn't alter the
>

Actually in this case matrixStats is loaded and attached.  Sometimes the
difference is significant.


> search path
> >
> > rowRanges(rse)
> GRanges object with 200 ranges and 1 metadata column:
>         seqnames           ranges strand |  feature_id
>            <Rle>        <IRanges>  <Rle> | <character>
>     [1]     chr1 [858613, 858712]      - |       ID001
> > rowRanges(counts)
> Error in (function (classes, fdef, mtable)  :
>   unable to find an inherited method for function ‘rowRanges’ for signature
> ‘"matrix"’
>

So -- we got a warning when there was a collision in namespaces, when
SummarizedExperiment was attached, and an indication that rowRanges is an
S4 generic when we encountered the error.  When should we introduce
the method

setMethod("rowRanges", "matrix", function(x, ...) matrixStats::rowRanges(x,
...))

that would foster the behavior I think you are looking for?


>
> > head(matrixStats::rowRanges(counts))
>            [,1]     [,2]
> [1,]   51.27791 9350.048
> [2,] 1417.41010 8272.040
> > sessionInfo()
> R Under development (unstable) (2016-08-25 r71150)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Ubuntu 14.04.5 LTS
>
> 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=en_US.UTF-8       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  stats4    stats     graphics  grDevices utils     datasets
> [8] methods   base
>
> other attached packages:
> [1] SummarizedExperiment_1.5.7 DelayedArray_0.1.7
> [3] matrixStats_0.51.0         Biobase_2.35.1
> [5] GenomicRanges_1.27.23      GenomeInfoDb_1.11.10
> [7] IRanges_2.9.19             S4Vectors_0.13.15
> [9] BiocGenerics_0.21.3
>
> loaded via a namespace (and not attached):
> [1] lattice_0.20-34         bitops_1.0-6            grid_3.4.0
> [4] zlibbioc_1.21.0         XVector_0.15.2          Matrix_1.2-8
> [7] RCurl_1.95-4.8          GenomeInfoDbData_0.99.0
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel

	[[alternative HTML version deleted]]



More information about the Bioc-devel mailing list