Last data update: 2014.03.03

R: Class '"RleDataFrame"'
RleDataFrame-classR Documentation

Class "RleDataFrame"

Description

The RleDataFrame class serves to hold a collection of Run Length Encoded vectors (Rle objects) of the same length. For example, it could be used to hold information along the genome for a number of samples, such as sequencing coverage, DNA copy number, or GC content. This class inherits from both DataFrame and SimpleRleList (one of the AtomicVector types). This means that all of the usual subsetting and applying functions will work. Also, the AtomicList functions, like mean and sum, that automatically apply over the list elements will work. The scalar mathematical AtomicList methods can make this class behave much like a matrix (see Examples).

New objects can be created with the RleDataFrame constructor: RleDataFrame(..., row.names=NULL), where ... can be a list of Rle objects, or one or more individual Rle objects.

Use in Biobase eSet objects

The genoset class defines an annotatedDataFrameFrom method for DataFrame, which makes it possible to include DataFrames as assayData elements. The column names for DataFrame cannot be NULL, which makes it impossible to use them as assays in SummarizedExperiment at this time.

Row and Column Summaries

These objects will sometimes be in place of a matrix, as in the eSet example above. It is convenient to have some of the summarization methods for matrices. Each of these methods takes an RleDataFrame and returns a single Rle. The time required is similar to that required for a matrix. For an RleDataFrame x,

rowSums:

Sum across 'rows'.

rowMeans:

Means across 'rows'.

colSums:

Sum each Rle. This is just the sum method for SimpleRleList.

colSums:

Mean of each Rle. This is just the mean method for SimpleRleList.

Slots

rownames:

Object of class "characterORNULL" Names to describe each row of the DataFrame. These may end up taking more space than your collection of Rle objects, so consider leaving this NULL.

nrows:

Object of class "integer" Number of rows.

elementType:

Object of class "character" Notes that elements of the internal list are Rle objects.

elementMetadata:

Object of class "DataTableORNULL" Metadata on the elements, see DataFrame.

metadata:

Object of class "list" Metadata on the whole object, see DataFrame.

listData:

Object of class "list" Base list containing the Rle objects.

Extends

Class "SimpleRleList", directly. Class "DataFrame", directly.

Methods

as.matrix

signature(x = "RleDataFrame"): Convert to matrix.

coerce

signature(x = "RleDataFrame"): Convert to other classes.

colMeans

signature(x = "RleDataFrame"): Mean of each column.

colSums

signature(x = "RleDataFrame"): Sum of each column.

rowMeans

signature(x = "RleDataFrame"): Mean of each 'row'.

rowSums

signature(x = "RleDataFrame"): Sum of each 'row'.

show

signature(object = "RleDataFrame"): Short and pretty description of an object of this type.

Author(s)

Peter M. Haverty, design suggestion from Michael Lawrence.

See Also

DataFrame AtomicList Rle RleList rowMeans colMeans rowSums colSums view-summarization-methods

Examples

showClass("RleDataFrame")

## Constructors
df = new("RleDataFrame", listData=list(A=Rle(c(NA, 2:3, NA, 5), rep(2,
5)), B=Rle(c(6:7, NA, 8:10),c(3,2,1,2,1,1))), nrows=10L)

df2 = RleDataFrame(list(A=Rle(c(NA, 2:3, NA, 5), rep(2, 5)),
B=Rle(c(6:7, NA, 8:10),c(3,2,1,2,1,1))))

df3 = RleDataFrame(A=Rle(c(NA, 2:3, NA, 5), rep(2, 5)), B=Rle(c(6:7,
NA, 8:10),c(3,2,1,2,1,1)))

## AtomicList Methods
runValue(df)
runLength(df)
ranges(df)
mean(df)
sum(df)
df + 5
log2(df) - 1

## Row and Column Summaries
rowSums(df)
colSums(df)
rowMeans(df)
colMeans(df)

## Coercion
as(df, "matrix")
as(df, "list")
as(df, "RleList")
as(df, "DataFrame")
as(df, "data.frame")

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(genoset)
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")'.


*** Genoset API Changes ***
The genoset class has transitioned to the
RangedSummarizedExperiment API from the eSet API (e.g. use colnames instead of sampleNames). ***

Attaching package: 'genoset'

The following object is masked from 'package:GenomicRanges':

    pos

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

    colMeans, colSums, rowMeans, rowSums

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

    colMeans, colSums, rowMeans, rowSums

Warning messages:
1: multiple methods tables found for 'colMeans' 
2: multiple methods tables found for 'colSums' 
3: multiple methods tables found for 'rowMeans' 
4: multiple methods tables found for 'rowSums' 
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/genoset/RleDataFrame-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: RleDataFrame-class
> ### Title: Class '"RleDataFrame"'
> ### Aliases: RleDataFrame-class as.matrix,RleDataFrame-method
> ###   coerce,RleDataFrame,matrix-method colMeans,RleDataFrame-method
> ###   colSums,RleDataFrame-method colMeans,DataFrame-method
> ###   rowMeans,RleDataFrame-method rowSums,RleDataFrame-method
> ###   show,RleDataFrame-method RleDataFrame
> ### Keywords: classes methods
> 
> ### ** Examples
> 
> showClass("RleDataFrame")
Class "RleDataFrame" [package "genoset"]

