[Bioc-devel] S4 classes extending GRangesList

Leonard Goldstein goldstein.leonard at gene.com
Thu Jun 11 19:48:24 CEST 2015


Hi all,

I noticed that when combining instances of a class that inherits from
GRangesList, the result does not preserve the class (it is returned as
a GRangesList instead). The class is preserved in other situations
(e.g. when a class extends GRanges). See below for an example. Is
there a reason why the class cannot be preserved in the first case?
Thanks in advance for your help.

Leonard


> ## define a new class 'A' inheriting from GRanges
> setClass(Class = "A", contains = "GRanges")
>
> ## combining two instances of class 'A' returns an object of class 'A'
> gr <- GRanges("1", IRanges(1, 100))
> a <- new("A", gr)
> a
A object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]        1  [1, 100]      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
> c(a, a)
A object with 2 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]        1  [1, 100]      *
  [2]        1  [1, 100]      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
>
> ## define a new class 'b' inheriting from GRangesList
> setClass(Class = "B", contains = "GRangesList")
>
> ## combining two instances of class 'B' returns a GRangesList
> grl <- split(gr, 1)
> b <- new("B", grl)
> b
B object of length 1:
$1
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]        1  [1, 100]      *

-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
> c(b, b)
GRangesList 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 Under development (unstable) (2014-11-04 r66932)
Platform: x86_64-unknown-linux-gnu (64-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=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.21.15 GenomeInfoDb_1.5.7    IRanges_2.3.11
[4] S4Vectors_0.7.4       BiocGenerics_0.15.2

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



More information about the Bioc-devel mailing list