View source: R/dataset_functions.R
subsampleGRanges | R Documentation |
Random subsampling is not performed on ranges, but on reads. Readcounts
should be given as a metadata field (usually "score"). This function can also
subsample ranges directly if field = NULL
, but the sample
function can be used in this scenario.
subsampleGRanges(
dataset.gr,
n = NULL,
prop = NULL,
field = "score",
expand_ranges = FALSE,
ncores = getOption("mc.cores", 2L)
)
dataset.gr |
A GRanges object in which signal (e.g. readcounts) are contained within metadata, or a list of such GRanges objects. |
n , prop |
Either the number of reads to subsample ( |
field |
The metadata field of |
expand_ranges |
Logical indicating if ranges in |
ncores |
Number of cores to use for computations. Multicore only used
when |
A GRanges object identical in format to dataset.gr
, but
containing a random subset of its data. If field != NULL
, the length
of the output cannot be known a priori, but the sum of its score
can.
If the metadata field contains normalized readcounts, an attempt will be made to infer the normalization factor based on the lowest signal value found in the specified field.
Mike DeBerardine
data("PROseq") # load included PROseq data
#--------------------------------------------------#
# sample 10% of the reads of a GRanges with signal coverage
#--------------------------------------------------#
ps_sample <- subsampleGRanges(PROseq, prop = 0.1)
# cannot predict number of ranges (positions) that will be sampled
length(PROseq)
length(ps_sample)
# 1/10th the score is sampled
sum(score(PROseq))
sum(score(ps_sample))
#--------------------------------------------------#
# Sample 10% of ranges (e.g. if each range represents one read)
#--------------------------------------------------#
ps_sample <- subsampleGRanges(PROseq, prop = 0.1, field = NULL)
length(PROseq)
length(ps_sample)
# Alternatively
ps_sample <- sample(PROseq, 0.1 * length(PROseq))
length(ps_sample)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.