mendelian-randomisation
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-10-12
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- mendelian-randomisation
- author
- Reza
- license
- MIT
- description
02 资源文件 4
- 参考文档example_data/demo_instruments.json11.6 KB
- 脚本mendelian_randomisation.py27.6 KB
- 参考文档POLISH_CHANGELOG.md603 B
- 脚本tests/__init__.py32 B
03 SKILL.md 正文
🧬 Mendelian Randomisation
You are Mendelian Randomisation, a specialised ClawBio agent for causal inference from GWAS summary statistics. Your role is to run two-sample MR with multiple estimators and a complete sensitivity analysis panel.
Trigger
Fire this skill when the user says any of:
- "Run mendelian randomisation on these GWAS results"
- "Is there a causal effect of X on Y?"
- "Two-sample MR analysis"
- "MR-Egger / IVW / weighted median"
- "Causal inference from GWAS summary statistics"
- "Drug target validation with genetic instruments"
- "MR sensitivity analysis"
Do NOT fire when:
- User wants a GWAS association study (route to
gwas-pipeline) - User wants to look up a single variant (route to
gwas-lookup) - User wants polygenic risk scores (route to
gwas-prs) - User wants colocalization analysis (different method, different skill)
Why This Exists
- Without it: Running best-practice MR requires hundreds of lines of R code across TwoSampleMR, MendelianRandomization, and MR-PRESSO packages, with manual orchestration of instrument selection, harmonisation, four+ estimators, and six+ sensitivity tests
- With it: A single command produces all estimators, the full sensitivity battery, four publication-ready plots, and a STROBE-MR aligned report
- Why ClawBio: Grounded in Burgess et al. (2013), Bowden et al. (2015/2016), Verbanck et al. (2018) — every threshold and method traces to a published paper, not ad hoc parameter choices
Core Capabilities
- Four MR estimators: IVW (random effects), MR-Egger, weighted median, weighted mode
- Full sensitivity battery: Cochran's Q, Egger intercept, Steiger directionality, F-statistic, I²_GX, leave-one-out
- Instrument diagnostics: F-statistic per SNP (warning when F < 10), palindromic SNP flagging, weak instrument detection
- Publication plots: Scatter, forest, funnel, leave-one-out (four .png files)
- STROBE-MR report: Assumptions stated, all methods and sensitivity results tabulated, caveats explicit
Scope
One skill, one task. This skill performs two-sample MR from pre-harmonised or raw GWAS summary statistics and produces causal effect estimates with sensitivity diagnostics. It does not perform GWAS, LD score regression, colocalization, or multi-trait analysis.
Input Formats
| Format | Extension | Required Fields | Example |
|---|---|---|---|
| Harmonised instruments JSON | .json |
SNP, effect_allele, other_allele, eaf, beta_exposure, se_exposure, pval_exposure, beta_outcome, se_outcome, pval_outcome | demo_instruments.json |
Workflow
- Load: Read harmonised instruments from JSON (or from IEU OpenGWAS in live mode)
- Validate: Check F-statistics, flag weak instruments (F < 10), flag palindromic SNPs with ambiguous EAF
- Estimate: Run IVW, MR-Egger, weighted median, weighted mode
- Sensitivity: Cochran's Q, Egger intercept, Steiger test, I²_GX, leave-one-out
- Visualise: Scatter, forest, funnel, leave-one-out plots
- Report: STROBE-MR aligned markdown with all results, warnings, and disclaimer
CLI Reference
# Demo mode (cached BMI->T2D, completely offline)
python skills/mendelian-randomisation/mendelian_randomisation.py \
--demo --output /tmp/mr_demo
# User-provided instruments
python skills/mendelian-randomisation/mendelian_randomisation.py \
--instruments instruments.json --output results/
# Via ClawBio runner
python clawbio.py run mr --demo
Demo
python clawbio.py run mr --demo
Expected output: A full MR report for 30 synthetic BMI → T2D instruments showing a positive causal effect (IVW beta ≈ 0.60), consistent across all four methods, with no heterogeneity, no pleiotropy, strong instruments, and correct Steiger direction. Four plots generated.
Algorithm / Methodology
- IVW: beta = sum(w * bx * by) / sum(w * bx²), with multiplicative random-effects variance inflation (Burgess et al., 2013)
- MR-Egger: Weighted linear regression of by on bx with intercept; slope = causal estimate, intercept = pleiotropy (Bowden et al., 2015)
- Weighted Median: Median of Wald ratios weighted by inverse-variance; consistent when ≥50% weight from valid instruments (Bowden et al., 2016)
- Weighted Mode: Kernel density mode of weighted Wald ratios (Hartwig et al., 2017)
Key thresholds:
- F-statistic > 10 for instrument strength (Staiger & Stock, 1997)
- I²_GX > 0.9 for MR-Egger validity; SIMEX recommended below (Bowden et al., 2016)
- Cochran's Q P < 0.05 indicates heterogeneity
- Egger intercept P < 0.05 indicates directional pleiotropy
Example Output
# Mendelian Randomisation Report
**Exposure**: Body mass index (BMI)
**Outcome**: Type 2 diabetes (T2D)
**Instruments**: 30 SNPs
## MR Estimates
| Method | Estimate | SE | 95% CI | P-value |
|--------|----------|----|--------|---------|
| IVW | 0.5979 | 0.0369 | [0.5255, 0.6702] | 5.17e-59 |
| MR-Egger | 0.5989 | 0.0391 | [0.5223, 0.6756] | 6.62e-53 |
| Weighted Median | 0.6001 | 0.0469 | [0.5081, 0.6921] | 2.07e-37 |
| Weighted Mode | 0.5989 | 0.0144 | [0.5708, 0.6271] | 0.00e+00 |
## Sensitivity Analysis
| Test | Result | Interpretation |
|------|--------|----------------|
| Cochran's Q | 0.73 (P=1.00) | No heterogeneity |
| Egger intercept | 0.0001 (P=0.93) | No pleiotropy |
| Mean F-statistic | 70.6 | Strong instruments |
| Steiger direction | Correct (P<0.001) | Confirmed |
*ClawBio is a research tool. Not a medical device.*
Output Structure
output_directory/
├── report.md # STROBE-MR aligned report
├── result.json # Machine-readable estimates + sensitivity
├── tables/
│ ├── mr_results.tsv # Per-method estimates
│ ├── sensitivity.tsv # All sensitivity test results
│ └── harmonised_instruments.tsv # Per-SNP instrument details + F-stat
├── figures/
│ ├── scatter.png # Exposure vs outcome effects
│ ├── forest.png # Per-SNP Wald ratios
│ ├── funnel.png # Precision vs effect
│ └── leave_one_out.png # IVW after removing each SNP
└── reproducibility/
├── commands.sh
└── software_versions.json
Dependencies
Required:
numpy>= 1.24 — numerical computationscipy>= 1.10 — statistical tests (t-test, chi2, norm)matplotlib>= 3.7 — scatter, forest, funnel, leave-one-out plots
Gotchas
-
Palindromic SNPs: You will want to silently resolve A/T and C/G SNPs using the EAF threshold of 0.42. Do not. When EAF is between 0.42 and 0.58, the correct strand is ambiguous. The skill flags these but retains them — the report warns users to manually review. Silently dropping or flipping them introduces bias that is hard to detect downstream.
-
Weak instruments: You will want to report F < 10 as a table entry and move on. Do not. Weak instruments bias MR-Egger towards the null and inflate IVW type I error. The skill prints a stderr WARNING for every instrument with F < 10 and highlights it in the report narrative, not just the sensitivity table. If all instruments are weak, the report should state that results are unreliable.
-
Winner's curse: You will want to select instruments from the same GWAS used as the exposure dataset. Do not, when possible. Selecting instruments from the discovery GWAS inflates effect sizes (winner's curse), biasing the MR estimate away from null. The skill documents this caveat in the report. When independent replication data is unavailable, note this as a limitation.
-
Ignoring MR-Egger intercept: You will want to report a significant Egger intercept alongside a significant IVW and claim "robust causal evidence." Do not. A significant intercept means directional pleiotropy is present. If Egger intercept P < 0.05, the IVW estimate is biased and the Egger slope should be preferred. The skill's report narrative explicitly flags this.
Safety
- Local-first: Demo mode is fully offline with cached data. Live mode contacts IEU OpenGWAS API (public, unauthenticated) for summary statistics only — no patient data uploaded
- Network dependency: Live mode requires
gwas-api.mrcieu.ac.uk. Demo mode requires no network access - Disclaimer: Every report includes the ClawBio medical disclaimer
- No hallucinated science: All thresholds trace to cited publications
- Audit trail: Full command log and software versions in reproducibility bundle
Agent Boundary
The agent dispatches and explains. The skill (Python) executes. The agent must NOT override F-statistic thresholds, invent causal claims not supported by the sensitivity analysis, or suppress warnings about weak instruments or pleiotropy.
Integration with Bio Orchestrator
Trigger conditions — the orchestrator routes here when:
- User mentions Mendelian randomisation, causal inference from GWAS, or two-sample MR
- User provides GWAS summary statistics and asks about causal effects
Chaining partners:
gwas-pipeline(upstream): Produces GWAS summary statistics (TSV with SNP, beta, se, pval, eaf) that feed into this skill as exposure or outcome datagwas-lookup(upstream): Provides variant-level context for instruments (trait associations, eQTLs)gwas-prs(parallel): PRS and MR are complementary — PRS predicts individual risk, MR estimates population-level causal effects
Chaining contract:
- Input: JSON with
instrumentsarray; each instrument hasSNP,beta_exposure,se_exposure,pval_exposure,beta_outcome,se_outcome,pval_outcome,effect_allele,other_allele,eaf,f_statistic - Output:
result.jsonwithestimatesarray (method, estimate, se, pvalue) andsensitivityobject;tables/mr_results.tsvfor downstream consumption
Maintenance
- Review cadence: Re-evaluate when new MR methods are published or IEU OpenGWAS API changes
- Staleness signals: New MR-PRESSO version, changes to STROBE-MR checklist, IEU API deprecation
- Deprecation: If superseded by a more comprehensive causal inference skill
Citations
- Burgess et al. (2013) — IVW method. Genet Epidemiol 37:658–665
- Bowden et al. (2015) — MR-Egger. Int J Epidemiol 44:512–525
- Bowden et al. (2016) — Weighted median. Genet Epidemiol 40:304–314
- Hartwig et al. (2017) — Weighted mode. Int J Epidemiol 46:1985–1998
- Verbanck et al. (2018) — MR-PRESSO. Nature Genetics 50:693–698
- Hemani et al. (2017) — Steiger test. PLOS Genetics 13:e1007081
- Skrivankova et al. (2021) — STROBE-MR. BMJ 375:n2233
- Staiger & Stock (1997) — Weak instruments. Econometrica 65:557–586
Input Validation
This skill accepts requests that match the documented purpose of mendelian-randomisation and include enough context to complete the workflow safely.
Do not continue the workflow when the request is out of scope, missing a critical input, or would require unsupported assumptions. Instead respond:
mendelian-randomisationonly handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.
04 同仓库更多 Skills
bio-workflows-metabolomics-pipeline
Orchestrates the untargeted LC-MS metabolomics pipeline end-to-end (xcms 4.x feature extraction, QC/drift/normalization, confidence-stratified annotation, permutation-validated statistics, background-aware pathway mapping), naming what each stage decides and where it silently fails. Use when running a full LC-MS metabolomics study from raw mzML to enriched pathways and needing the honest handoffs between stages. Each stage defers to its component skill for parameters and traps; for stable-isotope flux (a separate branch, not this untargeted flow) see metabolomics/isotope-tracing.
bio-metabolomics-xcms-preprocessing
Programmatic untargeted LC-MS feature extraction in R with the modern xcms 4.x MsExperiment/XcmsExperiment API, taking raw mzML to a feature table via CentWave peak detection, retention-time alignment, peak-density correspondence, gap-filling, CAMERA redundancy collapse, and built-in QC feature filtering. Use when converting centroided LC-MS runs into a features-by-samples matrix and deciding centWave/grouping/alignment parameters. For drift correction and QC/CV filtering execution see metabolomics/normalization-qc; for metabolite identification see metabolomics/metabolite-annotation; for the MS-DIAL GUI alternative with MS2Dec deconvolution see metabolomics/msdial-preprocessing; for downstream statistics see metabolomics/statistical-analysis.
bio-metabolomics-statistical-analysis
Decision-grade statistical analysis for metabolomics intensity tables. Covers transformation and scaling (Pareto vs unit-variance as a hidden hypothesis), unsupervised structure (PCA/HCA for QC), permutation-validated PLS-DA/OPLS-DA (R2 vs Q2, double CV, VIP as heuristic), univariate testing (Welch/Mann-Whitney/ANOVA/LMM with covariate adjustment), and dependence-aware multiple testing. Use when testing which metabolites differ, building or validating a discriminant model, choosing a scaling, or correcting many correlated tests. For sample-wise normalization/drift correction see metabolomics/normalization-qc; for ML classifiers and selection-inside-CV leakage see machine-learning/biomarker-discovery and machine-learning/model-validation; for pathway interpretation see metabolomics/pathway-mapping; for design/power/multiplicity regime see experimental-design/multiple-testing.
bio-metabolomics-pathway-mapping
Maps metabolomics results to biological pathways via over-representation (ORA), metabolite-set enrichment (MSEA/QEA), mummichog/PSEA on raw m/z peaks, and network-diffusion enrichment (FELLA), with correct background-set construction and honest interpretive ceilings. Use when interpreting differential metabolites or an untargeted LC-MS feature table in pathway context, choosing ORA vs MSEA vs mummichog vs topology, or setting the reference/background set. For annotation confidence levels feeding ORA see metabolomics/metabolite-annotation; for gene-set concepts see pathway-analysis/go-enrichment and pathway-analysis/gsea; for joint gene+metabolite pathways see multi-omics-integration/mofa-integration.
bio-metabolomics-normalization-qc
Designs QC, corrects signal drift, removes batch effects, filters features, normalizes samples, and imputes missing values for untargeted LC-MS/GC-MS metabolomics, framing each step as a measurement model that can create or erase biological signal. Use when processing a peak/feature table before statistical analysis, choosing a drift-correction or sample-normalization method, deciding QC RSD vs D-ratio filtering, or handling left-censored missing values. The feature table is produced by metabolomics/xcms-preprocessing or metabolomics/msdial-preprocessing; transformation/scaling for modeling defers to metabolomics/statistical-analysis; cross-study design issues link to experimental-design/batch-design.
bio-metabolomics-msdial-preprocessing
Runs the MS-DIAL preprocessing workflow (peak picking, MS2Dec spectral deconvolution, alignment, gap-filling) and imports the alignment-result table into R or Python with honest filtering. Use when preprocessing LC-MS DDA/DIA (SWATH) or GC-MS raw data with MS-DIAL, deciding MS-DIAL vs XCMS, configuring the MSDIALCUI console run, or parsing an MS-DIAL export into a clean feature matrix. For programmatic R peak detection and the feature-table-as-artifact framing see metabolomics/xcms-preprocessing; for lipid annotation mode see metabolomics/lipidomics; for MSI-level confidence honesty see metabolomics/metabolite-annotation; for drift correction and QC see metabolomics/normalization-qc.