# eylernur/genowall architecture

> Architecture diagram of the GitHub repository eylernur/genowall, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eylernur/genowall
- Repository: https://github.com/eylernur/genowall

## Overview

#### Purpose and Entry Points
GenoWall is a research prototype for predicting antimicrobial resistance from an uploaded bacterial genome FASTA, with calibrated per-drug predictions, abstention (“no-call”), and evidence labels. Default scope is *Klebsiella pneumoniae* and four antibiotics.

Runtime entry points:
- FastAPI inference service: `src/api.py`
- Prediction orchestration: `src/predict.py`
- Svelte/Vite browser UI: `ui/src/main.ts`, `ui/src/App.svelte`
- Optional Streamlit frontend: `app/streamlit_app.py`
- Reproducible training pipeline: `Makefile`

#### Genome Annotation and Feature Boundary
Raw genomes and laboratory AST labels are acquired, then each genome is annotated by AMRFinderPlus. Annotation results become binary gene/mutation features subject to configured identity and coverage thresholds.

Core paths:
- `src/ingest_bvbrc.py`
- `src/annotate.py`
- `src/features.py`

Persisted training boundary:
- `data/processed/features.parquet`
- `data/processed/labels.parquet`
- `data/processed/feature_dictionary.csv`

The feature dictionary distinguishes recognized AMR mechanisms from features used only as statistical associations.

#### Leakage-Resistant Model Development
Genomes are grouped by Mash homology before splitting, so closely related genomes cannot cross train, calibration, and held-out test partitions. This is the central generalization-control boundary.

Core paths:
- `src/cluster_split.py`
- `data/processed/splits.json`
- `tests/test_leakage.py`

Per antibiotic, the system trains balanced L2 logistic-regression models and calibrates probabilities using the calibration partition. Shipped artifacts permit inference without recreating training data:
- `src/train.py`
- `models/ciprofloxacin.joblib`
- `models/meropenem.joblib`

#### Decision Layer: Gates, Abstention, Explanation
Inference combines calibrated model probabilities with biological and uncertainty controls. A target-gene gate checks whether expected molecular targets appear intact; no-call rules abstain for uncertain probabilities, gate/model disagreement, or out-of-distribution genomes. Explanation classifies the supporting evidence rather than presenting all features as established mechanisms.

Core paths:
- `src/target_gate.py`
- `src/nocall.py`
- `src/explain.py`

Drug-to-target knowledge is maintained in `drugs.csv`. Evaluation emits held-out discrimination and calibration results in `src/evaluate.py` and `reports/metrics.md`.

#### Online Prediction Flow
`POST /predict` accepts multipart FASTA. The API delegates to prediction orchestration, which performs AMRFinderPlus annotation, feature construction aligned to trained-model features, per-drug scoring, decision controls, and report assembly. `GET /health` exposes runtime scope and safety banners; `GET /metrics` serves reported evaluation output.

Core paths:
- `src/api.py`
- `src/predict.py`
- `src/annotate.py`

This service is intentionally separate from Vercel because annotation requires native bioinformatics tooling and typically takes 1–2 minutes per genome.

#### User Delivery and Deployment Boundary
The Svelte UI uploads FASTA to a configurable HTTPS API endpoint and renders drug cards, recommendation, evidence, PDF download, and sharing. It has a mock/preview mode when no API URL is configured.

Core paths:
- `ui/src/lib/api.ts`
- `ui/src/lib/components/UploadZone.svelte`
- `ui/src/lib/components/DrugCard.svelte`

The UI is deployable to Vercel through `ui/vercel.json`; the Python API must run on a laptop or VM with the Conda environment and AMRFinder database.

#### Material Dependencies and Controls
Python runs with FastAPI, scikit-learn, AMRFinderPlus, and Mash as declared by `environment.yml`; Node 20+ runs the Vite/Svelte frontend through `ui/package.json`. External scientific sources are BV-BRC for genomes/lab phenotypes and NCBI AMRFinderPlus for resistance annotations. Scope, drugs, model thresholds, calibration, clustering, and no-call behavior are centrally controlled by `config.yaml`.

