[Bioc-devel] error when combining objects inheriting from GRangesList

Leonard Goldstein goldstein.leonard at gene.com
Fri Dec 4 18:43:21 CET 2015


Hi all,

In the latest Bioc release (and devel) I encountered problems with
classes inheriting from GRangesList. Combining two or more objects
that belong to such classes can result in an error, as the combined
object is apparently not recognized as a valid instance of the class.
I included an example below. Thanks in advance for your help.

Leonard

--
> library(GenomicRanges)
>
> validNewClass <- function(object) {
+
+   if (!"ID" %in% names(mcols(object))) {
+
+     return("missing metadata column ID")
+
+   }
+
+ }
>
> setClass(
+   Class = "newClass",
+   contains = "GRangesList",
+   validity = validNewClass)
>
> gr <- GRanges(1, IRanges(1, 100))
> grl <- split(gr, 1)
> mcols(grl)$ID <- 1
> x <- new("newClass", grl)
>
> ## combining two instances of newClass results in an error
> c(x, x)
Error in validObject(.Object) :
  invalid class “newClass” object: missing metadata column ID
>
> ## but can create an instance after combining as GRangesLists
> new("newClass", c(as(x, "GRangesList"), as(x, "GRangesList")))
newClass object of length 2:
$1
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]        1  [1, 100]      *

$1
GRanges object with 1 range and 0 metadata columns:
      seqnames   ranges strand
  [1]        1 [1, 100]      *

-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
>
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.6 (Santiago)

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] stats4    parallel  stats     graphics  grDevices utils     datasets
[8] methods   base

other attached packages:
[1] GenomicRanges_1.22.1 GenomeInfoDb_1.6.1   IRanges_2.4.4
[4] S4Vectors_0.8.3      BiocGenerics_0.16.1

loaded via a namespace (and not attached):
[1] zlibbioc_1.16.0 XVector_0.10.0
>



More information about the Bioc-devel mailing list