Scientific db gwas database

From jackspace/ClaudeSkillz · View interactive version

Scientific db gwas database is an AI agent skill from the GitHub repository jackspace/ClaudeSkillz. Query NHGRI-EBI GWAS Catalog for SNP-trait associations. Search variants by rs ID, disease/trait, gene, retrieve p-values and summary statistics, for genetic epidemiology and polygenic risk scores.

How to use this skill

Skill file

GWAS Catalog Database

Overview

The GWAS Catalog is a comprehensive repository of published genome-wide association studies maintained by the National Human Genome Research Institute (NHGRI) and the European Bioinformatics Institute (EBI). The catalog contains curated SNP-trait associations from thousands of GWAS publications, including genetic variants, associated traits and diseases, p-values, effect sizes, and full summary statistics for many studies.

When to Use This Skill

This skill should be used when queries involve:

Core Capabilities

1. Understanding GWAS Catalog Data Structure

The GWAS Catalog is organized around four core entities:

Key Identifiers:

2. Web Interface Searches

The web interface at https://www.ebi.ac.uk/gwas/ supports multiple search modes:

By Variant (rs ID):

rs7903146

Returns all trait associations for this SNP.

By Disease/Trait:

type 2 diabetes
Parkinson disease
body mass index

Returns all associated genetic variants.

By Gene:

APOE
TCF7L2

Returns variants in or near the gene region.

By Chromosomal Region:

10:114000000-115000000

Returns variants in the specified genomic interval.

By Publication:

PMID:20581827
Author: McCarthy MI
GCST001234

Returns study details and all reported associations.

3. REST API Access

The GWAS Catalog provides two REST APIs for programmatic access:

Base URLs:

API Documentation:

Core Endpoints:

  1. Studies endpoint - /studies/{accessionID}

```python

import requests

# Get a specific study

url = "https://www.ebi.ac.uk/gwas/rest/api/studies/GCST001795"

response = requests.get(url, headers={"Content-Type": "application/json"})

study = response.json()

```

  1. Associations endpoint - /associations

```python

# Find associations for a variant

variant = "rs7903146"

url = f"https://www.ebi.ac.uk/gwas/rest/api/singleNucleotidePolymorphisms/{variant}/associations"

params = {"projection": "associationBySnp"}

response = requests.get(url, params=params, headers={"Content-Type": "application/json"})

associations = response.json()

```

  1. Variants endpoint - /singleNucleotidePolymorphisms/{rsID}

```python

# Get variant details

url = "https://www.ebi.ac.uk/gwas/rest/api/singleNucleotidePolymorphisms/rs7903146"

response = requests.get(url, headers={"Content-Type": "application/json"})

variant_info = response.json()

```

  1. Traits endpoint - /efoTraits/{efoID}

```python

# Get trait information

url = "https://www.ebi.ac.uk/gwas/rest/api/efoTraits/EFO_0001360"

response = requests.get(url, headers={"Content-Type": "application/json"})

trait_info = response.json()

```

4. Query Examples and Patterns

Example 1: Find all associations for a disease

import requests

trait = "EFO_0001360"  # Type 2 diabetes
base_url = "https://www.ebi.ac.uk/gwas/rest/api"

# Query associations for this trait
url = f"{base_url}/efoTraits/{trait}/associations"
response = requests.get(url, headers={"Content-Type": "application/json"})
associations = response.json()

# Process results
for assoc in associations.get('_embedded', {}).get('associations', []):
    variant = assoc.get('rsId')
    pvalue = assoc.get('pvalue')
    risk_allele = assoc.get('strongestAllele')
    print(f"{variant}: p={pvalue}, risk allele={risk_allele}")

Example 2: Get variant information and all trait associations

import requests

variant = "rs7903146"
base_url = "https://www.ebi.ac.uk/gwas/rest/api"

# Get variant details
url = f"{base_url}/singleNucleotidePolymorphisms/{variant}"
response = requests.get(url, headers={"Content-Type": "application/json"})
variant_data = response.json()

# Get all associations for this variant
url = f"{base_url}/singleNucleotidePolymorphisms/{variant}/associations"
params = {"projection": "associationBySnp"}
response = requests.get(url, params=params, headers={"Content-Type": "application/json"})
associations = response.json()

# Extract trait names and p-values
for assoc in associations.get('_embedded', {}).get('associations', []):
    trait = assoc.get('efoTrait')
    pvalue = assoc.get('pvalue')
    print(f"Trait: {trait}, p-value: {pvalue}")

Example 3: Access summary statistics

import requests

# Query summary statistics API
base_url = "https://www.ebi.ac.uk/gwas/summary-statistics/api"

# Find associations by trait with p-value threshold
trait = "EFO_0001360"  # Type 2 diabetes
p_upper = "0.000000001"  # p < 1e-9
url = f"{base_url}/traits/{trait}/associations"
params = {
    "p_upper": p_upper,
    "size": 100  # Number of results
}
response = requests.get(url, params=params)
results = response.json()

# Process genome-wide significant hits
for hit in results.get('_embedded', {}).get('associations', []):
    variant_id = hit.get('variant_id')
    chromosome = hit.get('chromosome')
    position = hit.get('base_pair_location')
    pvalue = hit.get('p_value')
    print(f"{chromosome}:{position} ({variant_id}): p={pvalue}")

Example 4: Query by chromosomal region

import requests

# Find variants in a specific genomic region
chromosome = "10"
start_pos = 114000000
end_pos = 115000000

base_url = "https://www.ebi.ac.uk/gwas/rest/api"
url = f"{base_url}/singleNucleotidePolymorphisms/search/findByChromBpLocationRange"
params = {
    "chrom": chromosome,
    "bpStart": start_pos,
    "bpEnd": end_pos
}
response = requests.get(url, params=params, headers={"Content-Type": "application/json"})
variants_in_region = response.json()

