Skip to content
tmontserratPublic

About

Reconstructing full-length transposable element insertions (ERV & LINE-1) from fragmented RepeatMasker annotations — transparent, auditable, zero hand-made tables.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

joinTEr logo

Reconstructing full-length transposable element insertions from fragmented RepeatMasker annotations — transparently, without RepeatMasker IDs or hand-made lookup tables.

Release v0.8 MIT License Python 3.10+ ERV and LINE-1

Pre-release notice (v0.8): This is the preview release (v0.8) of joinTEr, shared ahead of the upcoming manuscript. The upcoming v1.0 manuscript release will unify the CLI across TE classes and freeze the final benchmark release. All code, parameters, and self-contained unit tests for both the ERV and LINE-1 reconstruction engines are included here.


1. The Problem — In Plain English

Almost half of the human genome is made of transposable elements (TEs) — ancient mobile DNA insertions such as endogenous retroviruses (ERVs) and LINE-1 retrotransposons.

When standard annotation tools like RepeatMasker scan a genome, they do a great job finding individual repeat pieces, but a single historical insertion is routinely shattered into many separate rows:

  1. Nested insertions ("Russian dolls"): Millions of years after an ERV or LINE-1 landed, younger elements (Alu, L1, SVA, or younger ERVs) jumped right into the middle of it, splitting one insertion into pieces separated by thousands of base pairs.
  2. Sequence decay & model switching: Over evolutionary time, mutations cause RepeatMasker to label different halves of the same insertion with different consensus model names (e.g., two related subfamily consensuses) or to miss degraded stretches altogether.
  3. 5′ inversions in LINE-1 (twin priming): During LINE-1 reverse transcription, the 5′ half often flips onto the opposite DNA strand, so a single insertion looks like two opposing-strand fragments.
  4. Unreliable heuristic IDs: RepeatMasker's built-in chaining IDs (rm_id) sometimes under-split nested elements, over-merge unrelated tandem copies, or change unpredictably across Dfam library releases.
What RepeatMasker sees on the chromosome (5 separate rows):
  [5' LTR]  [int piece 1]  --- [young Alu] --- [young L1] ---  [int piece 2]  [3' LTR]

What actually happened biologically (1 host ERV + 2 nested younger insertions):
  ├── Host ERV provirus:  [5' LTR ━━━ internal body ━━━ 3' LTR]  (flanked by its own TSD)
  │     ├── nested_in:    [young Alu]                            (arrived later)
  │     └── nested_in:    [young L1]                             (arrived later)

joinTEr reconstructs those shattered fragments back into complete, biologically coherent insertions, tells you exactly why every pair of fragments was joined (or kept separate), grades each call's confidence (T1–T4), and explicitly maps the nesting hierarchy (child nested_in parent).


2. How joinTEr Works: "Peel, Then Chain Like Exons"

Instead of relying on RepeatMasker IDs or brittle species-specific lookup tables (zero hand-made family tables, zero rm_id in scoring), joinTEr learns its compatibility priors directly from the input genome and reconstructs loci in four transparent steps:

flowchart LR
    A["RepeatMasker fragments<br/>(.out / rmsk + Genome FASTA)"] --> B["1. Genome-Learned Priors<br/>Zero hand-made tables<br/>(compatibility & TSD length)"]
    B --> C["2. Inside-Out Peeling<br/>Excise younger nested TEs<br/>(Alu, L1, SVA, younger ERVs)"]
    C --> D["3. Grammar-Constrained DP<br/>Chain fragments in collapsed<br/>coordinates & score seams"]
    D --> E["4. Grade & Explain<br/>Tiers T1–T4, alternatives,<br/>nesting & self-audit"]
Loading

