# jodyphelan/tbprofiler architecture

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

- Interactive diagram: https://gitdiagram.com/jodyphelan/tbprofiler
- Repository: https://github.com/jodyphelan/tbprofiler

## Overview

TB-Profiler is a command-line tuberculosis sequencing profiler. Users provide FASTQ or an existing BAM; the documented workflow aligns reads, calls variants, compares them with a resistance database, and writes sample reports. The repository also supports whole-genome SNP-distance comparisons, spoligotyping, and cohort collation. The README and sampled modules support the report and analysis branches shown here; the main CLI implementation and some pipeline wiring were not sampled, so those links are documented at the product level rather than attributed to unseen internal calls.

Main entry points: [`tb-profiler`](https://github.com/jodyphelan/tbprofiler/blob/master/tb-profiler) (TB-Profiler CLI), [`tbprofiler/models.py`](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/models.py) (Result models), [`tbprofiler/output.py`](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/output.py) (Output dispatcher), [`tbprofiler/snp_dists.py`](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/snp_dists.py) (SNP-distance search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_analysis["Sequence analysis"]
  node_align["Read alignment"]
  node_variantcall["Variant calling"]
end

subgraph group_interpretation["Variant interpretation"]
  node_resistance_db[("Resistance database")]
  node_reformat["Result reformatting<br/>[reformat.py]"]
  node_rules["Interpretation rules<br/>[rules.py]"]
  node_plugins["Plugin interface<br/>[plugins.py]"]
  node_models["Result models<br/>[models.py]"]
end

subgraph group_extras["Additional analyses"]
  node_whole_genome["Whole-genome calling"]
  node_consensus["Consensus VCF<br/>[consensus.py]"]
  node_snp_distance[("SNP-distance search<br/>[snp_dists.py]")]
  node_spoligo["Spoligotyping<br/>[spoligotyping.py]"]
end

subgraph group_reporting["Results and reporting"]
  node_output["Output dispatcher<br/>[output.py]"]
  node_text["Text and CSV reports<br/>[text.py]"]
  node_docx["Word reports<br/>[docx.py]"]
end

subgraph group_cohort["Cohort analysis"]
  node_collate["Sample collation<br/>[collate.py]"]
end

node_user(("CLI user"))
node_cli["TB-Profiler CLI"]
node_reads["FASTQ or BAM"]
node_reports["Sample results"]

node_user -->|"runs"| node_cli
node_cli -->|"accepts input"| node_reads
node_cli -->|"aligns reads"| node_align
node_align -->|"produces alignments"| node_variantcall
node_variantcall -->|"compares variants"| node_resistance_db
node_cli -.->|"formats results"| node_reformat
node_reformat -->|"builds results"| node_models
node_rules -->|"extends"| node_plugins
node_cli -.->|"applies rules"| node_rules
node_cli -->|"enables genome-wide calling"| node_whole_genome
node_whole_genome -->|"calls variants"| node_variantcall
node_cli -->|"enables distance search"| node_snp_distance
node_snp_distance -->|"gets consensus VCF"| node_consensus
node_snp_distance -->|"updates linked samples"| node_models
node_cli -->|"enables spoligotyping"| node_spoligo
node_spoligo -->|"analyzes FASTQ or BAM"| node_reads
node_cli -.->|"writes results"| node_output
node_output -->|"serializes result"| node_models
node_output -->|"writes text or CSV"| node_text
node_output -->|"writes Word report"| node_docx
node_text -->|"renders result fields"| node_models
node_docx -->|"renders result fields"| node_models
node_output -->|"writes reports"| node_reports
node_cli -.->|"collates samples"| node_collate
node_collate -->|"loads sample results"| node_models

click node_cli "https://github.com/jodyphelan/tbprofiler/blob/master/tb-profiler"
click node_resistance_db "https://github.com/jodyphelan/tbprofiler/tree/master/db/who_v2%2B"
click node_reformat "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/reformat.py"
click node_rules "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/rules.py"
click node_plugins "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/plugins.py"
click node_models "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/models.py"
click node_consensus "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/consensus.py"
click node_snp_distance "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/snp_dists.py"
click node_spoligo "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/spoligotyping.py"
click node_output "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/output.py"
click node_text "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/text.py"
click node_docx "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/docx.py"
click node_collate "https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/collate.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_align,node_variantcall,node_user toneBlue
class node_resistance_db,node_reformat,node_rules,node_plugins,node_models toneAmber
class node_whole_genome,node_consensus,node_snp_distance,node_spoligo toneMint
class node_output,node_text,node_docx toneRose
class node_collate,node_reads,node_reports toneIndigo
class node_cli toneTeal
```

## Components

### Sequence analysis

- **Read alignment**
- **Variant calling**

### Variant interpretation

- [Resistance database](https://github.com/jodyphelan/tbprofiler/tree/master/db/who_v2%2B): `db/who_v2+`
- [Result reformatting](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/reformat.py): `tbprofiler/reformat.py`
- [Interpretation rules](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/rules.py): `tbprofiler/rules.py`
- [Plugin interface](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/plugins.py): `tbprofiler/plugins.py`
- [Result models](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/models.py): `tbprofiler/models.py`

### Additional analyses

- **Whole-genome calling**
- [Consensus VCF](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/consensus.py): `tbprofiler/consensus.py`
- [SNP-distance search](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/snp_dists.py): `tbprofiler/snp_dists.py`
- [Spoligotyping](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/spoligotyping.py): `tbprofiler/spoligotyping.py`

### Results and reporting

- [Output dispatcher](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/output.py): `tbprofiler/output.py`
- [Text and CSV reports](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/text.py): `tbprofiler/text.py`
- [Word reports](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/docx.py): `tbprofiler/docx.py`

### Cohort analysis

- [Sample collation](https://github.com/jodyphelan/tbprofiler/blob/master/tbprofiler/collate.py): `tbprofiler/collate.py`

### Other components

- **CLI user**
- [TB-Profiler CLI](https://github.com/jodyphelan/tbprofiler/blob/master/tb-profiler): `tb-profiler`
- **FASTQ or BAM**
- **Sample results**

## Connections

- CLI user → TB-Profiler CLI: runs (evidence: `README.md`)
- TB-Profiler CLI → FASTQ or BAM: accepts input (evidence: `README.md`)
- TB-Profiler CLI → Read alignment: aligns reads (evidence: `README.md`)
- Read alignment → Variant calling: produces alignments (evidence: `README.md`)
- Variant calling → Resistance database: compares variants (evidence: `README.md`)
- TB-Profiler CLI → Result reformatting: formats results
- Result reformatting → Result models: builds results (evidence: `tbprofiler/reformat.py`)
- Interpretation rules → Plugin interface: extends (evidence: `tbprofiler/rules.py`)
- TB-Profiler CLI → Interpretation rules: applies rules
- TB-Profiler CLI → Whole-genome calling: enables genome-wide calling (evidence: `README.md`)
- Whole-genome calling → Variant calling: calls variants (evidence: `README.md`)
- TB-Profiler CLI → SNP-distance search: enables distance search (evidence: `README.md`)
- SNP-distance search → Consensus VCF: gets consensus VCF (evidence: `tbprofiler/snp_dists.py`)
- SNP-distance search → Result models: updates linked samples (evidence: `tbprofiler/snp_dists.py`)
- TB-Profiler CLI → Spoligotyping: enables spoligotyping (evidence: `README.md`)
- Spoligotyping → FASTQ or BAM: analyzes FASTQ or BAM (evidence: `tbprofiler/spoligotyping.py`)
- TB-Profiler CLI → Output dispatcher: writes results
- Output dispatcher → Result models: serializes result (evidence: `tbprofiler/output.py`)
- Output dispatcher → Text and CSV reports: writes text or CSV (evidence: `tbprofiler/output.py`)
- Output dispatcher → Word reports: writes Word report (evidence: `tbprofiler/output.py`)
- Text and CSV reports → Result models: renders result fields (evidence: `tbprofiler/text.py`)
- Word reports → Result models: renders result fields (evidence: `tbprofiler/docx.py`)
- Output dispatcher → Sample results: writes reports (evidence: `tbprofiler/output.py`)
- TB-Profiler CLI → Sample collation: collates samples
- Sample collation → Result models: loads sample results (evidence: `tbprofiler/collate.py`)
