Twitcher
Twitcher (template switch aligner) is a tool for identification and annotation of short-range template switch events. It builds on the ideas introduced in Löytynoja and Goldman (2017) and Löytynoja (2022), but includes a novel algorithm for optimal alignment of two sequences with any number of template switches. Twitcher works on VCF- and BAM-formatted data and can be directly incorporated in genome data analysis pipelines.
Twitcher operates in two stages:
- While reading the input (VCF or BAM; from stdin or a file), it extracts suspicious™ clusters of SNVs and indels, e.g. more than 2 base changes within 10 bp window.
- It then reconstructs the alternative (mutated) haplotype for the mutation cluster and flanking sequence, and aligns that with the homologous regions in the reference genome. If the mutation cluster can be better explained with one or more template switches, it outputs the new, reannotated VCF record and/or description of the mutation as a line in a CSV file.
Algorithm
Twitcher implements the original FPA algorithm (it can be selected with --fpa) but, by default, uses a novel tsalign algorithm. Conceptually, tsalign builds on the previous implementation and combines classical dynamic programming approaches with the possibility to jump between multiple matrices. However, the number of jumps (and independent template switch events) is not limited and also copy-events in forward orientation can be included. The flexibility comes with a cost, and tsalign solves a problem that is $O(n^6)$ in time and memory in the worst case.
Computational speedups
To reduce the search space and time, we use the A* algorithm with a predictive heuristic to create a lower bound on the remaining alignment cost. In practice, the algorithm is sufficiently fast for analyses of complex sequences but it may fail on repetitive sequences with numerous equally good sub-solutions. Often, that is acceptable, and although low-complexity sequences may evolve through template switching, alternative mechanisms can also explain copy-number reductions and expansions. (In principle, polymerase "slippage" -- thought to be involved e.g. in microsatellite evolution -- could also be considered a template switch and be identified by Twitcher.)
Another option for speeding up the analysis is to disable some mutation types and parameters. By default, forward copy events are disabled in Twitcher and, similarly to the original FPA tool, it only searches for reverse-complement copy events. Twitcher allows setting different mutation costs for various classes of sites and, by default, only some of these are enabled. The full scale of mutations -- and the relative cost of events -- can be adjusted through the cost model file, as explained in Twitcher Costs.
The greatest speed up for the tsalign algorithm is not to use it at all. Twitcher can build and utilise a database of known mutation clusters and retrieve the solution for a known pattern without the alignment step. This gives a massive acceleration in analyses of population data where individuals contain only few unique mutations and largely share the mutation patterns with others. A Twitcher DB can be considered a "panel" of known mutation clusters and be reutilised in production analyses.
Description of TSM events
The inferred template switch events are described using a novel TSIGAR format, which can be understood as an extension to the CIGAR format. The format is explained in more detail in TSIGAR Format.
Installation
Twitcher (and tsalign) are written in Rust and available through cargo install. Those not familiar with Rust may prefer the prebuilt binary.
Prebuilt binary (Linux, x86-64)
Every release ships a prebuilt binary; no Rust toolchain required:
The binary is built for x86-64-v3 (AVX2), so it needs a reasonably modern CPU. More detailed instructions are available in Twitcher Installation.
From source
Twitcher is an open-source software and the code is available at https://version.helsinki.fi/kraujasp/twitcher/.
It can be installed from source using cargo:
cargo (version 1.96.0 or higher is required) is available e.g. via rustup. The clang C compiler is required to compile the underlying htslib bindings.
Instructions for building Twitcher locally are available in Twitcher Installation.
Usage
Twitcher has two main commands:
twitcher vcf— Re-annotate VCF files with template switch mutationstwitcher reads— Find template switch mutations in sequencing reads
Quick Start
This realigns identified mutation clusters and outputs inferred TSM events as single complex variants.
Detailed instructions for using the program are available in Twitcher Usage.
Examples
# Realign with larger context window
# Only output realigned variants
# Use reads to (try to) phase ambiguous clusters
# Export template switch regions
# Use a database to store known cases