Skip to content

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

2 messages · Hervé Pagès, Leonard Goldstein

#
Hi Leonard,
On 12/04/2015 09:43 AM, Leonard Goldstein wrote:
A lot of code in the S4Vectors/IRanges/GenomicRanges infrastructure
needs to create temporarily invalid objects for various reasons. At
the lowest level we use S4Vectors::new2(..., check=FALSE) for that.
Unlike methods::new(), which always validates the new object, new2()
only validates it if 'check' is set to TRUE.
However new2() is only able to to this if the validity method for the
object was defined using setValidity2(), also defined in the S4Vectors
package. If you build on top of the S4Vectors/IRanges/GenomicRanges
infrastructure, please always use setValidity2():

   library(GenomicRanges)

   setClass("newClass", "GRangesList")

   setValidity2("newClass",
     function(object) {
       if (!("ID" %in% names(mcols(object))))
         return("missing metadata column ID")
       NULL
     }
   )

   gr <- GRanges("1:1-100")
   grl <- split(gr, 1)
   mcols(grl)$ID <- 1
   x <- new("newClass", grl)

Then:

   > c(x, x)
   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
This works because the validity method for GRangesList objects is set
with setValidity2().

I wish new() had the extra 'check' argument so we wouldn't need to use
the new2/setValidity2 hack.

Hope this helps,
H.

  
    
#
Hi Herv?,

OK thanks for the workaround and the quick reply.

Best wishes,

Leonard
On Fri, Dec 4, 2015 at 10:41 AM, Herv? Pag?s <hpages at fredhutch.org> wrote: