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
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ Collate:
'GenotypeHandle.R'
'AllClasses.R'
'AnnotationMatrix.R'
'FineMappingEntry.R'
'tupleSelectors.R'
'CtwasResult.R'
'CtwasResultEntry.R'
'FineMappingEntry.R'
'GwasFineMappingResult.R'
'H2Estimate.R'
'JointGroup.R'
Expand All @@ -113,6 +115,7 @@ Collate:
'colocPipeline.R'
'colocboostPipeline.R'
'cpp11.R'
'crossValidation.R'
'ctwasPipeline.R'
'deprecated.R'
'exampleData.R'
Expand Down
19 changes: 19 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ S3method(postprocessFinemappingFit,susie)
S3method(postprocessFinemappingFit,susieInf)
S3method(postprocessFinemappingFit,susieRss)
export(AnnotationMatrix)
export(CtwasResult)
export(CtwasResultEntry)
export(FineMappingEntry)
export(GenotypeHandle)
export(GwasFineMappingResult)
Expand All @@ -23,6 +25,8 @@ export(TwasWeightsEntry)
export(adjustPips)
export(alignVariantNames)
export(alleleQc)
export(asCtwasResult)
export(asGranges)
export(assembleCtwasInputs)
export(autoDecision)
export(bLassoWeights)
Expand All @@ -43,7 +47,9 @@ export(colocPipeline)
export(colocPostProcessor)
export(colocWrapper)
export(colocboostPipeline)
export(combineFineMappingResults)
export(combinePValues)
export(combineTwasWeights)
export(computeBlockLdCor)
export(computeCoefficientsGlasso)
export(computeCovDiag)
Expand Down Expand Up @@ -99,12 +105,14 @@ export(getContexts)
export(getCorrelation)
export(getCs)
export(getCtwasMetaData)
export(getCtwasParam)
export(getCvFits)
export(getCvResult)
export(getDataType)
export(getEigenList)
export(getEnrichment)
export(getFineMappingResult)
export(getFinemap)
export(getFits)
export(getFormat)
export(getFrqData)
Expand Down Expand Up @@ -138,6 +146,7 @@ export(getQcInfo)
export(getQtlDatasets)
export(getRefPanel)
export(getRefVariantInfo)
export(getRegion)
export(getResidualizedGenotypes)
export(getResidualizedPhenotypes)
export(getSampleIds)
Expand All @@ -150,6 +159,7 @@ export(getStandardized)
export(getStudy)
export(getSumStats)
export(getSumstatDf)
export(getSusieAlpha)
export(getSusieFit)
export(getSusieResult)
export(getTauBlocks)
Expand Down Expand Up @@ -233,6 +243,7 @@ export(prsCs)
export(prsCsWeights)
export(qtlEnrichment)
export(qtlEnrichmentPipeline)
export(qtlSumStatsFromZMatrix)
export(raiss)
export(readAfreq)
export(readAnnotations)
Expand All @@ -244,6 +255,7 @@ export(regionDataToIndInput)
export(regionDataToRssInput)
export(regionToDf)
export(regionsOverlap)
export(resolveWeights)
export(rssAnalysisPipeline)
export(sanitizeMashData)
export(scadRssWeights)
Expand All @@ -253,6 +265,7 @@ export(sdpr)
export(sdprWeights)
export(slalom)
export(sldscPostprocessingPipeline)
export(sldscSubsetMeta)
export(sliceMashData)
export(standardiseSumstatsColumns)
export(standardizeSldscTrait)
Expand Down Expand Up @@ -304,12 +317,14 @@ exportMethods(getBlocks)
exportMethods(getContexts)
exportMethods(getCorrelation)
exportMethods(getCs)
exportMethods(getCtwasParam)
exportMethods(getCvFits)
exportMethods(getCvResult)
exportMethods(getDataType)
exportMethods(getEigenList)
exportMethods(getEnrichment)
exportMethods(getFineMappingResult)
exportMethods(getFinemap)
exportMethods(getFits)
exportMethods(getFormat)
exportMethods(getFrqData)
Expand Down Expand Up @@ -342,6 +357,7 @@ exportMethods(getQcDiagnostics)
exportMethods(getQcInfo)
exportMethods(getQtlDatasets)
exportMethods(getRefPanel)
exportMethods(getRegion)
exportMethods(getResidualizedGenotypes)
exportMethods(getResidualizedPhenotypes)
exportMethods(getSampleIds)
Expand All @@ -354,6 +370,7 @@ exportMethods(getStandardized)
exportMethods(getStudy)
exportMethods(getSumStats)
exportMethods(getSumstatDf)
exportMethods(getSusieAlpha)
exportMethods(getSusieFit)
exportMethods(getTauBlocks)
exportMethods(getTopLoci)
Expand All @@ -371,6 +388,7 @@ exportMethods(hasGenotypes)
exportMethods(nSnps)
exportMethods(readAnnotations)
exportMethods(readGenotypes)
exportMethods(resolveWeights)
exportMethods(show)
exportMethods(subsetChr)
exportMethods(twasWeightsPipeline)
Expand Down Expand Up @@ -444,6 +462,7 @@ importFrom(stats,complete.cases)
importFrom(stats,cor)
importFrom(stats,cutree)
importFrom(stats,hclust)
importFrom(stats,lm)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,optim)
Expand Down
46 changes: 37 additions & 9 deletions R/AllClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ setGeneric(".fmrSelectEntry", function(x, ...) standardGeneric(".fmrSelectEntry"
setMethod("getCs", "FineMappingResultBase",
function(x, study = NULL, context = NULL, trait = NULL, method = NULL,
region = NULL, coverage = 0.95, ...) {
getCs(.fmrSelectEntry(x, study = study, context = context, trait = trait,
method = method, region = region),
coverage = coverage)
# Selectors pinning one entry -> that entry's bare credible-set table; no /
# partial selectors -> aggregate every matching entry's credible sets,
# prefixed with the row identity (study/context/trait/region_id/method).
.fmrAggregateView(x, study = study, context = context, trait = trait,
method = method, region = region,
perEntry = function(e) getCs(e, coverage = coverage))
})

#' @rdname getTopLoci
Expand All @@ -189,9 +192,27 @@ setMethod("getTopLoci", "FineMappingResultBase",
function(x, type = c("data.frame", "GRanges"), signalCutoff = 0.025,
study = NULL, context = NULL, trait = NULL, method = NULL,
region = NULL, ...) {
getTopLoci(.fmrSelectEntry(x, study = study, context = context,
trait = trait, method = method, region = region),
type = match.arg(type), signalCutoff = signalCutoff)
type <- match.arg(type)
# type = "GRanges" can only be honored for a single pinned entry; the
# aggregate (identity-prefixed) form is data.frame-only.
if (type == "GRanges") {
sel <- tryCatch(
.fmrSelectEntry(x, study = study, context = context, trait = trait,
method = method, region = region),
error = function(e) e)
if (inherits(sel, "error")) {
stop("getTopLoci: aggregating across multiple entries requires ",
"type = 'data.frame'.")
}
return(getTopLoci(sel, type = "GRanges", signalCutoff = signalCutoff))
}
# data.frame: bare per-variant table when selectors pin one entry, else the
# per-variant tables of every matching row stacked with row identity
# (study / context / trait / region_id / method) columns.
.fmrAggregateView(x, study = study, context = context, trait = trait,
method = method, region = region,
perEntry = function(e) getTopLoci(e, type = "data.frame",
signalCutoff = signalCutoff))
})

#' @rdname getMarginalEffects
Expand All @@ -200,11 +221,18 @@ setMethod("getMarginalEffects", "FineMappingResultBase",
function(x, maxPval = NULL,
study = NULL, context = NULL, trait = NULL, method = NULL,
region = NULL, ...) {
getMarginalEffects(.fmrSelectEntry(x, study = study, context = context,
trait = trait, method = method,
region = region), maxPval = maxPval)
# Selectors pinning one entry -> that entry's bare marginal table; no /
# partial selectors -> aggregate every matching entry's marginals, prefixed
# with the row identity (study/context/trait/region_id/method).
.fmrAggregateView(x, study = study, context = context, trait = trait,
method = method, region = region,
perEntry = function(e) getMarginalEffects(e, maxPval = maxPval))
})

#' @rdname getRegion
#' @export
setMethod("getRegion", "FineMappingResultBase", function(x, ...) .getRegionColumn(x))

#' @rdname getSusieFit
#' @export
setMethod("getSusieFit", "FineMappingResultBase",
Expand Down
56 changes: 56 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,50 @@ setGeneric("getCs", function(x, ...) standardGeneric("getCs"))
#' @export
setGeneric("getWeights", function(x, ...) standardGeneric("getWeights"))

#' @title Resolve Per-Variant Weights From a Weight Source
#' @description Return an aligned \code{(variantIds, weights)} pair from a single
#' weight-source entry, so cTWAS and \code{\link{causalInferencePipeline}}
#' extract weights identically whether the source is a
#' \code{TwasWeightsEntry} (its learned weight vector) or a
#' \code{FineMappingEntry} (its topLoci posterior effect).
#' @param x A \code{TwasWeightsEntry} or \code{FineMappingEntry}.
#' @param ... Reserved for future use.
#' @return A \code{list} with \code{variantIds} (character) and \code{weights}
#' (numeric) of equal length; both empty when no usable weights are present.
#' @export
setGeneric("resolveWeights", function(x, ...) standardGeneric("resolveWeights"))

#' @title Get cTWAS Fine-mapping Posteriors
#' @description Return the per-gene (and per-SNP) fine-mapping posterior table
#' from a \code{\link{CtwasResultEntry}} or a \code{\link{CtwasResult}}
#' collection (aggregated across rows, tagged with run identity).
#' @param x A \code{CtwasResultEntry} or \code{CtwasResult}.
#' @param ... Class-specific selection arguments.
#' @return A \code{data.frame} of posteriors (or \code{NULL} when absent).
#' @export
setGeneric("getFinemap", function(x, ...) standardGeneric("getFinemap"))

#' @title Get cTWAS Per-effect Susie Alpha Table
#' @description Return the full per-effect susie alpha table
#' (\code{ctwas::finemap_regions} \code{susie_alpha_res} shape) from a
#' \code{\link{CtwasResultEntry}} or a \code{\link{CtwasResult}} collection
#' (aggregated across rows, tagged with run identity). This is the fuller
#' cTWAS output retained so the raw run is reconstructable.
#' @param x A \code{CtwasResultEntry} or \code{CtwasResult}.
#' @param ... Class-specific selection arguments.
#' @return A \code{data.frame} of per-effect alphas (or \code{NULL} when absent).
#' @export
setGeneric("getSusieAlpha", function(x, ...) standardGeneric("getSusieAlpha"))

#' @title Get cTWAS Group Prior Parameters
#' @description Return the estimated \code{group_prior} / \code{group_prior_var}
#' of a \code{\link{CtwasResultEntry}}.
#' @param x A \code{CtwasResultEntry}.
#' @param ... Reserved for future use.
#' @return The stored parameter object (typically a list), or \code{NULL}.
#' @export
setGeneric("getCtwasParam", function(x, ...) standardGeneric("getCtwasParam"))

#' @title Get Standardized Flag
#' @description Check whether weights are on the standardized scale.
#' @param x A \code{TwasWeightsEntry} or \code{TwasWeights}.
Expand Down Expand Up @@ -591,6 +635,18 @@ setGeneric("getContexts", function(x) standardGeneric("getContexts"))
#' @export
setGeneric("getTraits", function(x) standardGeneric("getTraits"))

#' @title Get Per-Row Genomic Regions
#' @description Return the genomic anchor of each row of a per-tuple collection
#' as a \code{GRanges} with one range per row -- the trait's own region for a
#' \code{TwasWeights}, or the fine-mapping window for a \code{FineMappingResult}.
#' This is location provenance (e.g. for cTWAS LD-block placement).
#' @param x The object.
#' @param ... Reserved for future use.
#' @return A \code{GRanges} with one range per row of \code{x}, or an empty
#' \code{GRanges} when the collection carries no region provenance.
#' @export
setGeneric("getRegion", function(x, ...) standardGeneric("getRegion"))

#' @title Get Residualized Genotypes
#' @description Residualize the genotype matrix against the per-context
#' phenotype covariates and the genotype covariates, optionally
Expand Down
Loading
Loading