Aligners

Twitcher supports three alignment backends. How each of them uses the cost model is described in Cost model.

A* Aligner (default)

The default aligner uses an A* search strategy. It is the most capable option: it can find alignments with indels inside the template switch and can handle multiple template switches in a single cluster. It is gap-affine and uses a full cost model configurable via --costs.

The A* Aligner is developed under the name tsalign on Github.

Key parameters: - --costs <FILE>: a .tsa config file for the alignment cost model (gap open/extend, mismatch, template switch penalties, etc.). If omitted, built-in defaults are used. - --min-length-strategy <ML_STRATEGY>: controls how the minimum inner length of a template switch is enforced during the search. Available strategies: none, lookahead, preprocess-filter (default), preprocess-price, preprocess-lookahead. The preprocess strategies prune the search space before alignment and are generally faster. - --no-ts: disables template switch alignment entirely; the aligner falls back to a plain pairwise alignment. Mainly useful for benchmarking or debugging.

Four-Point-Aligner (enabled by --fpa)

An alternative aligner based on dynamic programming. It is generally faster but has two important limitations:

  • It cannot find alignments with indels inside the template switch.
  • It supports at most one template switch per cluster.

Because it is not gap-affine, the gap-open cost from the cost model is ignored; only the gap-extension cost applies.

Use --fpa when speed matters and the above limitations are acceptable for your data.

Chaining Aligner (enabled by --chain)

A chaining-based aligner from tsalign (lib_ts_chainalign). It anchors the alignment on exact k-mer matches between the sequences and their reverse complements, chains these anchors with an A* search over precomputed lower bounds, and fills the gaps between anchors with exact alignments. Unlike the four-point aligner it is gap-affine and allows indels inside a template switch.

It needs a simpler cost model than the A* aligner. The cost file is converted at startup, and twitcher exits with an error if that is not possible:

  • Zero match costs, and one substitution, gap open and gap extend cost each, for the primary and for the secondary (reverse) alignment. Only the A, C, G and T entries count; the N row and column are dropped.
  • Only reverse template switches. The forward base costs rrf, rqf, qrf and qqf are ignored.
  • The Length table becomes a on/off range: lengths with a cost of zero are allowed, all others are forbidden. With the default costs (0 5 6 7 8 401 / inf 15 10 5 0 inf) template switches of length 8 to 400 are allowed, and all others are not. A Length table without a zero-cost range, or with more than one, is rejected.
  • RQQROffset, RRQQOffset and ReverseAntiDescendantGap must each be zero on a single range and infinite outside of it, but the aligner does not enforce these ranges yet: the jump distance is bounded only by --padding.
  • LengthDifference and ForwardAntiDescendantGap are ignored, and flanks must be zero.

Twitcher warns on startup about every configured part of the cost model that --chain disregards (see Errors and warnings about settings).

Further properties:

  • The aligner only supports the bases A, C, G and T. A cluster whose reference or query contains anything else (N, IUPAC codes) is skipped as a soft failure; in vcf mode its records are written unchanged.
  • It does not compute uncertainty ranges, so they are reported as [-], like with --fpa.
  • --min-length-strategy, --uncertainty-range-mode and --allow-mixed-descendants have no effect.

Preprocessed tables

The aligner needs lower-bound tables that depend on the cost model, the k-mer size and the sequence length (rounded up to a power of two). Computing them is expensive and grows quickly with the length: about 2 s for 512 bases, 12 s and 0.6 GB of memory for 1024 bases, and around a minute and several GB for 2048 bases. With the default --padding 200, alignment windows are typically 512 to 1024 bases long.

The k-mer size and the table length are inferred for each alignment. They can be fixed with --chain-k and --chain-max-n; a cluster with a sequence longer than --chain-max-n is skipped as a soft failure.

Each run caches its tables on disk (in $TMPDIR, or /tmp if it is unset) and removes them when the run ends. The files are typically a few MB in size. A run that is killed (for example with Ctrl-C) leaves its directory behind.

Building a table needs far more memory than the finished table (about 0.6 GB for the 17 MB table of 1024 bases), so it may use the whole --memory-limit and pauses all other alignments while it runs. If a table cannot be built, for example because it does not fit into --memory-limit, every alignment that needs it fails. These failures are not stored in the alignment database, so the next run tries to build the table again. Alignments never compute a table themselves: one that disappears during the run is an error.