[BioC] subset a RleList using GRanges object?

Hervé Pagès hpages at fhcrc.org
Wed Dec 4 06:55:46 CET 2013


Hi Janet,

On 12/03/2013 04:53 PM, Janet Young wrote:
> Hi there,
>
> I'm playing around with coverage data generated outside of R, planning to plot RNA-seq coverage for some genes we're interested in.
>
> I have a request - it'd be nice from my point of view if it were possible to look at a small region an RleList (or CompressedRleList) using a GRanges object to focus on that smaller region.  Looks like I can subset a single Rle object with an IRanges object, but I wonder if this nice feature could be extended to GRanges objects?
>
> Some code is below to show what I'm trying to do.
>
> thanks veruy much,
>
> Janet
>
>
>
> library(GenomicRanges)
>
> ## an example RleList
> x <- Rle(10:1, 1:10)
> y <- Rle(10:1, 1:10)
> z <- RleList( chr1=x, chr2=y)
>
> ## an example GRanges object
> myRange <- GRanges( seqnames="chr1", ranges=IRanges(start=10,end=15) )
>
> ## subsetting an Rle using an IRanges object works, as expected:
> z[["chr1"]] [ ranges(myRange) ]
>
> ## but subsetting an RleList by GRanges object doesn't work
> z [ myRange ]
> # Error in normalizeSingleBracketSubscript(i, x) : invalid subscript type

Subsetting by a GRanges object is not supported (yet) but subsetting by
a RangesList object is:

   > idx <- IRangesList(IRanges(10, 15), IRanges(2, 6))
   > z[idx]
   RleList of length 2
   $chr1
   integer-Rle of length 6 with 2 runs
     Lengths: 1 5
     Values : 7 6

   $chr2
   integer-Rle of length 5 with 2 runs
     Lengths: 2 3
     Values : 9 8

So if you turn your GRanges object into a RangesList object, that
will make the trick:

   > z[as(myRange, "RangesList")]
   RleList of length 1
   $chr1
   integer-Rle of length 6 with 2 runs
     Lengths: 1 5
     Values : 7 6

HTH,
H.

>
> sessionInfo()
>
> R Under development (unstable) (2013-11-06 r64163)
> 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] parallel  stats     graphics  grDevices utils     datasets  methods
> [8] base
>
> other attached packages:
> [1] GenomicRanges_1.15.10 XVector_0.3.2         IRanges_1.21.13
> [4] BiocGenerics_0.9.1
>
> loaded via a namespace (and not attached):
> [1] stats4_3.1.0
>
>
>
>
> -------------------------------------------------------------------
>
> Dr. Janet Young
>
> Malik lab
> http://research.fhcrc.org/malik/en.html
>
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Avenue N., A2-025,
> P.O. Box 19024, Seattle, WA 98109-1024, USA.
>
> tel: (206) 667 4512
> email: jayoung  ...at...  fhcrc.org
>
> -------------------------------------------------------------------
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioconductor mailing list