tandemox 0.1.0

Pure-Rust tandem repeat finder: indel-tolerant detection of approximate tandem repeats in DNA, validated for concordance against Tandem Repeats Finder (TRF).
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented1 out of 4 items with examples
  • Size
  • Source code size: 81.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 322.6 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • necoli1822/tandemox
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • necoli1822

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 tandemox::detect;

let seq = b"GACTTCAGGATCCGATACGTTAGCACTG\
            ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC\
            CATGACTGACAGTGCACTAGC";
for r in detect(seq) {
    // coordinates are 1-based inclusive
    println!(
        "{}..{} period={} copies={:.1} identity={:.3} score={:.0}",
        r.start, r.end, r.period, r.copies, r.identity, r.score,
    );
}

detect takes one sequence (ASCII ACGTN, mixed case) and returns the repeats found in it, left to right:

pub struct TandemRepeat {
    pub start: usize,          // 1-based inclusive
    pub end: usize,            // 1-based inclusive
    pub period: usize,         // motif length (bp)
    pub copies: f64,           // region_len / period
    pub identity: f64,         // fraction identity to the consensus, 0..=1
    pub score: f32,            // TRF-comparable: 2*matches - 7*(mismatches+indels)
    pub consensus_size: usize, // == period
}

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

  1. Seeding — a linear per-period diagonal scan (Kadane / X-drop) flags where period-p structure exists. Deliberately permissive; it only proposes.
  2. 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 / -7 weights. This absorbs indels (which the ungapped seed scan structurally cannot) and yields the reported score, boundaries and identity.
  3. 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.