Transforms a raw glow_variant_set (from
extract_variant_set) into processed data ready for score
statistics and GLOW variant-set tests. Handles allele flipping, B/PI
computation, LD filtering, rare variant collapsing, and B/PI aggregation.
prepare_glow_input(
variant_set,
B = NULL,
B_func = NULL,
B_model = NULL,
PI = NULL,
PI_models = NULL,
PI_features = NULL,
reference_medians = NULL,
ld_threshold = 0.9,
ld_prefer_keep = "lower_maf",
remove_lindep = TRUE,
mac_threshold = 10L,
collapse_method = "mean",
max_group_size = Inf,
verbose = 1
)A glow_variant_set object from
extract_variant_set.
Numeric vector (length = n_variants) of pre-computed B values, or
NULL. Exactly one of B, B_func, B_model must be
provided.
Function taking a numeric MAF vector and returning B values.
For example:
function(maf) sqrt(-0.14307 * log(maf * (1 - maf)) - 0.19522).
A glow_B_model object. Calls
predict_B internally.
Numeric vector (length = n_variants) of pre-computed PI values, or
NULL. Exactly one of PI and PI_models must be provided.
Either a list from load_PI_models or a
character path to a model directory.
Character vector of annotation column names to use for PI
prediction. Required when using PI_models. If NULL, uses the
default 16 curated PI training features from
.default_PI_features().
Named numeric vector of chromosome-wide annotation
medians for NA imputation (optional). From
compute_annotation_medians. When provided, NA annotation
values are imputed with these medians instead of per-gene column medians.
Numeric (default 0.9). Correlation threshold for LD pruning.
Character (default "lower_maf"). Tie-breaking for LD pruning: "lower_maf", "higher_maf", or "first".
Logical (default TRUE). Remove linearly dependent columns via QR decomposition.
Integer (default 10). MAC threshold for rare variant collapsing. Set to 0 to disable collapsing.
Character (default "mean"). B/PI aggregation method for collapsed groups: "mean", "max", or "sum".
Numeric (default Inf). Maximum variants per collapsed group.
Integer (default 1). Verbosity level.
A glow_input S3 object (see Details), or NULL if too few
variants remain after filtering.
The processing pipeline applies the following steps in order:
Validate inputs
Flip alleles to minor allele coding via flip_alleles
Compute B values (from vector, function, or model)
Compute PI values (from vector or ensemble models)
LD filtering via filter_variants_ld
Rare variant collapsing via collapse_rare_variants
Aggregate B/PI for collapsed groups via aggregate_B_PI
The returned glow_input object contains:
Numeric matrix (n x p_final) of processed genotypes
Numeric vector (length p_final) of B values
Numeric vector (length p_final) of PI values
Logical vector indicating collapsed groups
List mapping final columns to original column indices
Integer vector (length n_after_ld); element
j is the post-filter variant index (i.e., 1-based row index into
the input variant set's variant_info) occupying post-LD column
j. Chained with col_mapping, this traces every post-collapse
test unit back to its post-filter raw variants.
Region information from the input variant set
Raw variant count in the region before any filtering
(from variant_set$n_total_in_region)
Variants remaining after Component 3's filter spec
(QC, variant type, annotation mask, MAF/MAC), i.e., the variants
entering prepare_glow_input
Variants remaining after LD filtering
Variants remaining after rare-variant collapsing
(= final number of columns in G)
Cumulative MAC across all final columns
Character vector of processing step descriptions
extract_variant_set for creating the input variant set,
flip_alleles, filter_variants_ld,
collapse_rare_variants, aggregate_B_PI
if (FALSE) { # \dontrun{
# Extract variant set from GDS
vset <- extract_variant_set(gds, region, filter_spec)
# Method 1: Pre-computed B and PI vectors
result <- prepare_glow_input(vset, B = B_vec, PI = PI_vec)
# Method 2: B from function, PI from models
B_formula <- function(maf) sqrt(-0.14307 * log(maf * (1 - maf)) - 0.19522)
result <- prepare_glow_input(vset, B_func = B_formula,
PI_models = "path/to/models/")
# Method 3: B from trained model
result <- prepare_glow_input(vset, B_model = b_model, PI = PI_vec)
} # }