Applies a series of quality control filters to GWAS summary statistics, removing variants that don't meet specified criteria.

apply_qc_filters(data, filters = list(), verbose = 1)

Arguments

data

data.frame with GWAS summary statistics

filters

List of filter parameters with elements:

  • min_sample_size: Minimum N (default: 500)

  • max_pvalue: Maximum p-value (default: 1)

  • min_maf: Minimum MAF (default: 0)

  • remove_duplicates: Remove duplicate rsIDs (default: TRUE)

  • remove_na: Remove rows with NA in required columns (default: TRUE)

  • remove_na_cols: Columns that must have non-NA values when remove_na=TRUE (default: c("MAF", "P", "N")). Can be customized by users.

Note: MAF > 0.5 values should be converted to 1 - MAF before calling this function (done automatically in prepare_B_training_data).

verbose

Integer verbosity level (0=silent, 1=messages)

Value

List with elements:

  • data: Filtered data.frame

  • qc_summary: data.frame summarizing what was filtered

Details

Filters are applied in this order:

  1. Clean invalid P-values (P<0 or P>1)

  2. Remove rows with NA in required columns

  3. Filter by sample size

  4. Filter by p-value threshold

  5. Filter by MAF range

  6. Remove duplicate rsIDs

Computational Complexity:

O(n x f) where n = number of variants, f = number of filters (typically f = 6). Current implementation creates multiple data frame copies during filtering, which could be optimized for very large datasets by using a single logical index vector.

Examples

if (FALSE) { # \dontrun{
# Apply strict QC filters with custom required columns
qc_result <- apply_qc_filters(
  data = my_gwas_data,
  filters = list(
    min_sample_size = 10000,
    max_pvalue = 0.001,
    min_maf = 0.01,
    remove_na_cols = c("MAF", "P", "N", "BETA")  # Also require BETA
  )
)

filtered_data <- qc_result$data
print(qc_result$qc_summary)
} # }