# 10 Pathway Analysis Logic

## Quick Answer
Pathway Analysis tests over-representation of query-linked genes across pathway sets, reports p-values and BH-FDR q-values, and provides category-level visual views.

## What this does
Runs enrichment statistics and visualizes pathway categories, top pathways, and category-gene connectivity.

## Inputs
- Query-linked gene-set
- Pathway membership table
- p-value cutoff and source filters

## Outputs
- Enriched pathways by category
- Category map and grouped pathway bars
- Category-gene network view

## Interaction UX (Phase 11)
- Category bars are rendered as a compact single chart and support click-to-detail expansion.
- Dot-plot pathways support click-select inline detail (pathway metadata + overlapping genes).
- Category detail lists are accordion-based with gene badges that can be explored in the main graph.

## How calculated
For each pathway, enrichment uses hypergeometric testing on observed overlap vs background. Multiple testing is corrected using BH-FDR. Active filters then drive chart subsets.

Formula (conceptual):
`p_value = P(X >= k | N, K, n)` from hypergeometric distribution, followed by BH adjustment to `q_value`.

The app requires at least one overlapping gene for final gene sets with fewer than 50 genes and at least two overlapping genes for larger sets. Category nodes report pathway count, overlapping genes, mean p-value, and median p-value. Category-map links require more than one shared gene and shared-gene Jaccard `> 0.1`.

## What to download
Download both full and filtered pathway CSVs, plus figure exports for reporting.

## Known limits
Large queries can generate dense pathway graphs. Visual caps improve usability but do not replace full export review.
