Filter genomic windows based on a summary function applied across selected samples. Typical uses include keeping windows with median NRPM above a threshold, or retaining windows where the minimum beta is below 0.5.

subsetWindowsBySignal(
  qseaSet,
  fn,
  threshold,
  aboveThreshold,
  samples = NULL,
  normMethod = "nrpm",
  useGroupMeans = FALSE
)

Arguments

qseaSet

qseaSet. Input object containing windows and signal.

fn

function. Summary function applied row-wise across the selected samples (e.g., median, min, max). If you need NA handling, provide it explicitly, e.g. function(x) median(x, na.rm = TRUE). Default: none (must be supplied).

threshold

numeric(1). Threshold applied to the summary value returned by fn. Default: none (must be supplied).

aboveThreshold

logical(1). Keep windows with values >= threshold when TRUE; keep windows with values < threshold when FALSE. Default: none (must be supplied).

samples

character() or NULL. Sample names to include, or a single string used as a pattern to match sample names. If NULL, use all samples. Default: NULL.

normMethod

character(1). Normalisation/measure to evaluate. One of "nrpm", "beta", or "counts". Default: "nrpm".

useGroupMeans

logical(1). If TRUE, aggregate replicates by the group column in the sample table and apply fn to group means; if FALSE, use individual samples. Default: FALSE.

Value

A filtered qseaSet containing only the selected windows.

Details

The function builds a window × sample matrix for the chosen normMethod, optionally restricts to samples via samples (exact names or pattern match), computes fn per row, and filters by threshold according to aboveThreshold. Supply a summary function that accepts a numeric vector and returns a scalar; include na.rm = TRUE inside fn if needed.

Examples

data(exampleTumourNormal, package = "mesa")

# Keep windows with median NRPM > 1 across all samples
exampleTumourNormal %>%
  subsetWindowsBySignal(
    fn = median,
    threshold = 1,
    aboveThreshold = TRUE
  )
#> Considering all 10 samples.
#> Generating table of nrpm values for 819 regions across 10 samples.
#> Keeping 131 windows with median above (or equal to) 1 over 10 samples.
#> qseaSet
#> =======================================
#> 10 Samples: 
#> Colon1_N, Colon1_T, Colon2_N, Colon2_T, Lung1_N, Lung1_T, Lung2_N, Lung2_T, Lung3_N, Lung3_T
#> 131 Regions in 22 chromosomes of BSgenome.Hsapiens.NCBI.GRCh38

# Keep windows where the MIN beta < 0.5 in any sample
exampleTumourNormal %>%
  subsetWindowsBySignal(
    fn = min,
    threshold = 0.5,
    aboveThreshold = FALSE,
    normMethod = "beta"
  )
#> Considering all 10 samples.
#> Generating table of beta values for 819 regions across 10 samples.
#> Keeping 792 windows with min below 0.5 over 10 samples.
#> qseaSet
#> =======================================
#> 10 Samples: 
#> Colon1_N, Colon1_T, Colon2_N, Colon2_T, Lung1_N, Lung1_T, Lung2_N, Lung2_T, Lung3_N, Lung3_T
#> 792 Regions in 22 chromosomes of BSgenome.Hsapiens.NCBI.GRCh38

# Restrict to samples whose names contain "Lung"
exampleTumourNormal %>%
  subsetWindowsBySignal(
    fn = median,
    threshold = 1,
    aboveThreshold = TRUE,
    samples = "Lung"
  )
#> Considering 6 samples containing "Lung" in the name.
#> Generating table of nrpm values for 819 regions across 6 samples.
#> Keeping 138 windows with median above (or equal to) 1 over 6 samples.
#> qseaSet
#> =======================================
#> 10 Samples: 
#> Colon1_N, Colon1_T, Colon2_N, Colon2_T, Lung1_N, Lung1_T, Lung2_N, Lung2_T, Lung3_N, Lung3_T
#> 138 Regions in 22 chromosomes of BSgenome.Hsapiens.NCBI.GRCh38

# Use group means instead of individual samples
exampleTumourNormal %>%
  subsetWindowsBySignal(
    fn = median,
    threshold = 1,
    aboveThreshold = TRUE,
    useGroupMeans = TRUE
  )
#> Considering all 10 sample groups.
#> Generating table of nrpm values for 819 regions across 10 sample groups.
#> Keeping 131 windows with median above (or equal to) 1 over 10 sample groups.
#> qseaSet
#> =======================================
#> 10 Samples: 
#> Colon1_N, Colon1_T, Colon2_N, Colon2_T, Lung1_N, Lung1_T, Lung2_N, Lung2_T, Lung3_N, Lung3_T
#> 131 Regions in 22 chromosomes of BSgenome.Hsapiens.NCBI.GRCh38