Tooluniverse gwas trait to gene

From mims-harvard/ToolUniverse · View interactive version

Tooluniverse gwas trait to gene is an AI agent skill from the GitHub repository mims-harvard/ToolUniverse. Discover causal genes for diseases/traits from GWAS data using Open Targets L2G (locus-to-gene) scoring — integrates eQTL, chromatin interaction, and distance evidence. Use for trait-to-gene mapping, drug-target hypothesis generation from GWAS, and replacing the 'nearest gene' heuristic with multi-e

How to use this skill

Skill file

GWAS Trait-to-Gene Discovery

Nearest gene is often wrong. Use L2G (locus-to-gene) scores from Open Targets which integrate eQTL, chromatin interaction, and distance data. L2G > 0.5 is a strong prediction; positional mapping alone should not be used to claim a causal gene. A single GWAS study with p < 5e-8 is suggestive — replication across independent cohorts is required for high confidence. GWAS hits are associations in the studied population; effect sizes and even the implicated gene can differ across ancestries due to differing LD patterns. Treat gene lists from GWAS as ranked candidates for validation, not confirmed causal genes.

LOOK UP DON'T GUESS: never assume trait-to-gene mappings or L2G scores — always call gwas_search_associations and OpenTargets_get_study_credible_sets to retrieve current data; associations are updated as new GWAS are published.

Discover genes associated with diseases and traits using genome-wide association studies (GWAS)

Overview

This skill enables systematic discovery of genes linked to diseases/traits by analyzing GWAS data from two major resources:

Use Cases

Clinical Research

Drug Target Discovery

Functional Genomics

Workflow

1. Trait Search → Search GWAS Catalog by disease/trait name
       ↓
2. SNP Aggregation → Collect genome-wide significant SNPs (p < 5e-8)
       ↓
3. Gene Mapping → Extract mapped genes from associations
       ↓
4. Evidence Ranking → Score by p-value, replication, fine-mapping
       ↓
5. Annotation (Optional) → Add L2G predictions from Open Targets

Key Concepts

Genome-wide Significance

Gene Mapping Methods

Evidence Confidence Levels

Required ToolUniverse Tools

GWAS Catalog (11 tools)

Open Targets Genetics (6 tools)

Parameters

Required

Optional

Output Schema

{
  "genes": [
    {
      "symbol": str,              # Gene symbol (e.g., "TCF7L2")
      "min_p_value": float,       # Most significant p-value
      "evidence_count": int,      # Number of independent studies
      "snps": [str],              # Associated SNP rs IDs
      "studies": [str],           # GWAS study accessions
      "l2g_score": float | null,  # Locus-to-gene score (0-1)
      "credible_sets": int,       # Number of credible sets
      "confidence_level": str     # "High", "Medium", or "Low"
    }
  ],
  "summary": {
    "trait": str,
    "total_associations": int,
    "significant_genes": int,
    "data_sources": ["GWAS Catalog", "Open Targets"]
  }
}

Example Results

Type 2 Diabetes

TCF7L2:  p=1.2e-98, 15 studies, L2G=0.82 → High confidence
KCNJ11:  p=3.4e-67, 12 studies, L2G=0.76 → High confidence
PPARG:   p=2.1e-45, 8 studies,  L2G=0.71 → High confidence
FTO:     p=5.6e-42, 10 studies, L2G=0.68 → High confidence
IRS1:    p=8.9e-38, 6 studies,  L2G=0.54 → High confidence

Alzheimer's Disease

APOE:    p=1.0e-450, 25 studies, L2G=0.95 → High confidence
BIN1:    p=2.3e-89,  18 studies, L2G=0.88 → High confidence
CLU:     p=4.5e-67,  16 studies, L2G=0.82 → High confidence
ABCA7:   p=6.7e-54,  14 studies, L2G=0.79 → High confidence
CR1:     p=8.9e-52,  13 studies, L2G=0.75 → High confidence

Best Practices

1. Use Disease Ontology IDs for Precision

# Instead of:
discover_gwas_genes("diabetes")  # Ambiguous

# Use:
discover_gwas_genes(
    "type 2 diabetes",
    disease_ontology_id="MONDO_0005148"  # Specific
)

2. Filter by Evidence Strength

# For drug targets, require strong evidence:
discover_gwas_genes(
    "coronary artery disease",
    p_value_threshold=5e-10,    # Stricter than GWAS threshold
    min_evidence_count=3,       # Multiple independent studies
    use_fine_mapping=True       # Include L2G predictions
)

3. Interpret Results Carefully

Tool-Specific Notes (Updated)

`gwas_get_variants_for_trait` -- p-value Filtering

This tool has no p-value threshold parameter. A p_value_threshold=... argument is

silently ignored (verified live: output identical with and without it), so filter the

returned associations yourself. Use sort="p_value", direction="asc" to get the strongest

associations first, and page/size to page (metadata.pagination.totalElements is the total).

result = tu.tools.gwas_get_variants_for_trait(
    trait="type 2 diabetes", size=200, sort="p_value", direction="asc"
)

def genome_wide_significant(a, exp=-8, mant=5):        # p < 5e-8
    return (a['pvalue_exponent'], a['pvalue_mantissa']) < (exp, mant)

hits = [a for a in result['data'] if genome_wide_significant(a)]

Filter on pvalue_mantissa and pvalue_exponent, not p_value: the p_value float underflows

to 0.0 for very small p-values (e.g. 3 x 10^-1315), so it cannot be compared to a threshold.

`gwas_get_associations_for_trait` -- BROKEN

This tool returns errors for most queries. Use gwas_search_associations(query=<trait>)

as a reliable alternative. The response format is {data: [{...}], metadata: {...}}.

`gwas_get_snps_for_gene` -- Parameter Rename

The parameter was renamed from mapped_gene to gene_symbol for clarity. Use:

result = tu.tools.gwas_get_snps_for_gene(gene_symbol="TCF7L2")

Programmatic Access (Beyond Tools)

When ToolUniverse tools return limited results or you need the full GWAS Catalog:

import requests, pandas as pd

# Download full GWAS Catalog (all associations, ~37MB TSV)
url = "https://www.ebi.ac.uk/gwas/api/search/downloads/alternative"
df = pd.read_csv(url, sep="\t")
# Filter locally by trait or gene
hits = df[df["DISEASE/TRAIT"].str.contains("type 2 diabetes", case=False, na=False)]
gene_hits = df[df["MAPPED_GENE"].str.contains("TCF7L2", na=False)]

# Per-study associations via REST
study_id = "GCST001234"
assocs = requests.get(f"https://www.ebi.ac.uk/gwas/rest/api/studies/{study_id}/associations").json()

# Summary statistics (when available)
# Check study page for fullPvalueSet=true, then download from linked FTP

See tooluniverse-data-wrangling skill for pagination, bulk download, and format parsing patterns.


Limitations

  1. Gene Mapping Uncertainty
  1. Population Bias
  1. Sample Size Dependence
  1. Validation Bug

Related Skills

Data Sources

GWAS Catalog

Open Targets Genetics

Citation

If you use this skill in research, please cite:

Buniello A, et al. (2019) The NHGRI-EBI GWAS Catalog of published genome-wide
association studies. Nucleic Acids Research, 47(D1):D1005-D1012.

Mountjoy E, et al. (2021) An open approach to systematically prioritize causal
variants and genes at all published human GWAS trait-associated loci.
Nature Genetics, 53:1527-1533.

Support

For issues with:

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.