Last data update: 2014.03.03

R: Un-pack results obtained with a pack()ed group of ranges
unpackR Documentation

Un-pack results obtained with a pack()ed group of ranges

Description

unpack returns results obtained with pack()ed ranges to the geometry of the original, unpacked ranges.

Usage

## S4 method for signature 'list,GRangesList'
unpack(flesh, skeleton, ...)
## S4 method for signature 'List,GRangesList'
unpack(flesh, skeleton, ...)

Arguments

flesh

A List object to be unpacked; the result from querying a file with skeleton.

skeleton

The GRangesList created with 'pack(x)'.

...

Arguments passed to other methods.

Details

unpack returns a List obtained with packed ranges to the geometry and order of the original, unpacked ranges.

Value

A unpacked form of flesh.

See Also

  • pack for packing ranges.

Examples

  fl <- system.file("extdata", "ex1.bam", package = "Rsamtools")
  gr <- GRanges(c(rep("seq2", 3), "seq1"), 
                IRanges(c(75, 1, 100, 1), width = 2))

  ## Ranges are packed by order within chromosome and grouped
  ## around gaps greater than 'inter_range_len'. See ?pack for details.
  pk <- pack(gr, inter_range_len = 25)

  ## FUN computes coverage for the range passed as 'rng'.
  FUN <- function(rng, fl, param) {
      requireNamespace("GenomicAlignments") ## for bamWhich() and coverage()
      Rsamtools::bamWhich(param) <- rng
      GenomicAlignments::coverage(Rsamtools::BamFile(fl), param=param)[rng]
  } 

  ## Compute coverage on the packed ranges.
  dat <- bplapply(as.list(pk), FUN, fl = fl, param = ScanBamParam())

  ## The result list contains RleLists of coverage.
  lapply(dat, class)

  ## unpack() transforms the results back to the order of 
  ## the original ranges (i.e., unpacked 'gr').
  unpack(dat, pk)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GenomicFiles)
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: GenomicRanges
Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: GenomeInfoDb
Loading required package: SummarizedExperiment
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: BiocParallel
Loading required package: Rsamtools
Loading required package: Biostrings
Loading required package: XVector
Loading required package: rtracklayer
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/GenomicFiles/unpack-methods.Rd_%03d_medium.png", width=480, height=480)
> ### Name: unpack
> ### Title: Un-pack results obtained with a pack()ed group of ranges
> ### Aliases: unpack unpack,list,GRangesList-method
> ###   unpack,List,GRangesList-method
> ### Keywords: methods
> 
> ### ** Examples
> 
>   fl <- system.file("extdata", "ex1.bam", package = "Rsamtools")
>   gr <- GRanges(c(rep("seq2", 3), "seq1"), 
+                 IRanges(c(75, 1, 100, 1), width = 2))
> 
>   ## Ranges are packed by order within chromosome and grouped
>   ## around gaps greater than 'inter_range_len'. See ?pack for details.
>   pk <- pack(gr, inter_range_len = 25)
> 
>   ## FUN computes coverage for the range passed as 'rng'.
>   FUN <- function(rng, fl, param) {
+       requireNamespace("GenomicAlignments") ## for bamWhich() and coverage()
+       Rsamtools::bamWhich(param) <- rng
+       GenomicAlignments::coverage(Rsamtools::BamFile(fl), param=param)[rng]
+   } 
> 
>   ## Compute coverage on the packed ranges.
>   dat <- bplapply(as.list(pk), FUN, fl = fl, param = ScanBamParam())
> 
>   ## The result list contains RleLists of coverage.
>   lapply(dat, class)
[[1]]
[1] "CompressedRleList"
attr(,"package")
[1] "IRanges"

[[2]]
[1] "CompressedRleList"
attr(,"package")
[1] "IRanges"

[[3]]
[1] "CompressedRleList"
attr(,"package")
[1] "IRanges"

> 
>   ## unpack() transforms the results back to the order of 
>   ## the original ranges (i.e., unpacked 'gr').
>   unpack(dat, pk)
RleList of length 4
[[1]]
integer-Rle of length 2 with 2 runs
  Lengths:  1  1
  Values : 37 35

[[2]]
integer-Rle of length 2 with 2 runs
  Lengths: 1 1
  Values : 3 4

[[3]]
integer-Rle of length 2 with 2 runs
  Lengths:  1  1
  Values : 32 30

[[4]]
integer-Rle of length 2 with 1 run
  Lengths: 2
  Values : 1

> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>