tandemox
A dependency-light, pure-Rust tandem repeat finder for DNA. It detects approximate tandem repeats — including ones broken by insertions and deletions — and reports each with its period, copy number, percent identity and a TRF-comparable alignment score.
tandemox is an independent implementation, not a port. The reference tool,
Tandem Repeats Finder (TRF) by Gary Benson,
is license-restricted, so no TRF source is used or derived from here. The gapped
alignment is built from the published wraparound dynamic programming
algorithm of Fischetti, Landau, Schmidt & Sellers (CPM 1992), and the output is
validated for concordance against TRF rather than copied from it.
Library
use detect;
let seq = b"GACTTCAGGATCCGATACGTTAGCACTG\
ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC\
CATGACTGACAGTGCACTAGC";
for r in detect
detect takes one sequence (ASCII ACGTN, mixed case) and returns the repeats
found in it, left to right:
Non-ACGT bases (including N) never match, so repeats never bridge ambiguous
runs or assembly gaps. Callers with multi-record FASTA loop over contigs
themselves.
For a single large sequence, detect_parallel(seq, threads) splits the
per-period work across OS threads (std only, no thread-pool dependency) and
returns the identical result. When you already process many sequences
concurrently, prefer detect per sequence over your own pool.
Command line
tandemox <input.fasta>
prints a TSV to stdout:
seqname start end period copies identity score
The CLI uses up to 16 threads per sequence (override with TANDEMOX_THREADS=N).
Performance
Wall-clock and peak memory vs C TRF (2 7 7 80 10 50 500), on the three
genomes above (single machine; tandemox CLI default of ≤16 threads):
| Genome | C TRF | tandemox | Peak RSS (C / tandemox) |
|---|---|---|---|
| MG1655 | 2.7 s | 0.85 s | 26 MB / 48 MB |
| B. subtilis | 2.8 s | 0.70 s | 25 MB / ~45 MB |
| P. aeruginosa | 8.6 s | 1.7 s | 32 MB / 56 MB |
The library detect (single-threaded) runs ~10–20 s per genome at ~20 MB —
lighter than C, ideal when you're already running one sequence per core. The
match-track scan is done a machine word at a time (SWAR), skipping non-repeat
stretches in bulk.
How it works
- Seeding — a linear per-period diagonal scan (Kadane / X-drop) flags where
period-
pstructure exists. Deliberately permissive; it only proposes. - Refinement — each seed votes a consensus motif, and wraparound dynamic
programming aligns the surrounding window against that motif repeated
end-to-end, under TRF's
2 / -7 / -7weights. This absorbs indels (which the ungapped seed scan structurally cannot) and yields the reported score, boundaries and identity. - Gating & dedup — significance gates (score, copies, identity) then greedy overlap resolution keep one call per region, at its fundamental period.
Defaults mirror TRF's 2 7 7 80 10 50 500 parameters (match 2, mismatch 7,
indel 7, min score 50, max period 500) and are tuned to be high-precision /
conservative: the goal is that reported repeats are real, accepting that the
recall envelope differs from TRF's own detector.
Concordance vs C TRF
Measured against trf … 2 7 7 80 10 50 500 -h -ngs on three complete bacterial
genomes (recall = fraction of TRF repeats recovered at ≥50% reciprocal overlap):
| Genome (GC%) | TRF repeats | Recovered | False calls |
|---|---|---|---|
| E. coli MG1655 (51%) | 92 | 82.6% | 4 |
| B. subtilis 168 (44%) | 55 | 78.2% | 1 |
| P. aeruginosa PAO1 (66%) | 203 | 60.6% | 12 |
Most "false calls" (calls with no TRF counterpart) are, on inspection, real
tandem repeats that TRF's own detector misses — e.g. large-period arrays near
the two-copy boundary — rather than spurious output. The regression harness in
tests/concordance.rs reproduces these numbers when pointed at reference data
via TRF_BENCH_DIR.
License
Licensed under either of MIT or Apache-2.0 at your option.