Mendelian randomisation

From aipoch/medical-research-skills · View interactive version

Mendelian randomisation is an AI agent skill from the GitHub repository aipoch/medical-research-skills. >-

How to use this skill

Skill file

Source: https://github.com/aipoch/medical-research-skills

🧬 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:

Do NOT fire when:

Why This Exists

Core Capabilities

  1. Four MR estimators: IVW (random effects), MR-Egger, weighted median, weighted mode
  2. Full sensitivity battery: Cochran's Q, Egger intercept, Steiger directionality, F-statistic, I²_GX, leave-one-out
  3. Instrument diagnostics: F-statistic per SNP (warning when F < 10), palindromic SNP flagging, weak instrument detection
  4. Publication plots: Scatter, forest, funnel, leave-one-out (four .png files)
  5. 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

  1. Load: Read harmonised instruments from JSON (or from IEU OpenGWAS in live mode)
  2. Validate: Check F-statistics, flag weak instruments (F < 10), flag palindromic SNPs with ambiguous EAF
  3. Estimate: Run IVW, MR-Egger, weighted median, weighted mode
  4. Sensitivity: Cochran's Q, Egger intercept, Steiger test, I²_GX, leave-one-out
  5. Visualise: Scatter, forest, funnel, leave-one-out plots
  6. 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

  1. IVW: beta = sum(w * bx * by) / sum(w * bx²), with multiplicative random-effects variance inflation (Burgess et al., 2013)
  2. MR-Egger: Weighted linear regression of by on bx with intercept; slope = causal estimate, intercept = pleiotropy (Bowden et al., 2015)
  3. Weighted Median: Median of Wald ratios weighted by inverse-variance; consistent when ≄50% weight from valid instruments (Bowden et al., 2016)
  4. Weighted Mode: Kernel density mode of weighted Wald ratios (Hartwig et al., 2017)

Key thresholds:

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:

Gotchas

Safety

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:

Chaining partners:

Chaining contract:

Maintenance

Citations

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-randomisation only handles its documented workflow. Please provide the missing required inputs or switch to a more suitable skill.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.