R/calculateStats.R
calculateStats.Rd
After defining the models of interest (see makeModels) and pre-processing the data (see preprocessCoverage), use calculateStats to calculate the F-statistics at base-pair resolution.
calculateStats(coveragePrep, models, lowMemDir = NULL, ...)
A list with $coverageProcessed
,
$mclapplyIndex
, and $position
normally generated using
preprocessCoverage.
A list with $mod
and $mod0
normally generated
using makeModels.
The directory where the processed chunks are saved when
using preprocessCoverage with a specified lowMemDir
.
Arguments passed to other methods and/or advanced arguments. Advanced arguments:
If TRUE
basic status updates will be printed along
the way.
This argument is passed to fstats.apply and should be the same as the one used in preprocessCoverage. Default: 32.
Has to be either 'Matrix' (default), 'Rle' or 'regular'. See details in fstats.apply.
A single value to adjust that is added in the denominator of the F-stat calculation. Useful when the Residual Sum of Squares of the alternative model is very small. Default: 0.
Passed to define_cluster.
A numeric Rle with the F-statistics per base pair that passed the cutoff.
## Collapse the coverage information
collapsedFull <- collapseFullCoverage(list(genomeData$coverage),
verbose = TRUE
)
#> 2024-12-13 15:13:06.234428 collapseFullCoverage: Sorting fullCov
#> 2024-12-13 15:13:06.23667 collapseFullCoverage: Collapsing chromosomes information by sample
## Calculate library size adjustments
sampleDepths <- sampleDepth(collapsedFull, probs = c(0.5), verbose = TRUE)
#> 2024-12-13 15:13:06.238278 sampleDepth: Calculating sample quantiles
#> 2024-12-13 15:13:06.24263 sampleDepth: Calculating sample adjustments
## Build the models
group <- genomeInfo$pop
adjustvars <- data.frame(genomeInfo$gender)
models <- makeModels(sampleDepths, testvars = group, adjustvars = adjustvars)
## Preprocess the data
prep <- preprocessCoverage(genomeData,
cutoff = 0, scalefac = 32,
chunksize = 1e3, colsubset = NULL
)
## Run the function
fstats <- calculateStats(prep, models, verbose = TRUE, method = "regular")
#> 2024-12-13 15:13:06.445012 calculateStats: calculating the F-statistics
fstats
#> numeric-Rle of length 1434 with 367 runs
#> Lengths: 1 5 3 ... 5 1
#> Values : 5.10948e+00 3.85229e+00 5.12448e-01 ... 0.032237427 3.997655116
if (FALSE) { # \dontrun{
## Compare vs pre-packaged F-statistics
library("testthat")
expect_that(fstats, is_equivalent_to(genomeFstats))
} # }