Identify genomic windows with significantly more reads than expected under a
Poisson background model, given total reads per sample and the number of
genome windows. If numWindows is provided, then that value will be used as
the total original number of windows under consideration for the false
discovery rate, otherwise it will use the number of windows currently in the
qseaSet.
subsetWindowsOverBackground(
qseaSet,
keepAbove = FALSE,
samples = NULL,
numWindows = NULL,
FDRthres = 0.01,
numAbove = 1
)qseaSet.
Input object containing per-window read counts.
logical(1).
If TRUE, keep windows above background; if FALSE, remove them.
Default: FALSE.
character() or NULL.
Vector of sample names to test, or a single string used as a pattern matched
against sample names. If NULL, all samples are tested.
Default: NULL.
integer(1) or NULL.
Total number of windows in the genome used to compute the expected
background.
If NULL, it will use all the windows currently in the qseaSet.
Default: NULL.
numeric(1).
FDR threshold used to call windows significantly above background.
Default: 0.01.
integer(1).
Minimum number of tested samples that must exceed background in a window
to keep/drop it (depending on keepAbove).
Default: 1.
A filtered qseaSet containing only windows passing the criteria.
For each tested sample, an expected count per window is derived from its
total
reads and the supplied/estimated numWindows, and a Poisson test is used to
flag windows above background. This uses the valid_fragments column in the
library information attached to the qseaSet, which is the number of fragments
used in the generation of the original qseaSet. Windows are retained or
removed based on keepAbove and the requirement that at least numAbove
samples are significant at FDRthres.
Other window-helpers:
calculateFractionReadsInGRanges(),
convertToArrayBetaTable(),
downSample(),
subsetWindowsBySignal()
data(exampleTumourNormal, package = "mesa")
# Keep windows above Poisson background in at least 2 samples whose names
# contain "Lung", assuming there were 9 million original windows
exampleTumourNormal %>%
subsetWindowsOverBackground(keepAbove = TRUE, samples = "Lung",
numAbove = 2, numWindows = 9e6 )
#> Filtering out 6 samples containing Lung in the name.
#> Removing windows with reads above background levels in 6 samples.
#> GRanges object with 265 ranges and 1 metadata column:
#> seqnames ranges strand | CpG_density
#> <Rle> <IRanges> <Rle> | <numeric>
#> [1] 7 25017601-25017900 * | 8.38014
#> [2] 7 25017901-25018200 * | 17.86376
#> [3] 7 25018801-25019100 * | 15.29626
#> [4] 7 25019401-25019700 * | 17.06054
#> [5] 7 25035001-25035300 * | 9.28668
#> ... ... ... ... . ...
#> [261] 7 27876901-27877200 * | 5.30366
#> [262] 7 27943201-27943500 * | 6.89654
#> [263] 7 27986701-27987000 * | 10.03481
#> [264] 7 27987001-27987300 * | 12.74275
#> [265] 7 27987301-27987600 * | 15.82394
#> -------
#> seqinfo: 22 sequences from BSgenome.Hsapiens.NCBI.GRCh38 genome
#> Removing 554 windows based on 6 samples, 265 remaining
#> qseaSet
#> =======================================
#> 10 Samples:
#> Colon1_N, Colon1_T, Colon2_N, Colon2_T, Lung1_N, Lung1_T, Lung2_N, Lung2_T, Lung3_N, Lung3_T
#> 265 Regions in 22 chromosomes of BSgenome.Hsapiens.NCBI.GRCh38
# Drop windows above background (retain only background-like windows) across
# all samples, assuming there were 9 million original windows
exampleTumourNormal %>%
subsetWindowsOverBackground(keepAbove = FALSE, numWindows = 9e6)
#> Removing windows with reads above background levels in 10 samples.
#> GRanges object with 452 ranges and 1 metadata column:
#> seqnames ranges strand | CpG_density
#> <Rle> <IRanges> <Rle> | <numeric>
#> [1] 7 25002001-25002300 * | 5.50911
#> [2] 7 25008601-25008900 * | 5.56726
#> [3] 7 25011301-25011600 * | 5.10095
#> [4] 7 25018501-25018800 * | 17.50445
#> [5] 7 25019701-25020000 * | 5.98508
#> ... ... ... ... . ...
#> [448] 7 27924001-27924300 * | 6.70225
#> [449] 7 27930001-27930300 * | 6.66011
#> [450] 7 27940501-27940800 * | 5.06512
#> [451] 7 27975001-27975300 * | 5.04081
#> [452] 7 27987601-27987900 * | 5.86953
#> -------
#> seqinfo: 22 sequences from BSgenome.Hsapiens.NCBI.GRCh38 genome
#> Removing 367 windows based on 10 samples, 452 remaining
#> qseaSet
#> =======================================
#> 10 Samples:
#> Colon1_N, Colon1_T, Colon2_N, Colon2_T, Lung1_N, Lung1_T, Lung2_N, Lung2_T, Lung3_N, Lung3_T
#> 452 Regions in 22 chromosomes of BSgenome.Hsapiens.NCBI.GRCh38