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
2 changes: 1 addition & 1 deletion .github/environment/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ platforms = [

[tasks]
devtools_document = "cd $GITHUB_WORKSPACE; R -e 'devtools::document()'"
devtools_test = "cd $GITHUB_WORKSPACE; R -e 'devtools::test()'"
devtools_test = "cd $GITHUB_WORKSPACE; R -e 'devtools::test(stop_on_failure = TRUE)'"
codecov = "cd $GITHUB_WORKSPACE; R -e 'covr::codecov(quiet = FALSE)'"
rcmdcheck = "cd $GITHUB_WORKSPACE; R -e 'rcmdcheck::rcmdcheck()'"
bioccheck_git_clone = "cd $GITHUB_WORKSPACE; R -e 'BiocCheck::BiocCheckGitClone()'"
Expand Down
9 changes: 5 additions & 4 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -2281,8 +2281,9 @@ setGeneric("credibleSetSummary", function(x, ...) {
#' the fitted effect curve and its credible band over the functional grid, one
#' row per (credible set, grid position). Wraps the upstream fSuSiE band
#' computation (fsusieR's internal \code{update_cal_credible_band.susiF} +
#' \code{get_fitted_effect}). Requires an UNtrimmed fit (the wavelet slots are
#' dropped by trimming); degrades to zero rows for non-fSuSiE or trimmed fits.
#' \code{get_fitted_effect}). Uses saved bands in trimmed fits, or computes
#' them from an untrimmed fit. Returns zero rows when the functional fields
#' are absent.
#'
#' @param x A \code{FineMappingRow} or \code{FineMappingResultBase}.
#' @param ... Ignored.
Expand All @@ -2303,8 +2304,8 @@ setGeneric("fsusieCredibleBand", function(x, ...) {
#' zero (the genomic footprint of each fSuSiE effect), from the upstream
#' \code{fsusieR::affected_reg}. Returns a \code{GRanges} with the credible-set
#' label, its purity, and the effect \code{direction}
#' (\code{"pos"}/\code{"neg"}; upstream discards it). Requires an UNtrimmed fit;
#' empty otherwise.
#' (\code{"pos"}/\code{"neg"}; upstream discards it). Uses retained functional
#' summaries or an untrimmed fit; empty when those fields are absent.
#'
#' @param x A \code{FineMappingRow} or \code{FineMappingResultBase}.
#' @param ... Ignored.
Expand Down
1 change: 1 addition & 0 deletions R/GenotypeHandle.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ setMethod("show", "GenotypeHandle", function(object) {
#' \code{VariantAnnotation::readVcf} when the source is a VCF.
#' @return A \code{GenotypeHandle} object.
#' @keywords internal
#' @rdname GenotypeHandle-class
GenotypeHandle <- function(
path = NULL,
plink1Prefix = NULL,
Expand Down
4 changes: 2 additions & 2 deletions R/fineMappingRow.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ fineMappingRow <- function(variantIds, susieFit, topLoci, cvResult = NULL) {
.isFsusieFit <- function(fit) {
!is.null(fit) &&
is.list(fit) &&
!is.null(fit$fitted_wc2) &&
!is.null(fit$fitted_func) &&
!is.null(fit$outing_grid) &&
!is.null(fit$alpha)
(!is.null(fit$cred_band) ||
(!is.null(fit$fitted_wc2) && !is.null(fit$alpha)))
}

# Chromosome of the fit's variants (matches topLoci's `chrom`, no "chr").
Expand Down
42 changes: 36 additions & 6 deletions R/fineMappingWrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2238,15 +2238,15 @@ trimFinemappingFit <- function(fit, effectIdx, method, csTables) {
} else {
common
}
# fSuSiE: keep the precomputed variants x features TWAS weight matrix
# (fsusieWeights output, attached as $coef before trimming) so downstream
# TWAS can read it without the dropped wavelet slots.
withCoef <- if (method == "fsusie" && !is.null(fit$coef)) {
list_assign(trimmed, coef = fit$coef)
# fSuSiE: retain the functional summaries alongside the precomputed
# weights, so a trimmed fit still yields curves, bands and TWAS weights
# once the wavelet reconstruction fields are gone.
withFsusie <- if (method == "fsusie") {
.trimAddFsusie(trimmed, fit)
} else {
trimmed
}
`class<-`(withCoef, unique(c(method, "susie")))
`class<-`(withFsusie, unique(c(method, "susie")))
}

# The minimal always-kept subset of a susie fit (pip, credible sets, effect
Expand Down Expand Up @@ -2341,6 +2341,30 @@ trimFinemappingFit <- function(fit, effectIdx, method, csTables) {

# mvsusie-specific slots: per-effect mu2_diag, the coefficient matrix, and the
# conditional lfsr array.
# fSuSiE: the fields the wavelet reconstruction would otherwise take with
# it. The base trimmed fit already keeps alpha, lbf_variable and the sets for
# coloc; these carry the fitted curve, its credible band and the functional
# grid. The band is populated BEFORE trimming because
# .fsusiePopulateCredibleBand() needs the reconstruction fields that trimming
# removes. intersect() rather than a per-field guard: an absent field is
# simply not retained.
# @noRd
.trimAddFsusie <- function(trimmed, fit) {
populated <- if (.isFsusieFit(fit)) {
.fsusiePopulateCredibleBand(fit)
} else {
fit
}
keep <- intersect(
c(
"coef", "fitted_func", "cred_band", "outing_grid", "cs",
"csd_X", "lfsr_func"
),
names(populated)
)
list_assign(trimmed, !!!populated[keep])
}

.trimAddMvsusie <- function(trimmed, fit, effectIdx) {
list_assign(
trimmed,
Expand Down Expand Up @@ -5550,6 +5574,12 @@ krigingOutlierQc <- function(
# @noRd
#' @importFrom rlang try_fetch
.fsusiePopulateCredibleBand <- function(fit) {
# A native post_processing = "none" run can leave zero-filled placeholder
# bands, so only reuse a band once trimming has removed the
# reconstruction fields -- otherwise recompute it.
if (is.null(fit$fitted_wc2) && !is.null(fit$cred_band)) {
return(fit)
}
fn <- try_fetch(
get("update_cal_credible_band.susiF", envir = asNamespace("fsusieR")),
error = function(cnd) NULL
Expand Down
23 changes: 18 additions & 5 deletions R/jointEngine.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ setMethod(
)

# fsusie joint fit (functional SuSiE over the trait domain; individual-level,
# cross-trait). One per-condition entry per trait, with an optional CV slice.
# cross-trait). Keep the first post-processed entry for this joint fit.
# @noRd
.jointFitFsusie <- function(group, Xc, Yc, nCond, cfg, args) {
if (length(.jgTraitPos(group)) != nCond) {
Expand All @@ -295,7 +295,7 @@ setMethod(
)
raw <- exec(fitFsusie, !!!.splitMethodArgs(fitFsusie, fitArgs))
# Collapse the functional fit to a variants x features weight matrix now
# (trimming later drops fitted_wc/csd_X); store on $coef so a trimmed fit
# (trimming later drops fitted_wc); store on $coef so a trimmed fit
# can still yield TWAS weights.
fit <- list_assign(
raw,
Expand All @@ -306,14 +306,27 @@ setMethod(
) |>
.setFinemappingFitClass("fsusie")
cvM <- .jointFsusieCv(Xc, Yc, group, cfg, args, verbose)
map(
seq_len(nCond),
.jointFsusieEntry,
entry <- .jointFsusieEntry(
r = 1L,
fit = fit,
cvM = cvM,
Xc = Xc,
cfg = cfg
)
# ONE entry for the whole joint fit, unlike mvsusie's one-per-condition.
# mvsusie's posteriors carry a conditions axis, so .fmSliceCond() gives
# each condition its own 2-D slice and N rows partition the fit at no
# cost. An fsusie fit has no such axis: each trait is a POSITION on a
# shared functional grid, so `fitted_func` / `cred_band` / `outing_grid`
# describe all traits at once and cannot be sliced per trait. One row per
# trait would therefore store N copies of the same curve.
#
# The trait list itself is not lost -- every row carries the full joint
# membership in its `jointTraits` column. Only the grid POSITIONS are
# unrecoverable from that, and they are what maps a curve position back
# to a trait, so they ride on the fit.
entry@susieFit$trait_positions <- .jgTraitPos(group)
list(entry)
}

# Per-fold fsusie CV slice, or NULL when CV is disabled.
Expand Down
97 changes: 97 additions & 0 deletions man/GenotypeHandle-class.Rd

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

103 changes: 0 additions & 103 deletions man/GenotypeHandle.Rd

This file was deleted.

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

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

Loading
Loading