Concepts
What are Template Switches?
A template switch (or template switching) is a replication error where the polymerase disengages, re-engages on a different part of the DNA template, copies some amount of bases from there before re-attaching to the original strand. This can create what looks like clusters of mutations but are actually originating from one longer event.
Twitcher identifies and re-annotates these template-switched mutations by realigning the surrounding sequence context.
Reference: Löytynoja and Goldman (2017)
How Twitcher Works
Twitcher operates in the two stages outlined in the Overview:
Stage 1: Clustering
While reading the input, Twitcher identifies suspicious clusters: groups of nearby mutations that are complex enough, packed densely enough. How clusters are found and scored is described in Clustering.
VCF
While reading the input VCF file, Twitcher groups successive records into clusters.
Unaffected variants, that is variants that are not part of a cluster or the realignment did not find any template switch event, are, by default, output as-is.
Twitcher works on exactly one sample. A single-sample input is used as it is; with more than one sample, --sample names the one to use, and it is an error to leave it out. The selected sample is the only one that is ever read (genotype and phase set come from its column), and the output is subsetted to it, so running with --sample gives the same result as running on the input reduced to that sample beforehand. In particular, a record that is hom-ref or uncalled in the selected sample is a hole even if another sample carries a variant there, and it is written unchanged.
Within a cluster, the phase of unphased heterozygous variants can be ambiguous. Such clusters cannot be realigned, unless the ambiguity is resolved by read-based phasing.
Haploid genotypes (GT of 0, 1, …, e.g. one VCF per assembled haplotype, or male chrX/Y) need no phasing: a cluster of haploid records is realigned as it is, and its template switch records get a haploid GT as well. A cluster that mixes haploid and diploid records (e.g. across a PAR boundary) is unresolvable (MixedPloidy).
BAM
When reading reads from a BAM/SAM/CRAM file, the CIGAR string and reference file are used to find clusters within each read.
Stage 2: Realignment
For each suspicious cluster, Twitcher:
- Extracts context: retrieves the surrounding reference sequence (configurable padding)
- Realigns: uses pairwise alignment to see if the mutations can be better explained by one or more template switches. Twitcher bundles two aligners for this.
- Outputs:
- VCF: either the original variant calls (if no improvement found) or new, reannotated records
- BAM: the location and read names of template switches in csv format
See Output files for the formats, and CSV output for the regions reported for every cluster.
Alignments can be cached in a database and reused across runs.