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
9 changes: 3 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ VignetteBuilder: knitr
Config/roxygen2/version: 8.0.0
RoxygenNote: 7.3.3
Collate:
'allGenerics.R'
'AllGenerics.R'
'GenotypeHandle.R'
'AllClasses.R'
'AnnotationMatrix.R'
'FineMappingEntry.R'
'FineMappingResultBase.R'
'GenotypeHandle.R'
'tupleSelectors.R'
'GwasFineMappingResult.R'
'H2Estimate.R'
Expand All @@ -105,14 +105,12 @@ Collate:
'QtlDataset.R'
'MultiStudyQtlDataset.R'
'QtlFineMappingResult.R'
'SumStatsBase.R'
'TwasWeightsEntry.R'
'causalInferencePipeline.R'
'colocPipeline.R'
'colocboostPipeline.R'
'cpp11.R'
'ctwasPipeline.R'
'ctwasWrapper.R'
'deprecated.R'
'exampleData.R'
'fineMappingPipeline.R'
Expand All @@ -121,7 +119,6 @@ Collate:
'gwasSumStats.R'
'h2Annotations.R'
'h2EstimationWrappers.R'
'jointDispatchers.R'
'jointSpecification.R'
'ld.R'
'mashPipeline.R'
Expand Down
11 changes: 4 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export(getCs)
export(getCtwasMetaData)
export(getCvPerformance)
export(getDataType)
export(getEffects)
export(getEigenList)
export(getEnrichment)
export(getFineMappingResult)
Expand All @@ -105,17 +104,16 @@ export(getGenotypeHandle)
export(getGenotypes)
export(getH2)
export(getInSample)
export(getLbf)
export(getLdBlocks)
export(getLdMatrixList)
export(getLdScoreWeights)
export(getLdScores)
export(getLdSketch)
export(getLocal)
export(getMaf)
export(getMarginalEffects)
export(getMethodNames)
export(getMixtureWeights)
export(getMolecularId)
export(getN)
export(getNRef)
export(getNSamples)
Expand All @@ -140,16 +138,15 @@ export(getStandardized)
export(getStudy)
export(getSumStats)
export(getSumstatDf)
export(getSusieFit)
export(getSusieResult)
export(getTauBlocks)
export(getTopLoci)
export(getTraits)
export(getTrimmedFit)
export(getTwasWeights)
export(getVarY)
export(getVariantIds)
export(getVariantInfo)
export(getVariantNames)
export(getWeights)
export(getZ)
export(glmnetWeights)
Expand Down Expand Up @@ -243,7 +240,6 @@ export(susieInfWeights)
export(susieRssPipeline)
export(susieRssWeights)
export(susieWeights)
export(trimCtwasVariants)
export(twasMultivariateWeightsPipeline)
export(twasPipeline)
export(twasPredict)
Expand Down Expand Up @@ -298,6 +294,7 @@ exportMethods(getLdScores)
exportMethods(getLdSketch)
exportMethods(getLocal)
exportMethods(getMaf)
exportMethods(getMarginalEffects)
exportMethods(getMethodNames)
exportMethods(getMixtureWeights)
exportMethods(getN)
Expand All @@ -323,10 +320,10 @@ exportMethods(getStandardized)
exportMethods(getStudy)
exportMethods(getSumStats)
exportMethods(getSumstatDf)
exportMethods(getSusieFit)
exportMethods(getTauBlocks)
exportMethods(getTopLoci)
exportMethods(getTraits)
exportMethods(getTrimmedFit)
exportMethods(getTwasWeights)
exportMethods(getVarY)
exportMethods(getVariantIds)
Expand Down
125 changes: 125 additions & 0 deletions R/AllClasses.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# =============================================================================
# AllClasses.R
# -----------------------------------------------------------------------------
# Virtual base classes shared across the package. Concrete subclasses live
# in their own per-class files (QtlSumStats.R, GwasSumStats.R, QtlDataset.R,
# QtlFineMappingResult.R, GwasFineMappingResult.R, etc.).
#
# Per Bioconductor convention this file is loaded first in the Collate
# ordering (the "AllClasses.R" filename sorts to the top of the alphabet),
# and every method-bearing file uses `@include AllClasses.R` so roxygen
# topologically orders the Collate field for us.
# =============================================================================

#' @include AllGenerics.R GenotypeHandle.R
#' @importFrom methods setClass setMethod new is validObject
NULL

# =============================================================================
# SumStatsBase
# -----------------------------------------------------------------------------
# Shared parent of the QTL and GWAS summary statistics collections.
# Concrete subclasses (QtlSumStats, GwasSumStats) inherit from DFrame and
# share the ldSketch / genome / qcInfo slots. Class-specific accessors
# (getZ / getN / getMaf / nSnps / subsetChr / getVarY / getSumStats)
# stay on the concrete subclass because they rely on the tuple shape
# (3-tuple for QtlSumStats, 1-tuple for GwasSumStats).
# =============================================================================