The Five Biological Rules

  1. Order & Grammar: Fragments of one insertion must progress cleanly along a shared consensus coordinate system without impossible backward jumps:
    • ERVs (erv/): 5′ LTR → internal body → 3′ LTR on one strand (with on-the-fly single-consensus alignment when RepeatMasker switches model names). Tandem proviruses sharing a middle LTR are kept as two distinct elements linked by shared_ltr, never fused.
    • LINE-1 (line1/): 5′ UTR → ORF1 → ORF2 → 3′ UTR/poly(A) colinearly, plus explicit biophysical handling of opposite-strand 5′ twin-priming inversions ((-, +) turnaround geometry, TSD closure, and anchored local alignment).
  2. Inside-Out Peeling: Younger intervening insertions are excised iteratively from youngest to oldest, collapsing the genomic distance between the two host halves (g_raw → g_coll). Every peeled element is recorded as an explicit nested_in relation.
  3. Strict Gap Accounting: After peeling, any leftover gap must match missing consensus sequence (m). Missing consensus is charged a deletion penalty (S_del); unexplained extra genomic DNA is charged an extra-sequence penalty (S_extra). Nothing is ever free.
  4. Local Chance Control: Every candidate join must beat the local Poisson probability (S_chance) that two unrelated copies of the same family happened to land that close by chance in a 2 Mb window.
  5. Parse First, Grade Separately (T1–T4): Reconstruction finds the highest-scoring biologically valid partition (plus runner-up alternatives within 5.0 nats). Confidence is then graded independently using outer-end physical proof (target site duplications, TSDs), 5′–3′ LTR concordance, and empirical opposite-strand FDR calibration.

Two TE Grammars, One Unified Philosophy

flowchart TD
    subgraph ERV ["ERV / LTR Retrotransposon Grammar (erv/ → HERVarium)"]
        direction LR
        E_TSD1(["TSD<br/>4–6 bp"]) --- E_5L["5' LTR"] --> E_INT["Internal body<br/>(gag · pro · pol · env)"] --> E_3L["3' LTR"] --- E_TSD2(["TSD<br/>4–6 bp"])
    end

    subgraph L1 ["LINE-1 Retrotransposon Grammar (line1/ → LINEpedia)"]
        direction LR
        L_TSD1(["TSD<br/>8–30 bp"]) --- L_5U["5' UTR / 5' inversion<br/>(sense or twin-primed antisense)"] --> L_O1["ORF1"] --> L_O2["ORF2"] --> L_3U["3' UTR + poly(A)"] --- L_TSD2(["TSD<br/>8–30 bp"])
    end
Loading

3. Understanding Confidence Tiers (T1–T4)

Every reconstructed element receives a human-readable confidence tier — no opaque black-box probabilities:

Tier Meaning in Plain English What Proves It?
T1 Ends physically proven Clean reconstruction plus tight, exact family-length Target Site Duplications (TSDs) flanking both outer boundaries — direct molecular proof that both ends came from a single integration event.
T2 Coherent + independent support Clean reconstruction backed by at least one independent corroborating signal (looser outer TSD, paired-LTR identity concordance, or structural confirmation).
T3 Coherent reconstruction Geometrically consistent after peeling, gap accounting, divergence concordance, and local chance testing, passing empirical false-discovery controls.
T4 Ambiguous — competing reading published Borderline score margin, high-FDR seam stratum, or structural conflict. Every single T4 element is guaranteed to list its competing split/merge partition in alternatives.tsv.

4. What Is Inside v0.8

Module A — ERV / LTR Retrotransposons (erv/)

  • Frozen v0.7.1 core DP engine (erv/scripts/03_reconstruct_neon.py, scoring.py, seq_utils.py): genome-learned LTR–internal compatibility, on-the-fly single-consensus alignment, genome-learned per-family TSD lengths (ERV1 = 4 bp, ERVL/MaLR = 5 bp, ERVK = 6 bp), iterative Wave 0–5 peeling, exact K-best laminar DP, and automated end-of-run self-audit (self_audit_v07.py).
  • v0.8 Second-Pass Layer (erv/scripts/second_pass_layer.py, gated behind --second-pass-layer-v0, byte-identical when OFF):
    • Module E3 (labels only): flags recurrent internal LTR-like insertions (recurrent_internal_ltr_like) with null-calibrated per-model recurrence thresholds and 3-tier segmental-duplication independence.
    • Module F1 (correct + flag): resolves internal LTRs mistaken as provirus ends via competing-hypotheses testing (H_end vs H_inside), with hard protection of supported complete proviruses.
    • Module tandem (labels only): identifies boundary-consistent shared-LTR tandem proviruses (shared_ltr).
    • Module R2 (labels only): strictly structural, family-name-free detector for L1-mediated retrotransposed ERV copies (l1_mediated_copy_candidate via 5′/3′ LTR truncation + poly(A) + L1-style TSD).
  • v0.8 Non-ERV Nesting Relations Layer (erv/scripts/layer_relations_nonERV.py): pure annotation layer that emits explicit nested_in links for non-ERV interspersed repeats (Alu, L1, SVA, DNA transposons, etc.) inside ERV host gaps without altering a single ERV join, partition, or tier.

