R/select_highlight_regions.R
select_highlight_regions.RdPicks the regions (genes, windows, loci) to highlight on a Manhattan plot.
Returns every region whose p-value is at or below threshold; if fewer
than min_n regions pass, the selection is topped up with the
next-smallest p-values so the plot is never empty (useful when no region
reaches genome-wide significance).
select_highlight_regions(
df,
pvalue_col,
threshold,
label_col = "label",
min_n = 10L
)data.frame of region-level results.
Character. Name of the p-value column (e.g.,
"GLOW_Omni").
Numeric. P-value cutoff; typically 0.05 / nrow(df).
Character. Name of the region-label column. Default
"label".
Integer. Minimum number of regions to return when fewer pass
threshold. Default 10L.
Character vector of region labels sorted by ascending p-value, of
length max(n_pass, min_n) (capped at the number of non-NA
p-values).
The returned labels are taken in ascending p-value order. The selection size
is min(max(n_pass, min_n), n_nonNA), where n_pass is the count
at or below threshold and n_nonNA is the number of non-NA
p-values; the result is empty only when there are no usable p-values.
Complexity is \(O(n \log n)\) from the p-value sort.
df <- data.frame(label = paste0("g", 1:5),
GLOW_Omni = c(1e-9, 0.2, 0.4, 0.6, 0.8))
select_highlight_regions(df, "GLOW_Omni", threshold = 1e-6, min_n = 3L)
#> [1] "g1" "g2" "g3"