R/qseaExtra.R
calculateFractionReadsInGRanges.RdFor each sample, compute the proportion of windows with counts
>= numCountsNeeded that overlap regionsToOverlap, relative to all
windows with counts >= numCountsNeeded in that sample.
calculateFractionReadsInGRanges(qseaSet, regionsToOverlap, numCountsNeeded)qseaSet.
Input qseaSet. Default: none (must be supplied).
GRanges or data.frame.
Regions to consider for overlap. Data frames must be coercible to GRanges
(e.g., have seqnames/start/end or chr/window_start/window_end).
Default: none (must be supplied).
integer(1).
Minimum reads per window for it to count toward the fraction.
Default: none (must be supplied).
A tibble with one row per sample containing:
sample_name
initialOverBackNum — windows >= threshold genome-wide
afterOverBackNum — windows >= threshold within regionsToOverlap
fraction — afterOverBackNum / initialOverBackNum
followed by columns from the sample table (left-joined by sample_name).
Operates on the window × sample count matrix from qsea::getCounts().
Counts are converted to a logical indicator (count >= numCountsNeeded)
and summed per sample:
initialOverBackNum: windows meeting the threshold genome-wide.
afterOverBackNum: windows meeting the threshold within
regionsToOverlap (via filterByOverlaps()).
The reported fraction is afterOverBackNum / initialOverBackNum.
Note: despite the function name, this computes a window-based fraction using a count threshold, not a direct fraction of raw reads.
data(exampleTumourNormal, package = "mesa")
# Using the shipped ultra-stable probes (GRCh38) as the region set
exampleTumourNormal %>%
calculateFractionReadsInGRanges(
regionsToOverlap = mesa::hg38CpGIslands,
numCountsNeeded = 5
) %>%
dplyr::select(sample_name, initialOverBackNum, afterOverBackNum, fraction)
#> Joining with `by = join_by(sample_name)`
#> # A tibble: 10 × 4
#> sample_name initialOverBackNum afterOverBackNum fraction
#> <chr> <dbl> <dbl> <dbl>
#> 1 Colon1_N 111 54 0.486
#> 2 Colon1_T 184 80 0.435
#> 3 Colon2_N 127 55 0.433
#> 4 Colon2_T 228 93 0.408
#> 5 Lung1_N 221 75 0.339
#> 6 Lung1_T 133 64 0.481
#> 7 Lung2_N 210 60 0.286
#> 8 Lung2_T 243 107 0.440
#> 9 Lung3_N 141 48 0.340
#> 10 Lung3_T 237 111 0.468
# Define a small GRanges subset from the object's own windows
gr <- exampleTumourNormal %>%
qsea::getRegions() %>%
head(n = 100)
calculateFractionReadsInGRanges(
qseaSet = exampleTumourNormal,
regionsToOverlap = gr,
numCountsNeeded = 3) %>%
dplyr::select(sample_name, initialOverBackNum, afterOverBackNum, fraction)
#> Joining with `by = join_by(sample_name)`
#> # A tibble: 10 × 4
#> sample_name initialOverBackNum afterOverBackNum fraction
#> <chr> <dbl> <dbl> <dbl>
#> 1 Colon1_N 173 8 0.0462
#> 2 Colon1_T 269 19 0.0706
#> 3 Colon2_N 193 14 0.0725
#> 4 Colon2_T 306 26 0.0850
#> 5 Lung1_N 314 30 0.0955
#> 6 Lung1_T 210 16 0.0762
#> 7 Lung2_N 307 30 0.0977
#> 8 Lung2_T 319 25 0.0784
#> 9 Lung3_N 206 23 0.112
#> 10 Lung3_T 315 23 0.0730