Module B — LINE-1 Retrotransposons (line1/)

  • Frozen LINEpedia v8 engine (line1/v8/engine_v8.py, rules_v8.py, runner_v8.py): strictly zero RepeatMasker IDs (rm_id stripped on load), zero primate data in calibration, zero family names or hand-made lookup tables.
  • Six switch-gated, biologically calibrated mechanisms (line1/v8/v8_policy.json):
    1. tsd_mismatch_inversion — rescues 5′ inversions corroborated by outer TSD closure.
    2. twin_priming_geometry — models canonical LINE-1 twin-priming turnaround coordinates.
    3. utr3_tip_rescue — recovers short, conserved 3′ UTR tips.
    4. tsd_colinear_rescue — rescues colinear splits validated by flanking TSDs.
    5. near3_inversion — handles near-3′ inversions with calibrated wear bounds.
    6. anchored_unknown_frame_inversion — local anchored Smith–Waterman rescue for unknown-frame inverted arms (restricted strictly to T4 with an explicit split alternative).
  • Whole-genome production workflow (line1/workflow/): parallelized 24-chromosome orchestration, resource watchdog, structural contract auditor, and SHA-256 verification.

5. Key Results & Benchmarks (v0.8)

All validation precision figures below come from independent 7-primate phylogenetic empty-site adjudication (never used during training or reconstruction; multi-species ≥ 2 discordant species rule).

ERV Module (erv/, Human GRCh38 & Zero-Tuning Mouse mm39)

Target Genome Reconstructed Elements Complete 5′LTR–int–3′LTR Nesting Relations Held-Out Primate Precision (≥2-sp) Dfam 3.9 vs 4.0 Stability
Human GRCh38 (Dfam 3.9) 482,568 16,725 24,349 ERV-in-ERV + 88,703 non-ERV-in-ERV (68,178 Alu, 11,042 L1, 757 SVA, 8,726 other) 99.51% overall (1,217/1,223) · 99.64% T1–T3 · 99.81% complete T1–T3 (538/539) 88.5% Jaccard (complete ERVs)
Mouse mm39 (chr1–3) (zero tuning) 162,267 3,281 Identical parameters, zero .align files 0/18 opposite-strand F1 false positives —

LINE-1 Module (line1/, Human GRCh38, Out-of-Sample 9 Chromosomes)

Metric (9 out-of-sample chromosomes: chrX + 8 even autosomes · 3,419 primate truth loci) joinTEr LINE-1 (v8)
Genome-wide catalogue (all 24 chroms) 923,172 fragments → 672,483 elements (8,657 5′ inversions, 249,748 parent→child nesting links)
Phylogenetic precision (≥2-sp rule) 99.6% (2,076/2,084, only 8 vetoes) · 99.93% on 5′ inversions · 100.0% on T1 (635/635)
Recall & F1 (Span IoU ≥ 0.90) 62.9% recall (2,151/3,419) · F1 = 77.1% (Union IoU ≥ 0.90: 65.8%, F1 = 79.2%)
Exact recall (±50 bp) 57.0% (1,948/3,419) · rescues 129 strict RepeatMasker-ID errors without ever reading rm_id
Pathological structural errors 0 reverse-order merges (0/1,907) · 0 non-inversion mixed-strand calls · 0 untraced T4 calls
Dfam 3.9 vs 4.0 stability (chrX) 83.7%–87.4% multifragment Jaccard

6. Unified Output Contract

Both modules publish the same clean, auditable set of tab-separated tables (plus SHA-256 checksums in outputs.sha256):

File What It Contains
elements.tsv One row per reconstructed TE insertion: coordinates, strand, structure (5LTR-int-3LTR, solo_LTR, 5′-inversion, etc.), family composition, fragment count, and confidence tier (T1–T4).
membership.tsv Exact fragment-to-element mapping (element_id ↔ RepeatMasker fragment and role).
relations.tsv Directed biological relationships: nested_in (ERV-in-ERV, L1-in-L1, and non-ERV-in-ERV via relations_all.tsv) and shared_ltr / tandem_with.
alternatives.tsv Competing near-optimal partitions and score margins — guaranteed non-empty for every T4 element.
evidence.tsv Full per-seam audit trail showing every additive score term (S_base, S_chance, S_age, S_family, S_peel, S_del, S_extra, S_restart, S_self_tsd), raw vs collapsed gaps, and provenance tags.

7. Quick Start & Verification

Installation

git clone https://github.com/tmontserrat/joinTEr.git
cd joinTEr

