Last data update: 2014.03.03

R: Statistical wrappers for SummarizedExperiment objects
SEmethodsR Documentation

Statistical wrappers for SummarizedExperiment objects

Description

Convenience wrappers for statistical routines operating on SummarizedExperiment objects.

Usage

## S4 method for signature 'SummarizedExperiment'
normOffsets(object, lib.sizes, assay=1, ...)
## S4 method for signature 'SummarizedExperiment'
normalize(object, lib.sizes, type="scaling", assay=1, ...) 
## S4 method for signature 'SummarizedExperiment'
asDGEList(object, lib.sizes, norm.factors, ...)

Arguments

object

a SummarizedExperiment object or its derived classes, like that produced by windowCounts

lib.sizes

an (optional) integer vector of library sizes

assay

a numeric scalar indicating which assay in object contains the count matrix

type

a character scaling indicating the type of normalization, see normOffsets

norm.factors

an (optional) numeric vector of normalization factors

...

other arguments to be passed to the function being wrapped

Details

For normalize and normOffset, counts are extracted from the matrix corresponding to the first assay in the SummarizedExperiment object (different assays can be specified with the assay argument). For asDGEList, counts are extracted from the assay named "counts", with the first assay used if no such assay exists with that name. If not specified in lib.sizes, library sizes are taken from the totals field in the column data of object. Warnings will be generated if this field is not present.

In the normOffsets and normalize methods, the extracted counts and library sizes are supplied to normOffsets,matrix-method. Similarly, the asDGEList method wraps the DGEList constructor. In both cases, any arguments in ... are also passed to the wrapped functions.

If type="scaling" in normalize, a vector of normalization factors is stored in the norm.factors field of the colData in the output object. If type="loess", an offset matrix is instead stored as a named entry in the assays of the output object.

If norm.factors is not specified, asDGEList will attempt to extract normalization factors from object$norm.factors. If this is not available, factors will be set to the default (all unity). If assays(object)$offset is present, this will be assigned to the offset field of the output DGEList object.

Value

For normOffsets, either a numeric matrix or vector is returned; see normOffsets,matrix-method.

For normalize, an object of the same class as object is returned with normalization data stored in various fields.

For asDGEList, a DGEList object is returned.

Author(s)

Aaron Lun

See Also

normOffsets, DGEList, windowCounts

Examples

bamFiles <- system.file("exdata", c("rep1.bam", "rep2.bam"), package="csaw")
data <- windowCounts(bamFiles, width=100, filter=1)

normOffsets(data)
normOffsets(data, lib.sizes=c(10, 100))
head(normOffsets(data, type="loess"))

asDGEList(data)
asDGEList(data, lib.sizes=c(10, 100))
asDGEList(data, norm.factors=c(1.11, 2.23), group=c("a", "b"))

norm.data <- normalize(data)
norm.data$norm.factors
asDGEList(norm.data)$samples$norm.factors
asDGEList(norm.data, norm.factors=c(1,2))$samples$norm.factors # gets priority
norm.data <- normalize(data, type="loess")
head(asDGEList(norm.data)$offset)

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(csaw)
Loading required package: GenomicRanges
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: 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")'.

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/csaw/SEmethods.Rd_%03d_medium.png", width=480, height=480)
> ### Name: SEmethods
> ### Title: Statistical wrappers for SummarizedExperiment objects
> ### Aliases: normalize normalize,SummarizedExperiment-method
> ###   normOffsets,SummarizedExperiment-method
> ###   asDGEList,SummarizedExperiment-method asDGEList
> ### Keywords: normalization
> 
> ### ** Examples
> 
> bamFiles <- system.file("exdata", c("rep1.bam", "rep2.bam"), package="csaw")
> data <- windowCounts(bamFiles, width=100, filter=1)
> 
> normOffsets(data)
[1] 0.997706 1.002299
> normOffsets(data, lib.sizes=c(10, 100))
[1] 2.0199685 0.4950572
> head(normOffsets(data, type="loess"))
           [,1]      [,2]
[1,] -0.4752867 0.4752867
[2,] -0.4871047 0.4871047
[3,] -0.4229590 0.4229590
[4,] -0.4249920 0.4249920
[5,] -0.4255988 0.4255988
[6,] -0.4248882 0.4248882
> 
> asDGEList(data)
An object of class "DGEList"
$counts
  Sample1 Sample2
1      68     113
2      68     137
3      74     172
4      65     193
5      69     186
66 more rows ...

$samples
        group lib.size norm.factors
Sample1     1     1349            1
Sample2     1     3291            1

> asDGEList(data, lib.sizes=c(10, 100))
An object of class "DGEList"
$counts
  Sample1 Sample2
1      68     113
2      68     137
3      74     172
4      65     193
5      69     186
66 more rows ...

$samples
        group lib.size norm.factors
Sample1     1       10            1
Sample2     1      100            1

> asDGEList(data, norm.factors=c(1.11, 2.23), group=c("a", "b"))
An object of class "DGEList"
$counts
  Sample1 Sample2
1      68     113
2      68     137
3      74     172
4      65     193
5      69     186
66 more rows ...

$samples
        group lib.size norm.factors
Sample1     a     1349         1.11
Sample2     b     3291         2.23

> 
> norm.data <- normalize(data)
> norm.data$norm.factors
[1] 0.997706 1.002299
> asDGEList(norm.data)$samples$norm.factors
[1] 0.997706 1.002299
> asDGEList(norm.data, norm.factors=c(1,2))$samples$norm.factors # gets priority
[1] 1 2
> norm.data <- normalize(data, type="loess")
> head(asDGEList(norm.data)$offset)
           [,1]      [,2]
[1,] -0.4752867 0.4752867
[2,] -0.4871047 0.4871047
[3,] -0.4229590 0.4229590
[4,] -0.4249920 0.4249920
[5,] -0.4255988 0.4255988
[6,] -0.4248882 0.4248882
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>