Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(check.sample.call.rate)
export(check.sample.heterozygosity)
export(check.snp.chromo)
export(check.snp.hwe)
export(check.snp.hwe.chi2)
export(check.snp.maf)
export(check.snp.mgf)
export(check.snp.monomorf)
Expand Down
36 changes: 36 additions & 0 deletions R/utils_fQC.R
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,39 @@ get.hwe.chi2 <- function(snp.summary) {
pvalues <- pchisq(chi2stat, df = 1, lower.tail = FALSE)
return(pvalues)
}

#' Check SNPs for Hardy-Weinberg equilibrium deviation using chi-square p-values
#'
#' This function identifies SNP markers whose Hardy-Weinberg equilibrium (HWE) chi-square p-values
#' indicate significant deviation beyond a specified threshold. It uses the p-values computed by
#' \code{get.hwe.chi2} on the input summary data frame.
#'
#' @param snp.summary A data frame or matrix containing summary statistics for SNP markers.
#' The row names should correspond to SNP identifiers. It must be compatible with
#' the function \code{get.hwe.chi2}.
#' @param max.dev A numeric value specifying the maximum acceptable p-value threshold.
#' SNPs with p-values below this threshold are considered as deviating from HWE.
#'
#' @return A character vector of SNP identifiers (rownames) that fail the HWE test (p-value < \code{max.dev}).
#' If no SNPs fail, an empty vector is returned.
#'
#' @details Any SNP with missing p-value (NA) is treated as not failing (returned as FALSE).
#'
#' @seealso \code{\link{get.hwe.chi2}}
#'
#' @examples
#' # Example usage (assuming snp.summary is precomputed and get.hwe.chi2 is defined)
#' # snps_failed <- check.snp.hwe.chi2(snp.summary, max.dev = 0.05)
#'
#' @export
check.snp.hwe.chi2 <- function (snp.summary, max.dev)
{
pvalues <- get.hwe.chi2(snp.summary)
result <- pvalues < max.dev
result[is.na(result)] <- FALSE
snps <- NULL
if (sum(result) > 0) {
snps <- rownames(snp.summary[result, ])
}
return(snps)
}
36 changes: 36 additions & 0 deletions man/check.snp.hwe.chi2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.