Compute per-sample summaries across windows and left-join them to the
qseaSet sample table.
addSummaryAcrossWindows(
qseaSet,
regionsToOverlap = NULL,
fn = mean,
suffix = "",
normMethod = c("nrpm", "beta"),
naMethod = "impute",
minEnrichment = 3
)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 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.
character(1).
Optional string appended to output column names (e.g., a region label) so
you can call this repeatedly for different regions.
Default: "".
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. Supported values:
"na.rm" — call fn with na.rm = TRUE (when supported);
"drop" — drop windows with any NA across selected methods;
"impute" — replace missing values via the package’s internal strategy
before summarising.
Default: "impute".
integer(1).
Minimum reads per window required for a non-NA beta (relevant when
normMethod includes "beta").
Default: 3.
A qseaSet with new summary columns appended to its sampleTable.
Internally, this calls summariseAcrossWindows() to compute per-sample
summaries for the requested normMethod(s), then left-joins those summaries
to the sampleTable. Output column names typically encode the method and the
summary function (and include suffix when provided).
summariseAcrossWindows(), getDataTable()
Other window-summaries:
countWindowsAboveCutoff(),
summariseAcrossWindows()
data(exampleTumourNormal, package = "mesa")
# Add mean NRPM and beta across all windows
exampleTumourNormal %>%
addSummaryAcrossWindows(
fn = mean,
normMethod = c("nrpm","beta")
) %>%
getSampleTable()
#> Generating table of nrpm values for 819 regions across 10 samples.Generating table of beta values for 819 regions across 10 samples.
#> sample_name group patient type tumour tissue age gender
#> Colon1_N Colon1_N Colon1_N Colon1 NormalColon Normal Colon 80 F
#> Colon1_T Colon1_T Colon1_T Colon1 CRC Tumour Colon 80 F
#> Colon2_N Colon2_N Colon2_N Colon2 NormalColon Normal Colon 67 F
#> Colon2_T Colon2_T Colon2_T Colon2 CRC Tumour Colon 67 F
#> Lung1_N Lung1_N Lung1_N Lung1 NormalLung Normal Lung 64 F
#> Lung1_T Lung1_T Lung1_T Lung1 LUAD Tumour Lung 64 F
#> Lung2_N Lung2_N Lung2_N Lung2 NormalLung Normal Lung 71 F
#> Lung2_T Lung2_T Lung2_T Lung2 LUSC Tumour Lung 71 F
#> Lung3_N Lung3_N Lung3_N Lung3 NormalLung Normal Lung 72 M
#> Lung3_T Lung3_T Lung3_T Lung3 LUAD Tumour Lung 72 M
#> stage nrpm_mean nrpm_num_windows beta_mean beta_num_windows
#> Colon1_N <NA> 0.8621078 819 0.2831889 626
#> Colon1_T III 1.1367507 819 0.3077768 819
#> Colon2_N <NA> 0.8505191 819 0.2843301 649
#> Colon2_T IV 1.0895907 819 0.3015557 819
#> Lung1_N <NA> 0.6772303 819 0.3093206 819
#> Lung1_T IIA 0.6040407 819 0.3037812 599
#> Lung2_N <NA> 0.6188086 819 0.2750337 819
#> Lung2_T IA 0.9979539 819 0.3237426 819
#> Lung3_N <NA> 0.6850391 819 0.2826574 754
#> Lung3_T IB 1.1158234 819 0.3283100 819
# Maximum NRPM across a small genomic slice
exampleTumourNormal %>%
addSummaryAcrossWindows(
regionsToOverlap = data.frame(
seqnames = 7,
start = 25002001,
end = 25017900
),
fn = max,
normMethod = "nrpm"
) %>%
getSampleTable()
#> Generating table of nrpm values for 5 regions across 10 samples.
#> sample_name group patient type tumour tissue age gender
#> Colon1_N Colon1_N Colon1_N Colon1 NormalColon Normal Colon 80 F
#> Colon1_T Colon1_T Colon1_T Colon1 CRC Tumour Colon 80 F
#> Colon2_N Colon2_N Colon2_N Colon2 NormalColon Normal Colon 67 F
#> Colon2_T Colon2_T Colon2_T Colon2 CRC Tumour Colon 67 F
#> Lung1_N Lung1_N Lung1_N Lung1 NormalLung Normal Lung 64 F
#> Lung1_T Lung1_T Lung1_T Lung1 LUAD Tumour Lung 64 F
#> Lung2_N Lung2_N Lung2_N Lung2 NormalLung Normal Lung 71 F
#> Lung2_T Lung2_T Lung2_T Lung2 LUSC Tumour Lung 71 F
#> Lung3_N Lung3_N Lung3_N Lung3 NormalLung Normal Lung 72 M
#> Lung3_T Lung3_T Lung3_T Lung3 LUAD Tumour Lung 72 M
#> stage nrpm_max nrpm_num_windows
#> Colon1_N <NA> 0.2627712 5
#> Colon1_T III 0.1307766 5
#> Colon2_N <NA> 4.4226993 5
#> Colon2_T IV 2.4971511 5
#> Lung1_N <NA> 2.4905774 5
#> Lung1_T IIA 1.6600984 5
#> Lung2_N <NA> 2.4013738 5
#> Lung2_T IA 1.7504474 5
#> Lung3_N <NA> 2.5569935 5
#> Lung3_T IB 1.5927831 5
# Add summaries repeatedly with different regions using a suffix
exampleTumourNormal %>%
addSummaryAcrossWindows(
regionsToOverlap = data.frame(
seqnames = 7,
start = 25002001,
end = 25017900
),
fn = median,
normMethod = "nrpm",
suffix = "subset"
) %>%
addSummaryAcrossWindows(
fn = median,
normMethod = "nrpm",
suffix = "all"
) %>%
getSampleTable()
#> Generating table of nrpm values for 5 regions across 10 samples.
#> Generating table of nrpm values for 819 regions across 10 samples.
#> sample_name group patient type tumour tissue age gender
#> Colon1_N Colon1_N Colon1_N Colon1 NormalColon Normal Colon 80 F
#> Colon1_T Colon1_T Colon1_T Colon1 CRC Tumour Colon 80 F
#> Colon2_N Colon2_N Colon2_N Colon2 NormalColon Normal Colon 67 F
#> Colon2_T Colon2_T Colon2_T Colon2 CRC Tumour Colon 67 F
#> Lung1_N Lung1_N Lung1_N Lung1 NormalLung Normal Lung 64 F
#> Lung1_T Lung1_T Lung1_T Lung1 LUAD Tumour Lung 64 F
#> Lung2_N Lung2_N Lung2_N Lung2 NormalLung Normal Lung 71 F
#> Lung2_T Lung2_T Lung2_T Lung2 LUSC Tumour Lung 71 F
#> Lung3_N Lung3_N Lung3_N Lung3 NormalLung Normal Lung 72 M
#> Lung3_T Lung3_T Lung3_T Lung3 LUAD Tumour Lung 72 M
#> stage nrpm_median_subset nrpm_num_windows_subset nrpm_median_all
#> Colon1_N <NA> 0.0000000 5 0.0000000
#> Colon1_T III 0.0000000 5 0.1307766
#> Colon2_N <NA> 0.0000000 5 0.2457055
#> Colon2_T IV 0.1783679 5 0.1783679
#> Lung1_N <NA> 0.1245289 5 0.2490577
#> Lung1_T IIA 0.0000000 5 0.1844554
#> Lung2_N <NA> 0.0000000 5 0.1143511
#> Lung2_T IA 0.0000000 5 0.2692996
#> Lung3_N <NA> 0.4261656 5 0.2130828
#> Lung3_T IB 0.1990979 5 0.1990979
#> nrpm_num_windows_all
#> Colon1_N 819
#> Colon1_T 819
#> Colon2_N 819
#> Colon2_T 819
#> Lung1_N 819
#> Lung1_T 819
#> Lung2_N 819
#> Lung2_T 819
#> Lung3_N 819
#> Lung3_T 819