Causal Inference Pipeline (TWAS-Z + Mendelian Randomization)
Source:R/causalInferencePipeline.R
causalInferencePipeline.RdPer-region pipeline that pairs QTL-derived weight vectors
(TwasWeights and/or a QTL
QtlFineMappingResult) with one or more GWAS studies
(GwasSumStats) to produce per-tuple TWAS Z-scores and,
when fine-mapping is supplied, Wald-ratio Mendelian Randomization
estimates over the QTL credible sets.
Input combinations:
twasWeightsalone (nofineMappingResult): TWAS Z only, no MR.fineMappingResultalone (notwasWeights): TWAS Z derived from SuSiE-style coefficients carried on thetopLocislot of each FineMappingEntry; plus MR.both: TWAS Z computed from
twasWeights; MR computed fromfineMappingResult.
Usage
causalInferencePipeline(
gwasSumStats,
twasWeights = NULL,
fineMappingResult = NULL,
rsqCutoff = 0,
rsqPvalCutoff = Inf,
rsqOption = "rsq",
rsqPvalOption = c("adj_rsq_pval", "pval"),
mrPipCutoff = 0.5,
mrMethod = c("ivwPerVariant", "csAware"),
mrCpipCutoff = 0.5,
mrPvalCutoff = 1,
combineMethods = NULL,
alleleFlip = TRUE,
...
)Arguments
- gwasSumStats
A
GwasSumStatsobject. Must be QC'd (length(getQcInfo(x)) > 0L).- twasWeights
Optional
TwasWeightscarrying per-(study, context, trait, method) weights. When supplied, drives the TWAS-Z computation.- fineMappingResult
Optional
QtlFineMappingResult. When supplied, drives the MR computation and (whentwasWeights = NULL) the TWAS-Z weights via the SuSiE-style coefficients on each entry'stopLoci.- rsqCutoff
Numeric (length 1). When
> 0, performs CV weight selection (ports the legacytwas_pipelinepick_best_model+update_twas_method): per(study, context, trait, gwasStudy)keep only the method whosecvResultrsqOptionmetric is highest among methods that clear bothrsqCutoffand thersqPvalCutoffgate AND that produced a finite TWAS Z (the NA/Inf re-selection); groups where no method clears the cutoffs are dropped. A group whose methods carry no usablecvResult(the SS-TWAS path) keeps all methods. Needs thetwasWeightscvResult, so selection is a no-op on the fineMappingResult-only path. Default0(no selection; score every method).- rsqPvalCutoff
Numeric (length 1). CV-p-value gate for weight selection (ports legacy
rsq_pval_cutoff): a method is eligible only when itscvResultrsqPvalOptionmetric is< rsqPvalCutoff. DefaultInf(no p-value gate). A finite value activates selection even whenrsqCutoff = 0.- rsqOption
Character. Which
cvResultmetric is the "r-squared" used for the cutoff and ranking (ports legacyrsq_option); typically"rsq"or"adj_rsq". Default"rsq".- rsqPvalOption
Character vector of candidate
cvResultmetric names for the p-value gate (ports legacyrsq_pval_option); the first one present in a tuple's metrics is used. Defaultc("adj_rsq_pval", "pval").- mrPipCutoff
Numeric (length 1). PIP threshold for a
topLocivariant to be used as an instrumental variable. Used only whenmrMethod = "ivwPerVariant". Default0.5.- mrMethod
One of
"ivwPerVariant"(default) or"csAware". The IVW-per-variant method filters topLoci variants bypip > mrPipCutoffand IVW-pools Wald ratios across variants. The CS-aware method groups variants by credible set (columncsin topLoci), computes a PIP-weighted composite Wald ratio per CS usingmrCpipCutoffon the per-CS cumulative PIP, then IVW-pools across CSs and reports Cochran's Q + I-squared in the output columnsQ,I2.- mrCpipCutoff
Numeric (length 1). Cumulative-PIP cutoff for retaining a credible set. Used only when
mrMethod = "csAware". Default0.5.- mrPvalCutoff
Numeric (length 1). TWAS-p-value gate for running MR (ports the legacy
twas_pipelinemr_pval_cutoff): MR is computed for a(qtl tuple, gwas)only when itstwasPval < mrPvalCutoff; otherwise the MR output columns areNA. Default1(no gate; MR runs wherever afineMappingResultentry exists).- combineMethods
Optional character vector forwarded to
combinePValuesfor cross-method combination per(qtlStudy, context, trait, gwasStudy)group.NULL(default) skips combination.- alleleFlip
Logical, default
TRUE. When TRUE, match QTL variants to the GWAS by (chrom, pos) with ref/alt swaps recognized and the exposure effect / weight sign-flipped accordingly; when FALSE, match on exact alleles only, so a ref/alt swap is treated as a distinct variant.- ...
Reserved.
LD-sketch identity check
If a QTL input (TwasWeights or QtlFineMappingResult) carries a
non-NULL ldSketch, it must match the ldSketch on
gwasSumStats. Mismatch is a hard error. A QTL input with
ldSketch = NULL (the fit was learned from individual-level
data) skips the validation for that input.
Output shape
A long-format GRanges with one row per
(qtlStudy, context, trait, method, gwasStudy) tuple,
positioned at the variant span of the QTL weight set, with mcols:
qtlStudy,context,trait,method,gwasStudyIdentity columns.
twasZ,twasPvalPer-tuple TWAS Z and p-value.
waldRatio,waldRatioSe,mrPvalPer-tuple IVW-aggregated Wald-ratio MR estimate, standard error, and p-value. Present only when MR was computed;
NAotherwise.nIVNumber of instrumental variables used in the MR aggregation.