# Twitcher
**T**emplate s**witch** align**er**.
A tool to find and annotate short-range template switch mutations (TSMs). We want to explain clusters of SNVs/MNVs/indels with one or more short-range template switches ([Löytynoja and Goldman (2017)](https://doi.org/10.1101/gr.214973.116)).
The tool operates in two stages:
1. While reading the input (a VCF or BAM file, from stdin or a file), find suspicious™ clusters of SNVs, MNVs and indels, e.g. at least 2 variants with at most 20 bp between consecutive ones.
2. Realign those clusters under consideration of a few hundred surrounding base pairs. If the mutation cluster can be better explained with one or more template switches, output the new, reannotated VCF records instead of the original ones, and/or a CSV row describing the event.
In `vcf` mode, the tool is designed to enrich the VCF file with more information. Unaffected records are output as-is.
For a more thorough, user-facing introduction see the [Overview](docs/overview.md).
## Installation
### Prebuilt binary (Linux, x86-64)
Every release ships a prebuilt binary; no Rust toolchain required:
```bash
curl -LO https://version.helsinki.fi/kraujasp/twitcher/-/releases/permalink/latest/downloads/binaries/twitcher-linux-x86_64
chmod +x twitcher-linux-x86_64
./twitcher-linux-x86_64 --version
```
The binary is built for portability (`x86-64-v2`, glibc ≥ 2.17); for best performance build from source. See [the installation docs](docs/installation.md) for checksum verification and version pinning.
### From source
You can also install the tool from source using `cargo` (needs at least version 1.95.0):
```bash
cargo install twitcher
```
Get cargo e.g. via [rustup](https://rustup.rs/). You'll also need the `clang` C compiler to compile the underlying htslib bindings.
## Usage
Twitcher has two main commands:
- **`twitcher vcf`** — Re-annotate VCF files with template switch mutations
- **`twitcher reads`** — Find template switch mutations in sequencing reads
and **`twitcher viz`** to render found template switches as SVGs.
### Quick Start
```bash
twitcher vcf input.vcf reference.fa -o output.vcf
```
This realigns suspicious mutation clusters and outputs reannotated variants.
### Full Documentation
Complete documentation is available in [`docs/`](docs/index.md).
### Examples
```bash
# Realign with larger context window
twitcher vcf input.vcf reference.fa --padding 500 -o output.vcf
# Only output realigned variants
twitcher vcf input.vcf reference.fa --only-realigned -o output.vcf
# Additionally write a CSV with details on every template switch
twitcher vcf input.vcf reference.fa -o output.vcf --csv ts.csv
# Use reads to (try to) phase ambiguous clusters
twitcher vcf input.vcf reference.fa --phasing-bam reads.bam -o output.vcf
# Export template switch regions
twitcher vcf input.vcf reference.fa -o output.vcf --output-regions ts_regions.bed
# Use a database to store known cases
twitcher vcf input.vcf reference.fa --db known.db -o output.vcf
# Scan reads for template switches, then render the hits as SVGs
twitcher reads reads.bam reference.fa -o hits.csv
twitcher viz hits.csv -r reference.fa -o svgs/
```
## Development
See [CONTRIBUTING.md](CONTRIBUTING.md) for the architecture and contribution guidelines.
## Background
The underlying pairwise aligner, [`tsalign`](https://github.com/algbio/tsalign), is developed by Sebastian Schmidt.