Quick Start¶
This guide will walk you through using leech for the first time.
Prerequisites¶
- Install leech
- POD5 file with nanopore signal data
- BAM file with basecalls and move tables (from dorado/guppy with
--emit-moves)
What you will do¶
The leech workflow has four steps, each handled by a dedicated CLI command:
graph LR
A[Prepare Data] --> B[Train Model]
B --> C[Test Model]
C --> D[Run Inference]
- Prepare (
leech data prepare) — read raw signal from a POD5 file and alignments from a BAM file, extract dwell times and signal statistics centered on a sequence motif, and split the resulting chunks into train/val/test sets at the read level. - Train (
leech model train) — fit a multi-branch neural network that takes signal, sequence, and dwell features as separate inputs and learns to classify modification state. - Test (
leech eval test) — evaluate the trained model on a held-out test set and report accuracy, precision, recall, F1, and AUC. - Predict (
leech predict) — apply the model to new POD5/BAM data and write modification probabilities into an output BAM file.
Step 1: Prepare Training Data¶
Extract features from your POD5 and BAM files:
| Bash | |
|---|---|
Key Parameters¶
--pod5: Path to POD5 file with raw signal--bam: Path to BAM file with alignments and move tables--output-dir: Directory to save training chunks--feature-set: Features to extract (one ofsignal,signal+dwell,signal+levels,signal+dwell+levels)--motif: Sequence motif to center on (e.g., "CCAGGC" for tRNA 3' end)--motif-offset: Position within motif to focus on (0-indexed)--label: Label identifier for this sample (e.g.,Ala,charged); a string, not necessarily 0/1
Parallel Processing¶
For large datasets, use parallel processing:
| Bash | |
|---|---|
This will process reads in parallel across 8 CPU cores.
Step 2: Train a Model¶
Train a model on your prepared data:
| Bash | |
|---|---|
Available Models¶
ConvLSTMDwell: Multi-branch Conv-LSTM with dwell features (recommended)ConvLSTMBase: Baseline without dwell featuresTransformerDwell: Transformer with self-attentionConvOnly: Pure convolutional networkTCNDwell: Temporal Convolutional NetworkResNetDwell: Residual network
Training Output¶
The training process will save:
model_best.pt: Best model checkpoint (by validation loss)model_last.pt: Latest checkpointmetrics.json: Training metrics over time
Step 3: Test the Model¶
Evaluate your trained model:
| Bash | |
|---|---|
This will output:
- Accuracy, precision, recall, F1 score
- Confusion matrix
- ROC-AUC score
- Per-class metrics
Example Output¶
| JSON | |
|---|---|
Step 4: Run Inference¶
Apply your model to new data:
| Bash | |
|---|---|
The output BAM file will contain modification probability tags for each base.
Beyond single-sample workflows¶
The steps above cover a single-sample classification. For multi-sample experiments (e.g., preparing charged and uncharged data separately, then merging), see leech data merge in the CLI Reference. The merge command handles read-level splitting across samples to prevent data leakage.
Deploying with model bundles¶
When you have multiple pairwise models (e.g., Ala vs Gly, Ala vs Val, ...), package them into a single bundle for deployment:
| Bash | |
|---|---|
See the CLI Reference for full bundle and inference options.
Next steps¶
- Data Preparation — parallel processing, motif search, multi-sample merging
- Understanding Move Tables — how leech decodes the BAM
mvtag into per-base dwell times - Dwell Time Features — the 9-channel feature set and model architecture
- Classification Tasks — charged vs. uncharged, pairwise amino acid, and chemical property comparisons
- Grid Search — optimize signal context and hyperparameters
- CLI Reference — all commands including training improvements and bundle workflows