<div align="center">

# labgenetics

**Genetic variant analysis — pathogenicity, drug interactions, longevity risk scoring.**

<br />

[![Star this repo](https://img.shields.io/github/stars/199-biotechnologies/labgenetics-cli?style=for-the-badge&logo=github&label=%E2%AD%90%20Star%20this%20repo&color=yellow)](https://github.com/199-biotechnologies/labgenetics-cli/stargazers)
&nbsp;&nbsp;
[![Follow @longevityboris](https://img.shields.io/badge/Follow_%40longevityboris-000000?style=for-the-badge&logo=x&logoColor=white)](https://x.com/longevityboris)

<br />

[![Rust](https://img.shields.io/badge/Rust-000000?style=for-the-badge&logo=rust&logoColor=white)](https://www.rust-lang.org/)
&nbsp;
[![License: Proprietary](https://img.shields.io/badge/License-Proprietary-blue?style=for-the-badge)](LICENSE)
&nbsp;
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen?style=for-the-badge)](https://github.com/199-biotechnologies/labgenetics-cli/pulls)

---

Most genetic reports hand you a wall of rsIDs with no context. labgenetics maps each variant to clinical recommendations: what your MTHFR/APOE/BRCA status means, which drugs to skip, what screenings to book.

[Quick Start](#quick-start) | [How It Works](#how-it-works) | [Variant Catalog](#variant-catalog) | [Pharmacogenomics](#pharmacogenomics) | [Pipeline Integration](#pipeline-integration)

</div>

## Why This Exists

Genetic testing got cheap. Interpretation didn't. A raw VCF or 23andMe export is useless without ClinVar and PharmGKB to cross-reference against decades of GWAS literature.

labgenetics does that lookup for you:

- Feed it a VCF, a gene list, or plain text like `"MTHFR C677T TT, APOE e3/e4"`
- Get back pathogenicity calls, risk levels per genotype, drug flags, and next steps
- Every claim backed by PMIDs

## Quick Start

```bash
# Build from source
cd labgenetics && cargo build --release

# Analyze variants from text
labgenetics --genes "MTHFR C677T, APOE e3/e4, Factor V Leiden heterozygous"

# Process a VCF file
labgenetics patient.vcf --json

# Pipe JSON input
echo '["rs1801133", "rs429358"]' | labgenetics --stdin --json

# List all known variants
labgenetics variants
```

## How It Works

```
                        ┌─────────────────────────────┐
                        │         INPUT                │
                        │  VCF · JSON · gene names     │
                        │  rsIDs · free text           │
                        └─────────────┬───────────────┘
                                      │
                                      ▼
                        ┌─────────────────────────────┐
                        │     VARIANT RESOLUTION       │
                        │  rsID matching · gene+name   │
                        │  alias lookup · VCF parsing  │
                        └─────────────┬───────────────┘
                                      │
                        ┌─────────────▼───────────────┐
                        │     CATALOG MATCHING         │
                        │  ClinVar pathogenicity       │
                        │  gnomAD allele frequency     │
                        │  genotype-specific risk      │
                        └─────────────┬───────────────┘
                                      │
                  ┌───────────────────┼───────────────────┐
                  ▼                   ▼                   ▼
        ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
        │  RISK ASSESSMENT │ │  PHARMACOGENOMICS│ │ GENE INTERACTIONS│
        │  per-genotype    │ │  star alleles    │ │  synergistic     │
        │  actionable recs │ │  drug flags      │ │  additive        │
        └─────────┬───────┘ └────────┬────────┘ └────────┬────────┘
                  │                  │                    │
                  └──────────────────┼────────────────────┘
                                     ▼
                        ┌─────────────────────────────┐
                        │         OUTPUT               │
                        │  JSON (piped) · table (TTY)  │
                        └─────────────────────────────┘
```

## Variant Catalog

20 clinically validated variants across 6 categories, each with PMID-backed evidence:

| Category | Variants | Key Genes |
|---|---|---|
| **Metabolic** | MTHFR C677T, MTHFR A1298C, HFE C282Y | Folate metabolism, iron overload |
| **Cardiovascular** | Factor V Leiden, Prothrombin G20210A, APOB R3527Q, 9p21, PCSK9 R46L, ACE I/D | Thrombophilia, familial hypercholesterolemia, CHD risk |
| **Cancer** | BRCA1, BRCA2 | Hereditary breast/ovarian cancer |
| **Neurological** | APOE genotype, COMT Val158Met | Alzheimer's risk, catecholamine metabolism |
| **Pharmacogenomics** | CYP2D6, CYP2C19 | Drug metabolism (codeine, clopidogrel, SSRIs, PPIs) |
| **Longevity** | FOXO3, CETP I405V, TERT, Klotho KL-VS, IL-6 -174G>C | Stress resistance, telomere length, inflammaging |

Every variant includes:
- ClinVar pathogenicity classification
- gnomAD global allele frequency
- Per-genotype risk assessment with actionable clinical recommendations
- Gene-gene interaction flags (e.g., MTHFR + MTRR, Factor V + Prothrombin)

## Pharmacogenomics

Built-in PGx interpretation for CYP2D6 and CYP2C19 star alleles:

| Gene | Poor Metabolizer Impact | Drugs Affected |
|---|---|---|
| **CYP2D6** `*4/*4` | No conversion of prodrugs to active form | Codeine, tramadol, tamoxifen, metoprolol |
| **CYP2D6** `*1/*1xN` | Ultra-rapid: toxicity risk from excess active metabolite | Codeine (respiratory depression risk) |
| **CYP2C19** `*2/*2` | Reduced clopidogrel activation → stent thrombosis risk | Clopidogrel, omeprazole, citalopram |
| **CYP2C19** `*17/*17` | Ultra-rapid PPI metabolism → reduced acid suppression | Omeprazole, lansoprazole |

## Pipeline Integration

Part of the [199 Biotechnologies longevity CLI suite](https://github.com/199-biotechnologies). Composes via JSON piping:

```
Lab PDF → labparse → labassess → assessment JSON
                                        ↕
VCF → labgenetics → variant JSON → combined risk profile
```

Same conventions as the rest of the suite:
- JSON on stdout when piped, tables on TTY
- `--json` to force JSON
- `agent-info` for AI agent discovery
- Exit codes: 0 success, 1 error, 2 config, 3 no-variants

```bash
# AI agent discovery
labgenetics agent-info

# Pipe to downstream tools
labgenetics patient.vcf --json | jq '.data.variants[] | select(.risk_level == "high")'
```

## Output Example

**TTY (human-readable):**
```
  labgenetics Genetic Variant Analysis

┌───────┬───────────┬────────────────┬──────────┬───────────────┬────────────┐
│ Gene  │ Variant   │ Category       │ Risk     │ Pathogenicity │ Actionable │
├───────┼───────────┼────────────────┼──────────┼───────────────┼────────────┤
│ MTHFR │ C677T     │ metabolic      │ moderate │ risk_factor   │ Yes        │
│ APOE  │ e3/e4     │ neurological   │ moderate │ risk_factor   │ Yes        │
│ F5    │ R506Q     │ cardiovascular │ moderate │ pathogenic    │ Yes        │
└───────┴───────────┴────────────────┴──────────┴───────────────┴────────────┘

  → MTHFR C677T:
    • Use methylfolate (5-MTHF) 400-800 µg/day instead of folic acid
    • Monitor homocysteine quarterly — target <8 µmol/L

  → APOE e3/e4:
    • Aggressive ApoB management — target <60 mg/dL
    • Regular cognitive screening after age 50
    • Exercise: 150+ min/week aerobic
```

## Contributing

Active development. To add variants:

1. Fork and clone the repo
2. Add entries to `data/variants.toml` following the existing format
3. Include PMID sources for all clinical claims
4. Submit a PR

Adding a variant is catalog-only. No code changes needed.

## License

Proprietary. 199 Biotechnologies.

---

<div align="center">

Built by [Boris Djordjevic](https://github.com/longevityboris) at [Paperfoot AI](https://paperfoot.com)

<br />

**If this is useful to you:**

[![Star this repo](https://img.shields.io/github/stars/199-biotechnologies/labgenetics-cli?style=for-the-badge&logo=github&label=%E2%AD%90%20Star%20this%20repo&color=yellow)](https://github.com/199-biotechnologies/labgenetics-cli/stargazers)
&nbsp;&nbsp;
[![Follow @longevityboris](https://img.shields.io/badge/Follow_%40longevityboris-000000?style=for-the-badge&logo=x&logoColor=white)](https://x.com/longevityboris)

</div>
