Spaces:
Configuration error
Download README.md from Satya737/pgx-analyzer: direct link, hf CLI and curl.
- Browser
- Download file 11.8 kB
-
https://huggingface.co/spaces/Satya737/pgx-analyzer/resolve/main/README.md
- Command line
-
hf download hf://spaces/Satya737/pgx-analyzer/README.md
-
curl -L -o README.md https://huggingface.co/spaces/Satya737/pgx-analyzer/resolve/main/README.md
A newer version of the Streamlit SDK is available: 1.67.0
title: PGx Population Pharmacogenomics Platform
emoji: π§¬
colorFrom: blue
colorTo: indigo
sdk: streamlit
sdk_version: 1.41.1
app_file: app.py
pinned: false
𧬠Automated Population Pharmacogenomics Analysis Platform
An industry-level, production-grade automated platform designed for genotype, allele frequency, HardyβWeinberg Equilibrium (HWE), regional/gender demographic stratification, and CYP2C19 star allele / diplotype / CPIC phenotype classification.
π― 1. Platform Aim & What the Tool Does Exactly
Currently, population pharmacogenomic analysis involves studying the distribution of pharmacogenetic variants across diverse geographic and demographic cohorts. Manual spreadsheet calculations for genotype counts, allele frequencies, HardyβWeinberg Equilibrium (HWE), demographic subgrouping, and diplotype assignment are time-consuming, prone to human error, and unscalable for growing patient cohorts.
This platform automates the complete end-to-end analytical workflow:
- Automated Data Validation & QC: Parses
.xlsx,.xls, and.csvfiles, standardizing raw column headers, detecting duplicate Sample IDs, and quarantining invalid allele calls. - Genetic & Statistical Engine: Instantly computes genotype frequencies, allele frequencies ($p$ and $q$), observed vs. expected counts, Chi-Square goodness-of-fit statistics ($\chi^2$), P-values, and Haldane exact test fallbacks.
- Demographic & Regional Stratification: Categorizes samples across 5 Indian geographic regions (South India, North India, East India, West India, Central India), 27+ individual state profiles, and Male vs. Female subgroups.
- CYP2C19 Star Allele & Phenotype Classifier: Translates *2 (rs4244285), *3 (rs4986893), and *17 (rs12248560) variants into diplotypes (
*1/*1,*1/*2,*1/*17,*2/*17,*2/*2,*17/*17) and CPIC Clinical Metabolizer Phenotypes (Ultrarapid, Rapid, Normal, Intermediate, Poor Metabolizers). - Multi-Format Exporters: Generates publication-ready multi-tab Excel (
.xlsx), summary CSV (.csv), and formal PDF (.pdf) summary reports with one click.
β‘ 2. Automated End-to-End Pipeline Architecture
The platform executes an 11-stage automated pipeline upon dataset upload:
ββββββββββββββββββββββββββ
β Excel / CSV File Uploadβ (.xlsx, .xls, .csv)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Data Validation & QC β (Header normalization, duplicate detection, invalid allele quarantine)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Genotype Normalization β (Genotype string cleaning: G/A -> GA, T/C -> CT)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Genotype Frequencies β (N_AA, N_Aa, N_aa counts, frequencies, percentages)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Allele Frequencies β (Ref/Var allele counts, p and q frequencies)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Hardy-Weinberg Engine β (Observed vs Expected, Chi-Square, P-value, Haldane Exact Test)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Population Grouping β (South, North, East, West, Central India & Gender Subgroups)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Star Allele Calling β (CYP2C19 *2, *3, *17 variant combination mapping)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Diplotype Assignment β (*1/*1, *1/*2, *1/*17, *2/*17, *2/*2, *17/*17)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Phenotype Calling β (CPIC classification: UM, RM, NM, IM, PM)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Interactive Dashboard β (9-Tab Streamlit UI, Plotly charts, HTML warning badges)
βββββββββββββ¬βββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Multi-Format Exporters β (Excel .xlsx, CSV .csv, PDF .pdf reports)
ββββββββββββββββββββββββββ
πΎ 3. Database Architecture & Automated Batch Updates
3.1 Why SQLite Was Chosen
The platform utilizes SQLite (database/db_manager.py $\rightarrow$ pharmacogenomics.db) as its core persistence backend.
- Zero Configuration Overhead: Lightweight, serverless embedded database requiring zero database administration or external daemon processes.
- ACID Compliance & Reliability: Ensures atomic transactions, preventing database corruption during batch sample writes.
- Local Zero-Latency Access: Disk-backed persistence allows instant query execution and in-memory caching.
- High Performance Scaling: Optimized to handle initial cohorts of 1,000 samples, scaling seamlessly to 1,200, 2,000, and 10,000+ samples.
3.2 How Data Updates & Recalculate Automatically
- Deduplication Engine: Every sample is assigned a primary key (
Sample_ID). When a new sample batch is ingested, the engine verifiesSample_IDagainst historical records. - Incremental Batch Appending: New unique patient records are appended to the
samplesdatabase table. - Automatic Recalculation: Upon inserting new records, the analytical engine automatically re-triggers statistical pipelines across the combined dataset, updating all overall, regional, gender, and diplotype/phenotype distributions in real time.
π¬ 4. Analytical Methodology & Formulas
4.1 Allele & Genotype Frequencies
For a locus with Reference allele $A$ and Variant allele $a$, with valid sample size $N$:
- Genotype Frequencies: $$f(AA) = \frac{N_{AA}}{N}, \quad f(Aa) = \frac{N_{Aa}}{N}, \quad f(aa) = \frac{N_{aa}}{N}$$
- Allele Frequencies: $$p = f(A) = \frac{2 N_{AA} + N_{Aa}}{2 N}, \quad q = f(a) = \frac{2 N_{aa} + N_{Aa}}{2 N} = 1 - p$$
4.2 HardyβWeinberg Equilibrium (HWE) & Chi-Square Test
- Expected Genotype Counts: $$E_{AA} = N \cdot p^2, \quad E_{Aa} = N \cdot 2pq, \quad E_{aa} = N \cdot q^2$$
- Chi-Square Goodness-of-Fit Statistic ($\chi^2$, $df = 1$): $$\chi^2 = \frac{(N_{AA} - E_{AA})^2}{E_{AA}} + \frac{(N_{Aa} - E_{Aa})^2}{E_{Aa}} + \frac{(N_{aa} - E_{aa})^2}{E_{aa}}$$
- P-value Calculation: $$\text{P-value} = 1 - \text{CDF}_{\chi^2_1}(\chi^2)$$
- Critical Threshold: $\chi^2 \ge 3.841$ ($\alpha = 0.05$). Values $\ge 3.841$ indicate deviation from HWE and are highlighted with a bright red warning badge (
β οΈ ChiΒ² β₯ 3.841). - Haldane Exact Test: Automatically triggered when any expected count $E < 5$ to prevent Chi-square small-sample bias.
4.3 3-Tier Demographic Gazetteer Engine
Samples are assigned to 5 geographic regions using a 3-tier lookup priority:
- South India: Tamil Nadu, Kerala, Karnataka, Andhra Pradesh, Telangana, Puducherry, Lakshadweep.
- North India: Delhi, Punjab, Haryana, Himachal Pradesh, Jammu & Kashmir, Ladakh, Uttarakhand, Uttar Pradesh.
- East India: West Bengal, Odisha, Bihar, Jharkhand, Assam, Sikkim, Arunachal Pradesh, Manipur, Meghalaya, Mizoram, Nagaland, Tripura, Andaman & Nicobar.
- West India: Maharashtra, Gujarat, Goa, Rajasthan, Dadra & Nagar Haveli, Daman & Diu.
- Central India: Madhya Pradesh, Chhattisgarh.
4.4 CPIC CYP2C19 Metabolizer Phenotype Translation Matrix
| Diplotype Call | CPIC Metabolizer Phenotype | Activity Score | Functional Description |
|---|---|---|---|
*17/*17 |
Ultrarapid Metabolizer (UM) | $> 2.0$ | Increased enzyme activity (Hom. Gain of Function) |
*1/*17 |
Rapid Metabolizer (RM) | $1.5$ | Increased enzyme activity (Het. Gain of Function) |
*1/*1 |
Normal Metabolizer (NM) | $2.0$ | Normal enzyme activity (Wildtype) |
*1/*2, *1/*3, *2/*17, *3/*17 |
Intermediate Metabolizer (IM) | $0.5 - 1.0$ | Reduced enzyme activity |
*2/*2, *2/*3, *3/*3 |
Poor Metabolizer (PM) | $0.0$ | No enzyme activity (Hom. Loss of Function) |
π 5. Project Directory Structure
analysis tools/
βββ app.py # 9-Tab Streamlit Web Dashboard UI & Workflow Renderer
βββ config.py # Global SNP configurations, Gazetteer rules & CPIC matrix
βββ core/ # Core Analytical & Statistical Engine Package
β βββ __init__.py
β βββ qc.py # Data Quality Control, Validation & Cleaning Engine
β βββ stats.py # Genotype, Allele Frequency & HWE Engine
β βββ stratification.py # Demographic & Geographic Stratification Engine
β βββ cyp2c19.py # CYP2C19 Star Allele, Diplotype & Phenotype Classifier
βββ database/ # Data Persistence Layer
β βββ __init__.py
β βββ db_manager.py # SQLite database manager for batch sample growth (1k -> 10k+)
βββ reports/ # Exporter & Reporting Layer
β βββ __init__.py
β βββ report_generator.py # Multi-Tab Excel (.xlsx), CSV, and PDF Report Exporter
βββ tests/ # Automated Unit Test Suite (PyTest)
β βββ __init__.py
β βββ test_qc.py
β βββ test_stats.py
β βββ test_stratification.py
β βββ test_cyp2c19.py
β βββ test_db_manager.py
β βββ test_report_generator.py
βββ .streamlit/ # Streamlit UI server and theme configuration
β βββ config.toml
βββ requirements.txt # Python dependencies (Pandas, SciPy, Plotly, ReportLab, etc.)
βββ README.md # Full platform documentation & methodology guide
π 6. How to Run & Test
6.1 Execute Web Application Dashboard
python3 -m streamlit run app.py
Access the web dashboard in your browser at http://localhost:8501.
6.2 Execute Automated Unit Test Suite
python3 -m pytest tests/
Executes all 8 automated tests for QC, statistics, HWE Chi-Square, diplotype calling, SQLite database, and report exporters (100% pass rate).
π 7. License & Compliance
Designed for research and population pharmacogenomics analysis in compliance with CPIC guidelines.