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
4 changes: 2 additions & 2 deletions R/file_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ load_plink2_data <- function(prefix, region = NULL, keep_indel = TRUE, keep_vari
# --- Attach allele frequency and rescale stochastic genotypes ---
afreq <- read_afreq(prefix)
if (!is.null(afreq)) {
variant_info <- merge(variant_info, afreq[, c("id", "alt_freq", "obs_ct")],
afreq_cols <- intersect(c("id", "alt_freq", "obs_ct", "u_min", "u_max"), colnames(afreq))
variant_info <- merge(variant_info, afreq[, afreq_cols, drop = FALSE],
by = "id", all.x = TRUE, sort = FALSE)
}
# Detect stochastic genotype (non-integer dosage, e.g., from rss_ld_sketch).
Expand Down Expand Up @@ -1591,4 +1592,3 @@ get_filter_lbf_index <- function(susie_obj, coverage = 0.5, size_factor = 0.5) {
# Return filtered lbf_variable rows (one per CS)
return(cs_index)
}

12 changes: 6 additions & 6 deletions R/susie_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ susie_wrapper <- function(X, y, init_L = 5, max_L = 30, l_step = 5, ...) {
#' @param L Initial number of causal configurations.
#' @param max_L Maximum number of causal configurations.
#' @param l_step Step size for increasing L when the limit is reached.
#' @param stochastic_ld_sample Stochastic LD parameter passed to susie_rss.
#' @param sketch_samples Sketch LD parameter passed to susie_rss.
#' NULL (default): no variance inflation. TRUE: infer sketch size from X
#' (requires X, not R). Integer: explicit sketch size (for R only).
#' @param ... Extra parameters passed to susie_rss (e.g., var_y, coverage).
Expand All @@ -165,14 +165,14 @@ susie_wrapper <- function(X, y, init_L = 5, max_L = 30, l_step = 5, ...) {
susie_rss_wrapper <- function(z, R = NULL, X = NULL, n = NULL,
L = 10, max_L = 30, l_step = 5,
coverage = 0.95,
stochastic_ld_sample = NULL, ...) {
sketch_samples = NULL, ...) {
# Validate: exactly one of R or X
if (is.null(R) && is.null(X)) stop("Either R or X must be provided.")
if (!is.null(R) && !is.null(X)) stop("Only one of R or X should be provided, not both.")

# Build argument list for susie_rss
base_args <- list(z = z, n = n, L = L, coverage = coverage,
stochastic_ld_sample = stochastic_ld_sample, ...)
sketch_samples = sketch_samples, ...)
if (!is.null(X)) base_args$X <- X else base_args$R <- R

run_susie <- function(args) do.call(susie_rss, args)
Expand Down Expand Up @@ -216,7 +216,7 @@ susie_rss_wrapper <- function(z, R = NULL, X = NULL, n = NULL,
#' @param secondary_coverage Secondary coverage levels (default: c(0.7, 0.5)).
#' @param signal_cutoff PIP cutoff for susie_post_processor (default: 0.1).
#' @param min_abs_corr Minimum absolute correlation for CS purity (default: 0.8).
#' @param stochastic_ld_sample Passed to susie_rss. NULL, TRUE, or integer.
#' @param sketch_samples Passed to susie_rss. NULL, TRUE, or integer.
#' @param ... Additional parameters passed to susie_rss (e.g., var_y).
#' @return A list with post-processed SuSiE RSS results.
#' @importFrom magrittr %>%
Expand All @@ -229,7 +229,7 @@ susie_rss_pipeline <- function(sumstats, LD_mat = NULL, X_mat = NULL, n = NULL,
secondary_coverage = c(0.7, 0.5),
signal_cutoff = 0.1,
min_abs_corr = 0.8,
stochastic_ld_sample = NULL, ...) {
sketch_samples = NULL, ...) {
analysis_method <- match.arg(analysis_method)

if (!is.null(sumstats$z)) {
Expand All @@ -242,7 +242,7 @@ susie_rss_pipeline <- function(sumstats, LD_mat = NULL, X_mat = NULL, n = NULL,

# Common args for susie_rss_wrapper
common <- list(z = z, n = n, coverage = coverage,
stochastic_ld_sample = stochastic_ld_sample, ...)
sketch_samples = sketch_samples, ...)
if (!is.null(X_mat)) common$X <- X_mat else common$R <- LD_mat

if (analysis_method == "single_effect") {
Expand Down
6 changes: 3 additions & 3 deletions R/univariate_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ load_study_LD <- function(ld_path, region) {
#' @param impute Whether to impute missing variants via RAISS (default TRUE).
#' @param impute_opts List of imputation options (rcond, R2_threshold, minimum_ld, lamb).
#' @param pip_cutoff_to_skip PIP threshold for early stopping (default 0, no skip).
#' @param stochastic_ld_sample Passed to susie_rss. NULL (default), TRUE, or integer.
#' @param sketch_samples Passed to susie_rss. NULL (default), TRUE, or integer.
#' @param keep_indel Whether to keep indel variants (default TRUE).
#' @param comment_string Comment character for sumstat file (default "#").
#' @param diagnostics Whether to include diagnostic info (default FALSE).
Expand All @@ -211,7 +211,7 @@ rss_analysis_pipeline <- function(
min_abs_corr = 0.8
),
impute = TRUE, impute_opts = list(rcond = 0.01, R2_threshold = 0.6, minimum_ld = 5, lamb = 0.01),
pip_cutoff_to_skip = 0, stochastic_ld_sample = NULL,
pip_cutoff_to_skip = 0, sketch_samples = NULL,
keep_indel = TRUE, comment_string = "#", diagnostics = FALSE) {
# Detect genotype input: single X matrix or list of X matrices (mixture panel).
# susie_rss accepts X=list(X1, X2, ...) for multi-panel mixture.
Expand Down Expand Up @@ -306,7 +306,7 @@ rss_analysis_pipeline <- function(
secondary_coverage = sec_coverage,
signal_cutoff = finemapping_opts$signal_cutoff,
min_abs_corr = finemapping_opts$min_abs_corr,
stochastic_ld_sample = stochastic_ld_sample
sketch_samples = sketch_samples
)
if (!is.null(qc_method)) {
res$outlier_number <- qc_results$outlier_number
Expand Down
4 changes: 2 additions & 2 deletions man/rss_analysis_pipeline.Rd

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

4 changes: 2 additions & 2 deletions man/susie_rss_pipeline.Rd

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

4 changes: 2 additions & 2 deletions man/susie_rss_wrapper.Rd

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

Loading