#' @title Summary Statistics Base Class
#' @description Virtual base class for QTL and GWAS summary statistics
#' collections. Concrete subclasses (\code{QtlSumStats},
#' \code{GwasSumStats}) inherit from \code{DFrame} and share the
#' \code{ldSketch} / \code{genome} / \code{qcInfo} slots.
#' @slot ldSketch The \code{GenotypeHandle} the QC pipeline harmonized
#' against. Required: \code{summaryStatsQc()} sets it.
#' @slot genome Character, genome build label.
#' @slot qcInfo A \code{list} recording which QC steps ran. Empty
#' \code{list()} on construction; populated by \code{summaryStatsQc()}
#' with a per-step audit record (filter names, drop counts, liftover
#' target, RAISS settings, etc.). Fine-mapping and TWAS-weights
#' pipelines reject inputs where \code{length(getQcInfo(x)) == 0L} — the
#' slot serves as both the gating flag and the audit trail.
#' @export
setClass("SumStatsBase",
contains = c("VIRTUAL", "DFrame"),
representation(
ldSketch = "GenotypeHandle",
genome = "character",
qcInfo = "list"
))

#' @rdname getGenome
#' @export
setMethod("getGenome", "SumStatsBase", function(x, ...) x@genome)

#' @rdname getQcInfo
#' @export
setMethod("getQcInfo", "SumStatsBase", function(x, ...) x@qcInfo)

#' @rdname getLdSketch
#' @export
setMethod("getLdSketch", "SumStatsBase", function(x, ...) x@ldSketch)

#' @rdname getStudy
#' @export
setMethod("getStudy", "SumStatsBase",
function(x) unique(as.character(x$study)))

# =============================================================================
# FineMappingResultBase
# -----------------------------------------------------------------------------
# Shared parent of the QTL and GWAS fine-mapping result collections.
# Concrete subclasses (QtlFineMappingResult, GwasFineMappingResult) carry
# a DFrame of per-fit rows plus a shared ldSketch slot. Downstream
# pipelines dispatch on FineMappingResultBase for behaviors that apply to
# either flavour, and on the concrete subclass when the tuple shape
# matters.
# =============================================================================

#' @title Fine-Mapping Result Base Class
#' @description Virtual base class for fine-mapping result collections.
#' Concrete subclasses (\code{QtlFineMappingResult},
#' \code{GwasFineMappingResult}) carry a \code{DFrame} of per-fit rows
#' and a shared \code{ldSketch} slot. Downstream pipelines should
#' dispatch on \code{FineMappingResultBase} for behaviors that apply to
#' either flavour, and on the concrete subclass when the tuple shape
#' matters.
#' @slot ldSketch The LD reference \code{GenotypeHandle} the fits were
#' computed against, or \code{NULL} when the fits were derived from
#' individual-level data (no LD reference). Used downstream for
#' cross-pipeline LD-sketch identity validation.
#' @export
setClass("FineMappingResultBase",
contains = c("VIRTUAL", "DFrame"),
representation(ldSketch = "ANY"))

#' @rdname getStudy
#' @export
setMethod("getStudy", "FineMappingResultBase",
function(x) unique(as.character(x$study)))

#' @rdname getLdSketch
#' @export
setMethod("getLdSketch", "FineMappingResultBase",
function(x, ...) x@ldSketch)

#' @rdname getMethodNames
#' @export
setMethod("getMethodNames", "FineMappingResultBase",
function(x) unique(as.character(x$method)))

