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 the SuSiE-style coefficients in each row's top loci (topLoci); plus MR.both: TWAS Z computed from
twasWeights; MR computed fromfineMappingResult.
Usage
causalInferencePipeline(
gwasSumStats,
twasWeights = NULL,
fineMappingResult = NULL,
weightSelectionParam = WeightSelectionParam(),
mrParam = MrParam(),
combineMethods = NULL,
alleleFlip = TRUE
)Arguments
- gwasSumStats
A
GwasSumStatsobject. Must be QC'd (length(qcInfo(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.- weightSelectionParam
How one TWAS method's weights are picked per
(study, context, trait, gwasStudy)tuple, built withWeightSelectionParam:cutoff(minimum cross-validated r-squared, default0),pvalCutoff(the CV-p-value gate, defaultInf), andmetric/pvalMetricnaming whichcvResultmetrics those two read. Selection runs whencutoff > 0orpvalCutoffis finite; it keeps the highest-metricmethod among those clearing both gates that also produced a finite TWAS Z. Otherwise every method is carried through. Ports the legacytwas_pipelinepick_best_model/update_twas_method.- mrParam
How Mendelian randomization is run, built with
MrParam:method("ivwPerVariant", the default, or"csAware"), the PIP threshold that method reads (pipCutofforcpipCutoff), andpvalCutoff, the TWAS-p-value gate below which MR runs at all (default1, no gate; otherwise the MR columns areNA).- 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.
LD reference compatibility check
If a QTL input
(TwasWeights or QtlFineMappingResult) carries a non-NULL
ldReference, it must be the same LD reference as the
ldReference on gwasSumStats.
The two must be the same kind of reference. Two genotype panels must
share their samples and allele orientation; two LdMatrix objects
must agree on the LD they share; two GenotypeMixture objects must
average the same panels with the same weights. The two need NOT carry
the same variants: QC-ing the two sides separately trims each reference
to its own surviving variants, and a partial overlap only warns. A
mismatch of any of those, or no shared variant at all, is a hard error. A
QTL input with ldReference = 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.
Examples
data(qtlDatasetExample)
data(gwasSumStatsS4Example)
tw <- twasWeightsPipeline(qtlDatasetExample,
methods = "lasso", cisWindow = 1e6)
#> Fitting lasso ...
#> Fitting lasso done in 0.3s
causalInferencePipeline(
gwasSumStats = gwasSumStatsS4Example, twasWeights = tw)
#> GRanges object with 1 range and 14 metadata columns:
#> seqnames ranges strand | qtlStudy context trait
#> <Rle> <IRanges> <Rle> | <character> <character> <character>
#> [1] chr22 14850625-15826991 * | study1 brain ENSG_example
#> method gwasStudy twasZ twasPval waldRatio waldRatioSe
#> <character> <character> <numeric> <numeric> <numeric> <numeric>
#> [1] lasso trait1 -0.18457 0.853566 NA NA
#> mrPval nIV Q I2 nCs
#> <numeric> <integer> <numeric> <numeric> <integer>
#> [1] NA <NA> NA NA <NA>
#> -------
#> seqinfo: 1 sequence from an unspecified genome; no seqlengths