Skip to contents

Tiles the specified region into n_bins equal-width bins, queries each input at those bins, then summarizes (e.g. mean) across all samples. Because every sample is queried on the same bin grid, no re-alignment is needed.

Usage

average_coverage(
  inputs,
  region,
  n_bins = 2000L,
  summary_fun = c("mean", "median", "max", "min", "sum"),
  nans_to_zeros = TRUE,
  verbose = FALSE
)

Arguments

inputs

A character vector of BigWig file paths, or a list of data frames each with columns seqnames, start, end, score.

region

A genomic region string ("chr:start-end") or a GRanges object.

n_bins

Number of equal-width bins to tile the region with (default: 2000).

summary_fun

Summary function applied across samples per bin. One of "mean", "median", "max", "min", "sum" (default: "mean").

nans_to_zeros

Logical. Replace NA/NaN per-bin scores with 0 before summarizing (default: TRUE).

verbose

Logical. If TRUE, print megadepth progress output when querying BigWig files. If FALSE (default), suppress routine messages.

Value

A data frame with columns seqnames, start, end, score.

Details

For BigWig inputs, megadepth is used directly via .query_megadepth_bins(). For data frame inputs, an overlap-based weighted average is calculated.

Examples

if (FALSE) { # \dontrun{
# Average two BigWig files
avg_df <- average_coverage(
  c("sample1.bw", "sample2.bw"),
  region = "chr1:1000000-2000000",
  n_bins = 1000
)

# Use with ez_coverage for plotting
ez_coverage(avg_df, "chr1:1000000-2000000")

# Average data frames
avg_df <- average_coverage(
  list(df1, df2, df3),
  region = "chr1:1000000-2000000",
  summary_fun = "median"
)
} # }