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)data.frame with GWAS summary statistics
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).
Integer verbosity level (0=silent, 1=messages)
List with elements:
data: Filtered data.frame
qc_summary: data.frame summarizing what was filtered
Filters are applied in this order:
Clean invalid P-values (P<0 or P>1)
Remove rows with NA in required columns
Filter by sample size
Filter by p-value threshold
Filter by MAF range
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.
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)
} # }