#' @rdname adjustPips
#' @export
setMethod("adjustPips", "FineMappingResultBase",
function(x, keepVariants, ...) {
if (nrow(x) == 0L) return(x)
entries <- x@listData$entry
for (i in seq_along(entries)) {
adj <- tryCatch(adjustPips(entries[[i]], keepVariants, ...),
error = function(err) NULL)
if (!is.null(adj)) entries[[i]] <- adj
}
x@listData$entry <- entries
x
})
80 changes: 36 additions & 44 deletions R/allGenerics.R → R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -366,35 +366,54 @@ setGeneric("adjustPips",
#' @export
setGeneric("getPip", function(x, ...) standardGeneric("getPip"))

#' @title Get Trimmed Fit
#' @description Extract the trimmed SuSiE fit.
#' @title Get SuSiE Fit
#' @description Extract the SuSiE fit object from a fine-mapping entry
#' or result. The fit may be the trimmed view (when the pipeline ran
#' with the default \code{trim = TRUE}) or the full untrimmed
#' \code{susie()} return (when \code{trim = FALSE}).
#' @param x A \code{FineMappingEntry} or \code{FineMappingResult}.
#' @param ... Class-specific selection arguments.
#' @return A list (trimmed SuSiE fit).
#' @return A list (the SuSiE fit object).
#' @export
setGeneric("getTrimmedFit", function(x, ...) standardGeneric("getTrimmedFit"))
setGeneric("getSusieFit", function(x, ...) standardGeneric("getSusieFit"))

#' @title Get Variant Names
#' @description Extract variant names.
#' @param x A \code{FineMappingResult} object.
#' @title Get Marginal Effects
#' @description Extract per-variant marginal univariate effects from a
#' fine-mapping entry or result. Returns a \code{data.frame} with
#' identity columns (\code{variant_id, chrom, pos, A1, A2}), context
#' (\code{N, MAF}), and the marginal effect columns
#' (\code{beta, se, z, p}). Populated uniformly across the
#' individual-level and RSS paths.
#' @param x A \code{FineMappingEntry} or \code{FineMappingResult}.
#' @param maxPval Optional numeric (length 1). When non-\code{NULL},
#' filter rows where \code{p > maxPval}. Default \code{NULL}
#' (no filter).
#' @param ... Class-specific selection arguments.
#' @return Character vector of variant names.
#' @return A \code{data.frame}.
#' @export
setGeneric("getVariantNames",
function(x, ...) standardGeneric("getVariantNames"))

#' @title Get Top Loci
#' @description Extract the top-loci payload as either a
#' \code{data.frame} (default, the on-disk shape) or a \code{GRanges}
#' (parsed from the \code{variant_id} \code{chr:pos:A2:A1} encoding,
#' with the remaining columns carried into \code{mcols}).
setGeneric("getMarginalEffects",
function(x, maxPval = NULL, ...) standardGeneric("getMarginalEffects"))

#' @title Get Top Loci (posterior view)
#' @description Extract the per-variant posterior fine-mapping payload
#' as either a \code{data.frame} (default) or a \code{GRanges}.
#' Returns identity columns (\code{variant_id, chrom, pos, A1, A2}),
#' context (\code{N, MAF}), the posterior effect columns
#' (\code{beta = posterior_mean, se = posterior_sd}), \code{pip},
#' and credible-set membership columns (\code{cs_95}, etc.).
#' Rows are filtered by PIP by default — set \code{signalCutoff = 0}
#' to return every variant.
#' @param x A \code{FineMappingEntry} or \code{FineMappingResult}.
#' @param type One of \code{"data.frame"} (default) or \code{"GRanges"}.
#' @param signalCutoff Numeric (length 1). Drop rows where
#' \code{pip <= signalCutoff}. Default \code{0.025}. Use
#' \code{signalCutoff = 0} to keep every variant.
#' @param ... Class-specific selection arguments.
#' @return A \code{data.frame} or a \code{GRanges}.
#' @export
setGeneric("getTopLoci",
function(x, type = c("data.frame", "GRanges"), ...)
function(x, type = c("data.frame", "GRanges"),
signalCutoff = 0.025, ...)
standardGeneric("getTopLoci"))

#' @title Get Credible Sets
Expand All @@ -405,23 +424,6 @@ setGeneric("getTopLoci",
#' @export
setGeneric("getCs", function(x, ...) standardGeneric("getCs"))

#' @title Get Log Bayes Factors
#' @description Extract per-variant log Bayes factors from a fine-mapping result.
#' @param x A \code{FineMappingEntry} or \code{FineMappingResult}.
#' @param ... Class-specific selection arguments.
#' @return A data.frame with columns \code{variant_id} and one numeric column
#' per effect.
#' @export
setGeneric("getLbf", function(x, ...) standardGeneric("getLbf"))

#' @title Get Per-Effect Fine-Mapping Summary
#' @description Extract per-effect information from a fine-mapping result.
#' @param x A \code{FineMappingEntry} or \code{FineMappingResult}.
#' @param ... Class-specific selection arguments.
#' @return A data.frame with one row per effect.
#' @export
setGeneric("getEffects", function(x, ...) standardGeneric("getEffects"))

# =============================================================================
# TwasWeights accessor generics
# =============================================================================
Expand Down Expand Up @@ -468,16 +470,6 @@ setGeneric("getFits", function(x, ...) standardGeneric("getFits"))
#' @export
setGeneric("getMethodNames", function(x) standardGeneric("getMethodNames"))

#' @title Get Molecular ID (legacy)
#' @description Legacy accessor. The molecular identifier is now stored
#' as the \code{trait} column on \code{TwasWeights} and
#' \code{FineMappingResult} collections — use \code{getTraits(x)}
#' instead.
#' @param x The object.
#' @return Character vector.
#' @export
setGeneric("getMolecularId", function(x) standardGeneric("getMolecularId"))

#' @title Get Data Type
#' @description Extract the data-type tag.
#' @param x A \code{TwasWeightsEntry} or \code{TwasWeights}.
Expand Down
2 changes: 1 addition & 1 deletion R/AnnotationMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# baseline (always jointly fitted) or candidate (score-tested).
# =============================================================================

#' @include allGenerics.R
#' @include AllGenerics.R
NULL

#' @title Genomic Annotation Matrix
Expand Down
Loading
Loading