Apply a summary function (e.g., mean, median, sd) over genomic windows per sample, optionally restricted to a set of regions and for one or more normalisation methods.
summariseAcrossWindows(
qseaSet,
regionsToOverlap = NULL,
fn = mean,
addSampleTable = TRUE,
normMethod = c("nrpm", "beta"),
naMethod = "na.rm",
minEnrichment = 3,
suffix = "",
fnName = NULL
)qseaSet.
Input object providing window-level signal.
Default: none (must be supplied).
GRanges, data.frame, or NULL.
Regions used to restrict the windows before summarising. Data frames must be
coercible to GRanges (e.g., have seqnames/start/end or
chr/window_start/window_end). If NULL, use all windows in qseaSet.
Default: NULL.
function.
Summary function applied column-wise per sample over the selected windows
(e.g., mean, median, sd). Provide NA handling inside fn if needed,
e.g., function(x) mean(x, na.rm = TRUE).
Default: mean.
logical(1).
If TRUE, join sample-table columns to the result.
Default: TRUE.
character().
One or more measures to summarise. Typically a subset of c("nrpm","beta").
Default: c("nrpm","beta").
character(1).
How to treat missing values prior to/within summarisation. Common choices:
"na.rm" — call fn with na.rm = TRUE when supported;
"drop" — drop windows with any NA across the selected methods before
summarising.
Default: "na.rm".
integer(1).
Minimum reads per window required for a non-NA beta (relevant when
normMethod includes "beta").
Default: 3.
character(1).
Optional string appended to output column names (e.g., a region label).
Default: "".
character(1) or NULL.
Name of fn used to construct output column names; if NULL, inferred
from fn.
Default: NULL.
A tibble with one row per sample. For each requested normMethod, a summary
column is added (column naming typically reflects <method> and fn and may
include suffix). If addSampleTable = TRUE, sample-table columns are
joined.
The function builds a window × sample matrix for each normMethod,
optionally
restricts to regionsToOverlap, then applies fn over windows for each
sample to produce a single summary value per sample (per method).
Missing-value
handling follows naMethod. When summarising betas, windows below
minEnrichment reads are NA prior to summarisation.
addSummaryAcrossWindows(), getDataTable()
Other window-summaries:
addSummaryAcrossWindows(),
countWindowsAboveCutoff()
data(exampleTumourNormal, package = "mesa")
# Mean NRPM and beta across all windows
exampleTumourNormal %>%
summariseAcrossWindows(
fn = mean,
normMethod = c("nrpm","beta")
)
#> Generating table of nrpm values for 819 regions across 10 samples.Generating table of beta values for 819 regions across 10 samples.
#> Removing NA values on a per-sample basis
#> # A tibble: 10 × 13
#> sample_name nrpm_mean nrpm_num_windows beta_mean beta_num_windows group
#> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 Colon1_N 0.862 819 0.283 626 Colon1_N
#> 2 Colon1_T 1.14 819 0.308 819 Colon1_T
#> 3 Colon2_N 0.851 819 0.284 649 Colon2_N
#> 4 Colon2_T 1.09 819 0.302 819 Colon2_T
#> 5 Lung1_N 0.677 819 0.309 819 Lung1_N
#> 6 Lung1_T 0.604 819 0.304 599 Lung1_T
#> 7 Lung2_N 0.619 819 0.275 819 Lung2_N
#> 8 Lung2_T 0.998 819 0.324 819 Lung2_T
#> 9 Lung3_N 0.685 819 0.283 754 Lung3_N
#> 10 Lung3_T 1.12 819 0.328 819 Lung3_T
#> # ℹ 7 more variables: patient <chr>, type <chr>, tumour <chr>, tissue <chr>,
#> # age <dbl>, gender <chr>, stage <chr>
# Maximum NRPM within a small genomic region
exampleTumourNormal %>%
summariseAcrossWindows(
regionsToOverlap = data.frame(
seqnames = 7,
start = 25002001,
end = 25017900
),
fn = max,
normMethod = "nrpm",
suffix = "_chr7_slice"
)
#> Generating table of nrpm values for 5 regions across 10 samples.
#> Removing NA values on a per-sample basis
#> # A tibble: 10 × 11
#> sample_name nrpm_max_chr7_slice nrpm_num_windows_chr7_s…¹ group patient type
#> <chr> <dbl> <dbl> <chr> <chr> <chr>
#> 1 Colon1_N 0.263 5 Colo… Colon1 Norm…
#> 2 Colon1_T 0.131 5 Colo… Colon1 CRC
#> 3 Colon2_N 4.42 5 Colo… Colon2 Norm…
#> 4 Colon2_T 2.50 5 Colo… Colon2 CRC
#> 5 Lung1_N 2.49 5 Lung… Lung1 Norm…
#> 6 Lung1_T 1.66 5 Lung… Lung1 LUAD
#> 7 Lung2_N 2.40 5 Lung… Lung2 Norm…
#> 8 Lung2_T 1.75 5 Lung… Lung2 LUSC
#> 9 Lung3_N 2.56 5 Lung… Lung3 Norm…
#> 10 Lung3_T 1.59 5 Lung… Lung3 LUAD
#> # ℹ abbreviated name: ¹nrpm_num_windows_chr7_slice
#> # ℹ 5 more variables: tumour <chr>, tissue <chr>, age <dbl>, gender <chr>,
#> # stage <chr>
# Median beta over all windows
exampleTumourNormal %>%
summariseAcrossWindows(
fn = median,
normMethod = "beta",
minEnrichment = 3
)
#> Generating table of beta values for 819 regions across 10 samples.
#> Removing NA values on a per-sample basis
#> # A tibble: 10 × 11
#> sample_name beta_median beta_num_windows group patient type tumour tissue
#> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr>
#> 1 Colon1_N 0.234 626 Colon1_N Colon1 Norm… Normal Colon
#> 2 Colon1_T 0.236 819 Colon1_T Colon1 CRC Tumour Colon
#> 3 Colon2_N 0.229 649 Colon2_N Colon2 Norm… Normal Colon
#> 4 Colon2_T 0.236 819 Colon2_T Colon2 CRC Tumour Colon
#> 5 Lung1_N 0.253 819 Lung1_N Lung1 Norm… Normal Lung
#> 6 Lung1_T 0.245 599 Lung1_T Lung1 LUAD Tumour Lung
#> 7 Lung2_N 0.208 819 Lung2_N Lung2 Norm… Normal Lung
#> 8 Lung2_T 0.250 819 Lung2_T Lung2 LUSC Tumour Lung
#> 9 Lung3_N 0.239 754 Lung3_N Lung3 Norm… Normal Lung
#> 10 Lung3_T 0.264 819 Lung3_T Lung3 LUAD Tumour Lung
#> # ℹ 3 more variables: age <dbl>, gender <chr>, stage <chr>