# cmwendy/samosa_zmw_selector_script architecture

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

- Interactive diagram: https://gitdiagram.com/cmwendy/samosa_zmw_selector_script
- Repository: https://github.com/cmwendy/samosa_zmw_selector_script

## Overview

This repository selects PacBio ZMW reads overlapping genomic-site windows. The principal workflow is a CLI that reads site and chromosome inputs, selects overlapping reads from a BAM, and prints one row per read/site match. BAM access validates or creates an index before fetching. A separate PBS wrapper batches the CLI across BAM files. The wrapper relationships and some operational details are documented in the README; the Python selection and indexing calls are visible in the excerpted source.

Main entry points: [`zmw_selector_updated.py`](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py) (CLI entry point), [`run_zmw_selector.sh`](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/run_zmw_selector.sh) (PBS batch runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_selection["Read selection"]
  node_cli["CLI entry point"]
  node_selection_logic["Window selection"]
  node_bam_reader["BAM iterator"]
  node_index_check["Index validation"]
  node_pysam["Pysam fetch"]
end

subgraph group_batch["Batch execution"]
  node_batch_runner["PBS batch runner"]
end

node_user(("User"))
node_sites["Sites file"]
node_chromosomes["Chromosome list"]
node_bam["Aligned BAM"]
node_samtools["Samtools"]
node_output["TSV on stdout"]

node_user -->|"runs"| node_cli
node_sites -->|"reads"| node_cli
node_chromosomes -->|"reads"| node_cli
node_bam -->|"checks"| node_cli
node_cli -->|"calls"| node_selection_logic
node_selection_logic -->|"fetches via"| node_bam_reader
node_bam_reader -->|"calls"| node_index_check
node_bam_reader -->|"fetches reads"| node_pysam
node_index_check -->|"runs index"| node_samtools
node_selection_logic -->|"returns rows"| node_output
node_cli -->|"prints rows"| node_output
node_user -->|"runs batch"| node_batch_runner
node_batch_runner -->|"invokes per BAM"| node_cli

click node_cli "https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py"
click node_selection_logic "https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py"
click node_bam_reader "https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py"
click node_index_check "https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py"
click node_pysam "https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py"
click node_batch_runner "https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/run_zmw_selector.sh"

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_cli,node_selection_logic,node_bam_reader,node_index_check,node_pysam,node_user toneBlue
class node_batch_runner toneAmber
class node_sites,node_chromosomes,node_bam,node_samtools,node_output toneIndigo
```

## Components

### Read selection

- [CLI entry point](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py): `zmw_selector_updated.py`
- [Window selection](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py): `zmw_selector_updated.py`
- [BAM iterator](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py): `zmw_selector_updated.py`
- [Index validation](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py): `zmw_selector_updated.py`
- [Pysam fetch](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/zmw_selector_updated.py): `zmw_selector_updated.py`

### Batch execution

- [PBS batch runner](https://github.com/cmwendy/samosa_zmw_selector_script/blob/main/run_zmw_selector.sh): `run_zmw_selector.sh`

### Other components

- **User**
- **Sites file**
- **Chromosome list**
- **Aligned BAM**
- **Samtools**
- **TSV on stdout**

## Connections

- User → CLI entry point: runs (evidence: `README.md`)
- Sites file → CLI entry point: reads (evidence: `README.md`)
- Chromosome list → CLI entry point: reads (evidence: `README.md`)
- Aligned BAM → CLI entry point: checks (evidence: `zmw_selector_updated.py`)
- CLI entry point → Window selection: calls (evidence: `zmw_selector_updated.py`)
- Window selection → BAM iterator: fetches via (evidence: `zmw_selector_updated.py`)
- BAM iterator → Index validation: calls (evidence: `zmw_selector_updated.py`)
- BAM iterator → Pysam fetch: fetches reads (evidence: `zmw_selector_updated.py`)
- Index validation → Samtools: runs index (evidence: `zmw_selector_updated.py`)
- Window selection → TSV on stdout: returns rows (evidence: `README.md`)
- CLI entry point → TSV on stdout: prints rows (evidence: `zmw_selector_updated.py`)
- User → PBS batch runner: runs batch (evidence: `README.md`)
- PBS batch runner → CLI entry point: invokes per BAM (evidence: `README.md`)