Main entry points: [`src/api.py`](https://github.com/eylernur/genowall/blob/main/src/api.py) (FastAPI service), [`src/predict.py`](https://github.com/eylernur/genowall/blob/main/src/predict.py) (Prediction orchestration), [`src/features.py`](https://github.com/eylernur/genowall/blob/main/src/features.py) (Feature construction), [`src/train.py`](https://github.com/eylernur/genowall/blob/main/src/train.py) (Model training and calibration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Offline training pipeline"]
  node_sources[("BV-BRC genomes and AST<br/>external data")]
  node_ingest["Data ingestion<br/>Python module<br/>[ingest_bvbrc.py]"]
  node_features["Feature construction<br/>Python module<br/>[features.py]"]
  node_processed[("Processed training data<br/>Parquet datasets<br/>[features.parquet]")]
  node_dictionary["Feature dictionary<br/>CSV knowledge artifact"]
  node_split["Mash homology split<br/>Python module<br/>[cluster_split.py]"]
  node_splits["Train/calibration/test splits<br/>split manifest<br/>[splits.json]"]
  node_training_model["Model training and calibration<br/>Python module<br/>[train.py]"]
  node_evaluation["Held-out evaluation<br/>Python module<br/>[evaluate.py]"]
  node_metrics["Evaluation report<br/>Markdown report<br/>[metrics.md]"]
end

subgraph group_inference["Python inference service"]
  node_annotation{{"AMRFinderPlus annotation<br/>bioinformatics stage<br/>[annotate.py]"}}
  node_artifacts[("Shipped drug models<br/>joblib artifacts")]
  node_api["FastAPI service<br/>Python API<br/>[api.py]"]
  node_orchestrator["Prediction orchestration<br/>Python module<br/>[predict.py]"]
  node_decision["Safety decision layer<br/>Python modules<br/>[target_gate.py]"]
end

subgraph group_delivery["Browser delivery"]
  node_svelte_ui["Svelte upload UI<br/>Vite/Svelte client<br/>[App.svelte]"]
  node_ui_api["HTTPS API client<br/>Svelte module<br/>[api.ts]"]
  node_streamlit["Optional Streamlit frontend<br/>Python UI<br/>[streamlit_app.py]"]
end

node_config["Central scope controls<br/>YAML configuration<br/>[config.yaml]"]

node_sources -->|"genomes and AST labels"| node_ingest
node_ingest -->|"training genomes"| node_annotation
node_annotation -->|"gene and mutation calls"| node_features
node_features -->|"features and labels"| node_processed
node_features -->|"feature classification"| node_dictionary
node_processed -->|"genomes for partitioning"| node_split
node_split -->|"homology-safe partitions"| node_splits
node_processed -->|"training data"| node_training_model
node_splits -->|"train and calibration sets"| node_training_model
node_training_model -->|"calibrated per-drug models"| node_artifacts
node_training_model -->|"models"| node_evaluation
node_splits -->|"held-out test set"| node_evaluation
node_evaluation -->|"reported results"| node_metrics
node_config -.->|"feature thresholds"| node_features
node_config -.->|"clustering controls"| node_split
node_config -.->|"drug and no-call policy"| node_decision
node_svelte_ui -->|"submits FASTA"| node_ui_api
node_ui_api -->|"POST /predict"| node_api
node_streamlit -->|"prediction requests"| node_api
node_api -->|"delegates prediction"| node_orchestrator
node_api -->|"GET /metrics"| node_metrics
node_orchestrator -->|"uploaded FASTA"| node_annotation
node_orchestrator -->|"aligned feature scoring"| node_artifacts
node_orchestrator -->|"calibrated probabilities"| node_decision
node_decision -->|"per-drug calls and evidence"| node_api
node_dictionary -->|"evidence labels"| node_decision

click node_ingest "https://github.com/eylernur/genowall/blob/main/src/ingest_bvbrc.py"
click node_annotation "https://github.com/eylernur/genowall/blob/main/src/annotate.py"
click node_features "https://github.com/eylernur/genowall/blob/main/src/features.py"
click node_processed "https://github.com/eylernur/genowall/blob/main/data/processed/features.parquet"
click node_dictionary "https://github.com/eylernur/genowall/blob/main/data/processed/feature_dictionary.csv"
click node_split "https://github.com/eylernur/genowall/blob/main/src/cluster_split.py"
click node_splits "https://github.com/eylernur/genowall/blob/main/data/processed/splits.json"
click node_training_model "https://github.com/eylernur/genowall/blob/main/src/train.py"
click node_artifacts "https://github.com/eylernur/genowall/blob/main/models/ciprofloxacin.joblib"
click node_evaluation "https://github.com/eylernur/genowall/blob/main/src/evaluate.py"
click node_metrics "https://github.com/eylernur/genowall/blob/main/reports/metrics.md"
click node_config "https://github.com/eylernur/genowall/blob/main/config.yaml"
click node_api "https://github.com/eylernur/genowall/blob/main/src/api.py"
click node_orchestrator "https://github.com/eylernur/genowall/blob/main/src/predict.py"
click node_decision "https://github.com/eylernur/genowall/blob/main/src/target_gate.py"
click node_svelte_ui "https://github.com/eylernur/genowall/blob/main/ui/src/App.svelte"
click node_ui_api "https://github.com/eylernur/genowall/blob/main/ui/src/lib/api.ts"
click node_streamlit "https://github.com/eylernur/genowall/blob/main/app/streamlit_app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sources,node_ingest,node_features,node_processed,node_dictionary,node_split,node_splits,node_training_model,node_evaluation,node_metrics toneBlue
class node_annotation,node_artifacts,node_api,node_orchestrator,node_decision toneAmber
class node_svelte_ui,node_ui_api,node_streamlit toneMint
class node_config toneNeutral
```

## Components

### Offline training pipeline

Reproducible data preparation, validation, and model development.

- **BV-BRC genomes and AST**: external data · Genome sequences and laboratory phenotypes.
- [Data ingestion](https://github.com/eylernur/genowall/blob/main/src/ingest_bvbrc.py): Python module · `src/ingest_bvbrc.py`
- [Feature construction](https://github.com/eylernur/genowall/blob/main/src/features.py): Python module · Applies identity and coverage thresholds to binary features. · `src/features.py`
- [Processed training data](https://github.com/eylernur/genowall/blob/main/data/processed/features.parquet): Parquet datasets · Feature matrix and AST labels. · `data/processed/features.parquet`
- [Feature dictionary](https://github.com/eylernur/genowall/blob/main/data/processed/feature_dictionary.csv): CSV knowledge artifact · Separates recognized mechanisms from statistical associations. · `data/processed/feature_dictionary.csv`
- [Mash homology split](https://github.com/eylernur/genowall/blob/main/src/cluster_split.py): Python module · Prevents related genomes crossing development partitions. · `src/cluster_split.py`
- [Train/calibration/test splits](https://github.com/eylernur/genowall/blob/main/data/processed/splits.json): split manifest · `data/processed/splits.json`
- [Model training and calibration](https://github.com/eylernur/genowall/blob/main/src/train.py): Python module · Per-drug balanced L2 logistic regression with calibrated probabilities. · `src/train.py`
- [Held-out evaluation](https://github.com/eylernur/genowall/blob/main/src/evaluate.py): Python module · Emits discrimination and calibration results. · `src/evaluate.py`
- [Evaluation report](https://github.com/eylernur/genowall/blob/main/reports/metrics.md): Markdown report · `reports/metrics.md`

### Python inference service

Native-tooling runtime for genome prediction.

- [AMRFinderPlus annotation](https://github.com/eylernur/genowall/blob/main/src/annotate.py): bioinformatics stage · Calls resistance genes and mutations from genomes. · `src/annotate.py`
- [Shipped drug models](https://github.com/eylernur/genowall/blob/main/models/ciprofloxacin.joblib): joblib artifacts · Inference-ready calibrated models. · `models/ciprofloxacin.joblib`
- [FastAPI service](https://github.com/eylernur/genowall/blob/main/src/api.py): Python API · Provides prediction, health, and metrics endpoints. · `src/api.py`
- [Prediction orchestration](https://github.com/eylernur/genowall/blob/main/src/predict.py): Python module · Coordinates annotation, aligned features, scoring, and report assembly. · `src/predict.py`
- [Safety decision layer](https://github.com/eylernur/genowall/blob/main/src/target_gate.py): Python modules · Target gate, abstention rules, and evidence classification. · `src/target_gate.py`

### Browser delivery

Separately deployed client applications.

- [Svelte upload UI](https://github.com/eylernur/genowall/blob/main/ui/src/App.svelte): Vite/Svelte client · Uploads FASTA and renders drug cards, evidence, and reports. · `ui/src/App.svelte`
- [HTTPS API client](https://github.com/eylernur/genowall/blob/main/ui/src/lib/api.ts): Svelte module · Uses a configurable endpoint or mock preview mode. · `ui/src/lib/api.ts`
- [Optional Streamlit frontend](https://github.com/eylernur/genowall/blob/main/app/streamlit_app.py): Python UI · `app/streamlit_app.py`

### Other components

- [Central scope controls](https://github.com/eylernur/genowall/blob/main/config.yaml): YAML configuration · Controls drugs, thresholds, calibration, clustering, and no-call behavior. · `config.yaml`

## Connections

- BV-BRC genomes and AST → Data ingestion: genomes and AST labels
- Data ingestion → AMRFinderPlus annotation: training genomes
- AMRFinderPlus annotation → Feature construction: gene and mutation calls
- Feature construction → Processed training data: features and labels
- Feature construction → Feature dictionary: feature classification
- Processed training data → Mash homology split: genomes for partitioning
- Mash homology split → Train/calibration/test splits: homology-safe partitions
- Processed training data → Model training and calibration: training data
- Train/calibration/test splits → Model training and calibration: train and calibration sets
- Model training and calibration → Shipped drug models: calibrated per-drug models
- Model training and calibration → Held-out evaluation: models
- Train/calibration/test splits → Held-out evaluation: held-out test set
- Held-out evaluation → Evaluation report: reported results
- Central scope controls → Feature construction: feature thresholds
- Central scope controls → Mash homology split: clustering controls
- Central scope controls → Safety decision layer: drug and no-call policy
- Svelte upload UI → HTTPS API client: submits FASTA
- HTTPS API client → FastAPI service: POST /predict
- Optional Streamlit frontend → FastAPI service: prediction requests
- FastAPI service → Prediction orchestration: delegates prediction
- FastAPI service → Evaluation report: GET /metrics
- Prediction orchestration → AMRFinderPlus annotation: uploaded FASTA
- Prediction orchestration → Shipped drug models: aligned feature scoring
- Prediction orchestration → Safety decision layer: calibrated probabilities
- Safety decision layer → FastAPI service: per-drug calls and evidence
- Feature dictionary → Safety decision layer: evidence labels
