binFeatureProfiles: Bin coverage profiles given as a matrix or RleList of...

Description Usage Arguments Value DETAILS Author(s) See Also Examples

View source: R/binFeatureProfiles.R

Description

Bin coverage profiles given as a matrix or RleList of profiles.

Usage

1
2
3
4
5
6
7
8
binFeatureProfiles(
  FeatureProfiles,
  nbins = 100L,
  binwidth = NULL,
  aggregFUN = "mean",
  asMatrix = FALSE,
  ...
)

Arguments

FeatureProfiles

A matrix (with features in row and genomic positions in column) or RleList, typically obtained with the profcomp function.

nbins

Integer. Number of bins to define along each feature. Default value is 100 bins.

binwidth

Integer. Size of the bins to define on the features. Default value is NULL and 100 bins are used instead.

aggregFUN

A character string (or a function name), such as "median", "mean", etc., with the name of a function used to aggregate the data within the bins. Defaults to "mean". A user-defined aggregFUN should take an Rle as an argument and return a single value.

asMatrix

Logical (default to FALSE). If TRUE, the binned profiles are returned as a matrix (only possible if featrures have the same number of bins).

...

Further arguments passed to aggregFUN.

Value

An RleList or a matrix (if asMatrix is TRUE) of binned profiles.

DETAILS

The function removes features of length < nbins (or binwidth) and returns an message with the number of removed features. The remaining features are sliced into nbins (possibly different bin sizes for different features) or into bins of size binwidth (possibly different number of bins for different features). Then the data in each bins is aggregated using the aggregFUN function

Author(s)

Pascal GP Martin

See Also

profcomp annotationCoverageAroundFeatures

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## Obtain coverage for all genes:
  covr <- GenomicRanges::coverage(Genegr)
## Select a (random) set of (100) genes
  set.seed(123)
  randGenes <- sample(names(Genegr), 100)
## Windows of interests covering the gene bodies + 50bp on each side
  woi <- Genegr[randGenes] +50
## Remove windows that go beyond chromosome borders
  woi <- woi[GenomicRanges::width(GenomicRanges::trim(woi)) -
              GenomicRanges::width(woi) == 0]
## Coverage on these windows of interest:
  profs <- profcomp(covr, woi)
## Make 10 bins:
  binFeatureProfiles(profs, nbins = 10)
## Return a matrix instead:
  binFeatureProfiles(profs[1:3], nbins=10, asMatrix = TRUE)
## Make bins of size 20bp:
  binFeatureProfiles(profs, binwidth=20)
##use your own function to aggregate the data within the bins
  mymean <- function(x) {mean(as.numeric(x), trim=0.1)}
  binFeatureProfiles(profs[1:3], aggregFUN=mymean, nbins=10, asMatrix = TRUE)

pgpmartin/GeneNeighborhood documentation built on Sept. 2, 2021, 6:37 a.m.