Learn R Programming

bamsignals (version 1.4.3)

CountSignals-class: Container for count signals

Description

This s4 class is a tiny wrapper around a normal list (stored in the signals slot) and it is the output of the methods in the bamsignals package. Among other things the container provides an accessor method, that returns single signals as vectors and matrices, and the methods as.list and alignSignals, that convert the container to a list or an array/matrix respectively. A CountSignals object is read-only, i.e. it cannot be modified.

Usage

"length"(x)
"width"(x)
"["(x, i, drop = TRUE)
"as.list"(x)
"alignSignals"(x)

Arguments

x
A CountSignals object
i
Index for subsetting. It can be a single index as well as a vector of indices.
drop
In case i is a vector of length 1, after subsetting, collapse the CountSignal object to a single signal or not.

Value

return values are described in the Methods section.

Methods (by generic)

  • length: Number of contained signals
  • width: Width of each signal. If the CountSignals object csig is strand-specific then width(csig)[i] == ncol(csig[i]), otherwise width(csig)[i] = length(csig[i]).
  • [: Access single signals or subset the CountSignals object. If i is a single index and drop==TRUE then the accessor returns a single signal. If x is strand-specific then a single signal is a matrix with two rows, the first for the sense, the second for the antisense strand. Otherwise a signle signal is simply a vector of integers. If i is a vector of length different than 1, then the acessor returns a subset of the CountSignals object. Invalid indices result into errors.
  • as.list: Converts the container to a list l such that l[[i]] is the i-th signal.
  • alignSignals: Convert to a matrix or to an array. This is only possible if all signals have the same width w. If the CountSignals object csig is strand-specific, the result is an array of dimensions [2, w, length(csig)], otherwise it will be a matrix of dimensions [w, length(csig)].

Slots

ss
A single boolean value indicating whether all signals are strand-specific or not
signals
A list of integer vectors (if ss==TRUE) or of integer matrices, representing each signal

See Also

bamsignals-methods for the functions that produce this object

Examples

Run this code
#get a CountSignals object
library(GenomicRanges)
bampath <- 
system.file("extdata", "randomBam.bam", package="bamsignals")
genes <- 
get(load(system.file("extdata", "randomAnnot.Rdata", package="bamsignals")))
csig <- bamProfile(bampath, genes, ss=TRUE)

#show it
show(csig)

#number of contained signals
len <- length(csig)

#width of each signal
w <- width(csig)

#get one element as a vector (or matrix)
v <- csig[1]

#use as if it was a list
tot_per_sig <- sapply(csig, sum)

#convert to a list
siglist <- as.list(csig)

#get regions and signals of the same width
proms <- promoters(genes, upstream=150, downstream=150)
csig <- bamCoverage(bampath, proms)

#convert to matrix
mat <- alignSignals(csig)

Run the code above in your browser using DataLab