Computes the median of each annotation score across all variants in a GDS file that pass the supplied filter_spec. These medians serve as reference values for imputing NA annotations when computing PI scores per gene, so the filter applied here must match the per-gene filter used by extract_variant_set() — otherwise the global and per-gene imputation pools are drawn from different populations.

compute_annotation_medians(
  gds,
  annotation_names,
  filter_spec,
  sample_id = NULL,
  Annotation_dir = "annotation/info/FunctionalAnnotation",
  Annotation_name_catalog = NULL,
  verbose = 1
)

Arguments

gds

An open SeqVarGDSClass object or a file path to a GDS file. If a file path, the file is opened and closed automatically.

annotation_names

Character vector of annotation column names to compute medians for (e.g., from .default_PI_features()).

filter_spec

A glow_variant_filter object. Applied in full: QC status, variant type, annotation clauses (pLoF, missense, etc.), MAF cutoff, and MAC cutoff. The min_variants field is ignored — this is a reference-pool computation, not a per-gene test, so a small pool is acceptable.

sample_id

Character vector of sample IDs (optional). Used for MAF/MAC computation. If NULL, all samples in the GDS are used.

Annotation_dir

Character. GDS path prefix for annotations. Default: "annotation/info/FunctionalAnnotation".

Annotation_name_catalog

Data frame mapping annotation names to GDS paths. If NULL, uses the package-bundled catalog.

verbose

Integer. Verbosity level (0 = silent, 1 = progress).

Value

Named numeric vector of per-annotation medians. Names correspond to annotation_names. An entry is NA if no non-NA values exist for that annotation across all matching variants.

Details

Filter consistency with per-gene extraction is the point of this function. When prepare_glow_input() falls back to per-gene median imputation for an annotation that is non-NA in at least some of the gene's variants, those variants were selected by extract_variant_set() under the same filter_spec. For consistency, the global reference passed via reference_medians must be drawn from the same filter pool — chromosome-wide instead of gene-scoped. Both functions delegate filtering to the internal .select_variants_by_spec() helper to guarantee this pooling rule by construction.

MAF and MAC are computed from SeqArray::seqAlleleFreq(), which avoids materializing a whole-chromosome dosage matrix and lets this function scale to real WGS cohorts.

Examples

if (FALSE) { # \dontrun{
spec <- coding_filter("plof")
medians <- compute_annotation_medians(
  "chr22.gds",
  annotation_names = c("cadd_phred", "linsight"),
  filter_spec = spec,
  sample_id = my_sample_ids
)
} # }