5. Working with Summary Statistics

The GWAS Catalog hosts full summary statistics for many studies, providing access to all tested variants (not just genome-wide significant hits).

Access Methods:

  1. FTP download: http://ftp.ebi.ac.uk/pub/databases/gwas/summary_statistics/
  2. REST API: Query-based access to summary statistics
  3. Web interface: Browse and download via the website

Summary Statistics API Features:

Example: Download summary statistics for a study

import requests
import gzip

# Get available summary statistics
base_url = "https://www.ebi.ac.uk/gwas/summary-statistics/api"
url = f"{base_url}/studies/GCST001234"
response = requests.get(url)
study_info = response.json()

# Download link is provided in the response
# Alternatively, use FTP:
# ftp://ftp.ebi.ac.uk/pub/databases/gwas/summary_statistics/GCSTXXXXXX/

6. Data Integration and Cross-referencing

The GWAS Catalog provides links to external resources:

Genomic Databases:

Functional Resources:

Phenotype Resources:

Following Links in API Responses:

import requests

# API responses include _links for related resources
response = requests.get("https://www.ebi.ac.uk/gwas/rest/api/studies/GCST001234")
study = response.json()

# Follow link to associations
associations_url = study['_links']['associations']['href']
associations_response = requests.get(associations_url)

Query Workflows

Workflow 1: Exploring Genetic Associations for a Disease

  1. Identify the trait using EFO terms or free text:
  1. Query associations via API:

```python

url = f"https://www.ebi.ac.uk/gwas/rest/api/efoTraits/{efo_id}/associations"

```

  1. Filter by significance and population:
  1. Extract variant details:
  1. Cross-reference with other databases:

Workflow 2: Investigating a Specific Genetic Variant

  1. Query the variant:

```python

url = f"https://www.ebi.ac.uk/gwas/rest/api/singleNucleotidePolymorphisms/{rs_id}"

```

  1. Retrieve all trait associations:

```python

url = f"https://www.ebi.ac.uk/gwas/rest/api/singleNucleotidePolymorphisms/{rs_id}/associations"

```

  1. Analyze pleiotropy:
  1. Check genomic context:

Workflow 3: Gene-Centric Association Analysis

  1. Search by gene symbol in web interface or:

```python

url = f"https://www.ebi.ac.uk/gwas/rest/api/singleNucleotidePolymorphisms/search/findByGene"

params = {"geneName": gene_symbol}

```

  1. Retrieve variants in gene region:
  1. Analyze association patterns:
  1. Functional interpretation:

Workflow 4: Systematic Review of Genetic Evidence

  1. Define research question:
  1. Comprehensive variant extraction:
  1. Quality assessment:
  1. Data synthesis:
  1. Export and documentation:

Workflow 5: Accessing and Analyzing Summary Statistics

  1. Identify studies with summary statistics:
  1. Download summary statistics:

```bash

# Via FTP

wget ftp://ftp.ebi.ac.uk/pub/databases/gwas/summary_statistics/GCSTXXXXXX/harmonised/GCSTXXXXXX-harmonised.tsv.gz

```

  1. Query via API for specific variants:

```python

url = f"https://www.ebi.ac.uk/gwas/summary-statistics/api/chromosomes/{chrom}/associations"

params = {"start": start_pos, "end": end_pos}

```

  1. Process and analyze:

Response Formats and Data Fields

Key Fields in Association Records:

Study Metadata Fields:

Pagination:

Results are paginated (default 20 items per page). Navigate using:

Best Practices

Query Strategy

Data Interpretation

Rate Limiting and Ethics

Data Quality Considerations

Python Integration Example

Complete workflow for querying and analyzing GWAS data:

import requests
import pandas as pd
from time import sleep

def query_gwas_catalog(trait_id, p_threshold=5e-8):
    """
    Query GWAS Catalog for trait associations

    Args:
        trait_id: EFO trait identifier (e.g., 'EFO_0001360')
        p_threshold: P-value threshold for filtering

    Returns:
        pandas DataFrame with association results
    """
    base_url = "https://www.ebi.ac.uk/gwas/rest/api"
    url = f"{base_url}/efoTraits/{trait_id}/associations"

    headers = {"Content-Type": "application/json"}
    results = []
    page = 0

    while True:
        params = {"page": page, "size": 100}
        response = requests.get(url, params=params, headers=headers)

        if response.status_code != 200:
            break

        data = response.json()
        associations = data.get('_embedded', {}).get('associations', [])

        if not associations:
            break

        for assoc in associations:
            pvalue = assoc.get('pvalue')
            if pvalue and float(pvalue) <= p_threshold:
                results.append({
                    'variant': assoc.get('rsId'),
                    'pvalue': pvalue,
                    'risk_allele': assoc.get('strongestAllele'),
                    'or_beta': assoc.get('orPerCopyNum') or assoc.get('betaNum'),
                    'trait': assoc.get('efoTrait'),
                    'pubmed_id': assoc.get('pubmedId')
                })

        page += 1
        sleep(0.1)  # Rate limiting

    return pd.DataFrame(results)

# Example usage
df = query_gwas_catalog('EFO_0001360')  # Type 2 diabetes
print(df.head())
print(f"\nTotal associations: {len(df)}")
print(f"Unique variants: {df['variant'].nunique()}")

Resources

references/api_reference.md

Comprehensive API documentation including:

Consult this reference when:

Training Materials

The GWAS Catalog team provides workshop materials:

Important Notes

Data Updates

Citation Requirements

When using GWAS Catalog data, cite:

Limitations

Data Access

Additional Resources

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.