# Option 1: Conda / Mamba (recommended — includes Snakemake and BLAST+)
conda env create -f environment.yml
conda activate jointer

# Option 2: pip (core Python dependencies)
pip install -r requirements.txt

Verify Your Installation (Runs in < 5 Seconds, No Genome Data Required)

All self-contained unit tests for both the ERV and LINE-1 engines can be run immediately after cloning:

# 1. ERV core DP engine, scoring, peeling, and self-audit tests (32 tests)
python3 erv/scripts/test_neon_unit.py

# 2. ERV v0.8 second-pass layer tests — E3, F1, tandem, R2 (15 tests)
python3 -m unittest erv/scripts/test_second_pass_layer.py -v

# 3. ERV v0.8 non-ERV nesting relations layer tests
python3 -m unittest erv/scripts/test_layer_relations_nonERV.py -v

# 4. LINE-1 v8 engine, policy switches, and firewall tests
python3 -m unittest line1/test_line1_unit.py -v

Running on Your Own Genome

  • ERV workflow (erv/):
    1. Edit erv/config.yaml to point to your reference genome FASTA and prepared RepeatMasker .out / UCSC rmsk inputs (see docs/INPUT_CONTRACT_ERV.md).
    2. Run the frozen core via Snakemake:
      cd erv
      snakemake --cores 3 out_v071/outputs.sha256
    3. Apply the v0.8 second-pass layer and non-ERV nesting relations layer:
      python3 scripts/second_pass_layer.py --second-pass-layer-v0 --in-dir out_v071 --out-dir out_v08
      python3 scripts/layer_relations_nonERV.py --in-dir out_v08 --out-dir out_v08_relations_layer \
        --rm-path /path/to/genome.fa.out --fasta /path/to/genome.fa
  • LINE-1 workflow (line1/): Set JOINTER_DATA_ROOT / JOINTER_FASTA to your genome workspace and see line1/v8/run_frozen_v8.py, line1/workflow/produce.py, and docs/PRODUCTION_LINE1.md.

8. Repository Map & Detailed Documentation

joinTEr/
├── assets/                   # Logos (joinTEr, HERVarium, LINEpedia)
├── docs/
│   ├── METHODS_ERV.md        # Full mathematical & biological specification (ERV v0.8)
│   ├── INPUT_CONTRACT_ERV.md # Exact RepeatMasker .out / rmsk vs optional .align schema
│   ├── PRODUCTION_LINE1.md   # Whole-genome LINE-1 v8 production & structural audit summary
│   └── BENCHMARK_LINE1.md    # Out-of-sample 9-chromosome LINE-1 benchmark vs comparators
├── erv/
│   ├── Snakefile             # Portable Snakemake workflow for ERV reconstruction
│   ├── config.yaml           # Template configuration
│   ├── config/               # Frozen parameters (v071_params.json, PARAMETERS.tsv, fdr_lookup)
│   └── scripts/              # Core DP engine, v0.8 second-pass layer, non-ERV relations, tests
├── line1/
│   ├── v8/                   # Frozen LINE-1 v8 engine, 6 biological switches & policy JSON
│   ├── workflow/             # Whole-genome 24-chromosome orchestration & structural verification
│   ├── test_line1_unit.py    # Self-contained LINE-1 unit tests
│   └── FREEZE.md             # Freeze provenance & development validation gates
├── environment.yml           # Reproducible conda environment
├── requirements.txt          # Minimal Python pip dependencies
├── CHANGELOG.md              # Release notes (v0.8 pre-release & roadmap to v1.0)
└── LICENSE                   # MIT License

9. The Ecosystem Behind joinTEr

joinTEr is the reconstruction engine powering two companion human transposable-element catalogues currently in preparation:

joinTEr
joinTEr
The biological reconstruction engine (ERV & LINE-1)
HERVarium
HERVarium
Human ERV provirus & solo-LTR catalogue
LINEpedia
LINEpedia
Human LINE-1 insertion & coding catalogue

10. License & Author

Released under the MIT License.

Developed by Tomàs Montserrat Ayuso (t.montserrat.ayuso@gmail.com). If you use or explore joinTEr v0.8 before the v1.0 manuscript is published, please cite this repository (https://github.com/tmontserrat/joinTEr, release v0.8).

About

Reconstructing full-length transposable element insertions (ERV & LINE-1) from fragmented RepeatMasker annotations — transparent, auditable, zero hand-made tables.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages