Code
out_dir <- "output/fm_out/"
dir.create(out_dir, showWarnings = FALSE, recursive = TRUE)
library(susieR)
library(data.table)
library(ggplot2)
source("scripts/finemapping/helpers.R")
data_dir <- "input/finemapping/"This notebook is a guided introduction to statistical fine-mapping in a post-GWAS workflow. You will inspect a GWAS summary-statistics table, apply basic quality-control filters, and produce the standard plots used to assess signal quality before moving to gene-level interpretation.
By the end of this notebook, you should be able to: - inspect the main columns in a GWAS summary-statistics file and describe their role in downstream analysis - apply basic quality-control filters, including INFO and minor-allele-frequency thresholds - interpret Manhattan, QQ, and p-value distribution plots to judge signal strength and possible inflation - connect SNP-level association results to the fine-mapping, gene-mapping, and pathway steps that follow
Fine-mapping narrows a GWAS signal from hundreds of candidate SNPs in linkage disequilibrium (LD) to a small credible set (the set of variants that collectively contain the causal variant with 95% probability). If you increase the probability to 99% for example, then more SNPs will be attributed to each credible set to reach that confidence.
In this exercise you will:
L and the LD reference can change how many credible sets you get.We start with the SORCS3 locus (chr10 ~106.45 Mb). Its lead variant is rs11596214. ADHD is a case/control trait, so the sample size passed to SuSiE is the effective N (Neff ~ 51.6k). The LD here is the 1000G EUR reference panel.
SNPs in locus: 1461
LD matrix dim: 1461 1461
| CHR | POS | SNP | Z | N |
|---|---|---|---|---|
| <int> | <int> | <chr> | <dbl> | <int> |
| 10 | 105954394 | rs11191944 | -0.1308085 | 51568 |
| 10 | 105956776 | rs584309 | 0.2107371 | 51568 |
| 10 | 105957561 | rs678292 | 0.2212851 | 51568 |
| 10 | 105957613 | rs677904 | 0.2318341 | 51568 |
| 10 | 105957714 | rs10883979 | 0.3756775 | 51568 |
| 10 | 105958440 | rs10883980 | 0.3755886 | 51568 |
The locus before fine-mapping. First look at the raw association signal, this is the LocusZoom-style view you would see in any GWAS paper.
Before running SuSiE: study the plot above and answer to these Questions.
sum(abs(sumstats$Z) > 5)# Run susie_rss() on this locus.
# Docs: https://www.rdocumentation.org/packages/susieR/versions/0.14.2/topics/susie_rss
fit <- susie_rss(
z = , # the per-SNP Z-scores
R = , # the matched LD matrix (same SNP order as the sumstats)
n = , # which N for a case/control trait? (see the hint below)
L = # allow up to this many independent signals
)HINT: For large R or large XtX, consider installing the Rfast package for better performance.
z = sumstats$Z - the per-SNP Z-scoresR = ld - already matched to the same SNP ordern = sumstats$N[1] - case/control trait, so this is the effective N (Neff), not the raw case+control totalL = 10 - up to 10 independent signals# Plot PIPs along the locus. susie_plot is the built-in view; pip_track() is the
# provided ggplot version (genomic x-axis, coloured by credible set). Compare it
# to the LocusZoom plot above.
susie_plot(fit, y = "PIP", main = "SORCS3 - matched LD (EUR)")
pip_track(fit, sumstats, title = "SORCS3 locus - PIP after fine-mapping (matched LD)")Questions: Interpret the output
length(fit$sets$cs[[1]]))max(susie_get_pip(fit)). Is there a single clear candidate, or is the posterior spread across a wide set?fit$sets$purity): is min.abs.corr ≥ 0.5?You may notice SuSiE returns more than one credible set here.
# Inspect the credible set and purity.
cat("Converged:", fit$converged, "\n")
cat("Number of credible sets:", length(fit$sets$cs), "\n")
cat("Credible set size:", length(fit$sets$cs[[1]]), "SNPs\n")
cat("Top PIP SNP:", sumstats$SNP[which.max(susie_get_pip(fit))], "\n")
cat("Top PIP value:", round(max(susie_get_pip(fit)), 3), "\n")
cat("\nPurity (min.abs.corr >= 0.5 means acceptable):\n")
print(round(fit$sets$purity, 3))Converged: TRUE
Number of credible sets: 2
Credible set size: 6 SNPs
Top PIP SNP: rs11599313
Top PIP value: 0.265
Purity (min.abs.corr >= 0.5 means acceptable):
min.abs.corr mean.abs.corr median.abs.corr
L1 0.922 0.967 0.976
L2 0.916 0.957 0.950
Now rerun the same locus using ld_mismatched.RDS - the 1000G EAS panel (East Asian, shorter LD blocks, different haplotype structure than the European GWAS). The Z-scores are identical, only the reference panel changes.
HINT: For large R or large XtX, consider installing the Rfast package for better performance.
Warning message in susie_suff_stat(XtX = XtX, Xty = Xty, n = n, yty = (n - 1) * :
“IBSS algorithm did not converge in 100 iterations!
Please check consistency between summary statistics and LD matrix.
See https://stephenslab.github.io/susieR/articles/susierss_diagnostic.html”
Run the LD diagnostic, although susie already prints that something might be wrong
# estimate_s_rss() measures global Z-score / LD inconsistency.
# Rule of thumb: s_hat < 0.05 fine, 0.05 to 0.10 marginal, > 0.10 mismatch.
# estimate_s_rss() measures global Z-score / LD inconsistency.
# Rule of thumb: s_hat < 0.05 fine, 0.05 to 0.10 marginal, > 0.10 mismatch.
s_matched <- estimate_s_rss(z = sumstats$Z, R = ld, n = sumstats$N[1]) # matched panel
s_mismatch <- estimate_s_rss(z = sumstats$Z, R = ld_mm, n = sumstats$N[1]) # mismatched panel
cat("s_hat (matched panel): ", round(s_matched, 4), "\n")
cat("s_hat (mismatched panel):", round(s_mismatch, 4), "\n")WARNING: The matrix R is not positive semidefinite. Negative eigenvalues are set to zero WARNING: The matrix R is not positive semidefinite. Negative eigenvalues are set to zero
s_hat (matched panel): 0.0092
s_hat (mismatched panel): 0.6087
s_hat is a single number. The kriging_rss diagnostic is the per-SNP version: for each SNP it compares the observed z to the value expected from its LD neighbours, and flags outliers (in red), variants whose z is inconsistent with the reference panel. Under a matched panel the points sit on the diagonal.
# Run kriging_rss() for each panel and show its diagnostic plot.
# https://www.rdocumentation.org/packages/susieR/versions/0.14.2/topics/kriging_rss
# Same idea, for the matched panel (ld) and the mismatched panel (ld_mm).
k_matched <- kriging_rss(sumstats$Z, ld, n = sumstats$N[1]) # matched panel
k_mismatch <- kriging_rss(sumstats$Z, ld_mm, n = sumstats$N[1]) # mismatched panel
k_matched$plot + ggplot2::ggtitle("Matched LD (EUR) - z on the expected line")
k_mismatch$plot + ggplot2::ggtitle("Mismatched LD (EAS) - outlier z-scores in red")WARNING: The matrix R is not positive semidefinite. Negative eigenvalues are set to zero. WARNING: The matrix R is not positive semidefinite. Negative eigenvalues are set to zero Warning message: “`aes_string()` was deprecated in ggplot2 3.0.0. ℹ Please use tidy evaluation idioms with `aes()`. ℹ See also `vignette("ggplot2-in-packages")` for more information. ℹ The deprecated feature was likely used in the susieR package. Please report the issue at <https://github.com/stephenslab/susieR/issues>.” WARNING: The matrix R is not positive semidefinite. Negative eigenvalues are set to zero. WARNING: The matrix R is not positive semidefinite. Negative eigenvalues are set to zero
# Compare credible sets side by side.
cat("Matched LD\n")
cat("CS size: ", length(fit$sets$cs[[1]]), "SNPs\n")
cat("Purity: ", round(fit$sets$purity[1, "min.abs.corr"], 3), "\n")
cat("\nMismatched LD\n")
cat("CS size: ", length(fit_mm$sets$cs[[1]]), "SNPs\n")
cat("Purity: ", round(fit_mm$sets$purity[1, "min.abs.corr"], 3), "\n")
par(mfrow = c(1, 2))
susie_plot(fit, y = "PIP", main = "Matched LD")
susie_plot(fit_mm, y = "PIP", main = "Mismatched LD")
par(mfrow = c(1, 1))Matched LD
CS size: 6 SNPs
Purity: 0.922
Mismatched LD
CS size: 4 SNPs
Purity: 1
Signs of LD mismatch what to look for:
s_hat > 0.10: global inconsistency between Z-scores and the reference LDmin.abs.corr < 0.5 in fit$sets$purity: credible set contains SNPs that are NOT in tight LD with each other, so the set is not a coherent haplotypeThis mismatch is obvious: East Asian LD on a European GWAS. A mismatch can be less obvious: the same ancestry but a different reference panel. Later you can compare results of two different panels of the same ancestry. Your SuSiE PIPs (1000G EUR LD) and the SBayesRC PIPs (UKB EUR LD) come from different panels, so they will not be the same.
how many independent signals are really here, and how much does the answer depend on your choices? L is the maximum number of independent signals SuSiE may report. Re-fit the locus with L = 1 (assume one causal variant) and with L = 10, and compare how many credible sets come back.
HINT: For large R or large XtX, consider installing the Rfast package for better performance.
HINT: For large R or large XtX, consider installing the Rfast package for better performance.
L = 1 → credible sets found: 0
L = 10 → credible sets found: 2
Interpreting L and the credible sets. L is the maximum number of single-effect (causal) signals SuSiE may place at the locus. Each 95% credible set is a group of variants ≥95% likely to contain one causal variant. If we have genotypes available then our fine-mapping would use in-sample LD; with a reference panel (here 1000G) susie_rss is sensitive to LD mismatch and can return a false-positive credible set, so investigate any extra set (estimate_s_rss) before deciding.
Questions
L = 1 vs L = 10? With L = 1, SuSiE may return zero confident sets. Why might forcing a single effect onto this locus leave nothing that passes the purity/coverage filter?L = 10, what is its purity (fit_l10$sets$purity)? Would you report it?SBayesRC (Zheng et al., Nat Genet 2024) is a genome-wide fine-mapping method that runs Markov chain Monte Carlo (over the full set of GWAS SNPs jointly. Very different from SuSiE’s per-locus approach. MCMC can take a while to run, so we provide pre-computed output for locus 1. You can find the tutorial here: https://gctbhub.cloud.edu.au/software/gctb/#Genome-wideFine-mappinganalysis
Note that SBayesRC in this run uses a different LD reference (UKB EUR) than the SuSiE fit (1000G EUR). So the results are not directly comparable. We provide them like this to open a discussion about the different methods
SBayesRC output columns: Name, Chrom, Position, A1, A2, A1Freq, b, se, p, PIP, Var
| Name | Position | b | se | PIP |
|---|---|---|---|---|
| <chr> | <int> | <dbl> | <dbl> | <dbl> |
| rs7909129 | 106457576 | -0.008129 | 0.008721 | 0.3067860 |
| rs3896224 | 106467853 | 0.003326 | 0.005203 | 0.2206610 |
| rs731163 | 106541900 | -0.003587 | 0.006055 | 0.1291070 |
| rs971527 | 106551929 | -0.002144 | 0.004272 | 0.0915063 |
| rs12413206 | 106469813 | -0.001116 | 0.003006 | 0.0877369 |
| rs970052 | 106534351 | 0.001247 | 0.003594 | 0.0848123 |
# Build a SuSiE PIP table
pip_susie <- data.table(
SNP = sumstats$SNP,
pip_susie = susie_get_pip(fit)
)
# Merge with SBayesRC on SNP name
merged <- merge(pip_susie, sbrc[, .(Name, pip_sbrc = PIP)],
by.x = "SNP", by.y = "Name")
lim <- c(0, max(merged$pip_susie, merged$pip_sbrc) * 1.05)
ggplot(merged, aes(x = pip_susie, y = pip_sbrc)) +
geom_abline(slope = 1, intercept = 0, linetype = "dashed", colour = "grey40") +
geom_point(alpha = 0.4, size = 1) +
coord_equal(xlim = lim, ylim = lim) +
labs(x = "SuSiE PIP", y = "SBayesRC PIP",
title = "Locus 1 SuSiE vs SBayesRC",
subtitle = "Neither method exceeds PIP ≈ 0.3, no single confident variant") +
theme_bw()Discussion questions:
At the end of this exercise you save the SuSiE credible set in a format that you can use later for FLAMES. The expected columns are SNP (format CHR:POS:A1:A2), PIP, locus_id.
# Build the FLAMES input file from your fit object.
# Use only SNPs that are members of the lead credible set.
cs_idx <- fit$sets$cs[[1]] # indices of the lead credible set's members (look inside fit$sets$cs)
head(cs_idx)
cs_snps <- sumstats[cs_idx]
flames_ready <- data.table(
SNP = paste0(cs_snps$CHR, ":", cs_snps$POS, ":", cs_snps$A1, ":", cs_snps$A2),
PIP = susie_get_pip(fit)[cs_idx],
locus_id = "locus1_SORCS3"
)
out_file <- file.path(out_dir, "credible_sets_for_flames.tsv")
fwrite(flames_ready, out_file, sep = " ")
cat("Saved", nrow(flames_ready), "SNPs to", out_file, "\n")Saved 6 SNPs to output/fm_out//credible_sets_for_flames.tsv