Slots:
                                                                      
Name:         rownames           nrows     elementType elementMetadata
Class: characterORNULL         integer       character DataTableORNULL
                                      
Name:         metadata        listData
Class:            list            list

Extends: 
Class "SimpleRleList", directly
Class "DataFrame", directly
Class "RleList", by class "SimpleRleList", distance 2
Class "SimpleAtomicList", by class "SimpleRleList", distance 2
Class "DataTable", by class "DataFrame", distance 2
Class "AtomicList", by class "SimpleRleList", distance 3
Class "SimpleList", by class "SimpleRleList", distance 3
Class "DataTableORNULL", by class "DataFrame", distance 3
Class "List", by class "DataFrame", distance 3
Class "Vector", by class "DataFrame", distance 4
Class "Annotated", by class "DataFrame", distance 5
> 
> ## Constructors
> df = new("RleDataFrame", listData=list(A=Rle(c(NA, 2:3, NA, 5), rep(2,
+ 5)), B=Rle(c(6:7, NA, 8:10),c(3,2,1,2,1,1))), nrows=10L)
> 
> df2 = RleDataFrame(list(A=Rle(c(NA, 2:3, NA, 5), rep(2, 5)),
+ B=Rle(c(6:7, NA, 8:10),c(3,2,1,2,1,1))))
> 
> df3 = RleDataFrame(A=Rle(c(NA, 2:3, NA, 5), rep(2, 5)), B=Rle(c(6:7,
+ NA, 8:10),c(3,2,1,2,1,1)))
> 
> ## AtomicList Methods
> runValue(df)
NumericList of length 2
[["A"]] <NA> 2 3 <NA> 5
[["B"]] 6 7 <NA> 8 9 10
> runLength(df)
IntegerList of length 2
[["A"]] 2 2 2 2 2
[["B"]] 3 2 1 2 1 1
> ranges(df)
IRangesList of length 2
$A
IRanges object with 5 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         2         2
  [2]         3         4         2
  [3]         5         6         2
  [4]         7         8         2
  [5]         9        10         2

$B
IRanges object with 6 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         3         3
  [2]         4         5         2
  [3]         6         6         1
  [4]         7         8         2
  [5]         9         9         1
  [6]        10        10         1

> mean(df)
 A  B 
NA NA 
> sum(df)
 A  B 
NA NA 
> df + 5
RleList of length 2
$A
numeric-Rle of length 2 with 1 run
  Lengths:  2
  Values : NA

$B
numeric-Rle of length 2 with 1 run
  Lengths:  2
  Values : 11

> log2(df) - 1
RleList of length 2
$A
numeric-Rle of length 10 with 5 runs
  Lengths:                 2                 2 ...                 2
  Values :                NA                 0 ...  1.32192809488736

$B
numeric-Rle of length 10 with 6 runs
  Lengths:                3                2 ...                1
  Values : 1.58496250072116  1.8073549220576 ... 2.32192809488736

> 
> ## Row and Column Summaries
> rowSums(df)
numeric-Rle of length 10 with 7 runs
  Lengths:  2  1  1  1  3  1  1
  Values : NA  8  9 10 NA 14 15
> colSums(df)
 A  B 
20 67 
> rowMeans(df)
numeric-Rle of length 10 with 7 runs
  Lengths:   2   1   1   1   3   1   1
  Values :  NA   4 4.5   5  NA   7 7.5
> colMeans(df)
       A        B 
3.333333 7.444444 
> 
> ## Coercion
> as(df, "matrix")
       A  B
 [1,] NA  6
 [2,] NA  6
 [3,]  2  6
 [4,]  2  7
 [5,]  3  7
 [6,]  3 NA
 [7,] NA  8
 [8,] NA  8
 [9,]  5  9
[10,]  5 10
> as(df, "list")
$A
numeric-Rle of length 10 with 5 runs
  Lengths:  2  2  2  2  2
  Values : NA  2  3 NA  5

$B
integer-Rle of length 10 with 6 runs
  Lengths:  3  2  1  2  1  1
  Values :  6  7 NA  8  9 10

> as(df, "RleList")
RleList of length 2
$A
numeric-Rle of length 10 with 5 runs
  Lengths:  2  2  2  2  2
  Values : NA  2  3 NA  5

$B
integer-Rle of length 10 with 6 runs
  Lengths:  3  2  1  2  1  1
  Values :  6  7 NA  8  9 10

> as(df, "DataFrame")
DataFrame with 10 rows and 2 columns
       A     B
   <Rle> <Rle>
1     NA     6
2     NA     6
3      2     6
4      2     7
5      3     7
6      3    NA
7     NA     8
8     NA     8
9      5     9
10     5    10
> as(df, "data.frame")
    A  B
1  NA  6
2  NA  6
3   2  6
4   2  7
5   3  7
6   3 NA
7  NA  8
8  NA  8
9   5  9
10  5 10
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>