Tandem repeat somatic instability quantification from long-read sequencing.
MosaicTR uses HP (haplotype) tags in BAM files to decompose tandem repeat signals per haplotype, enabling:
- Somatic instability quantification per haplotype
- Multi-sample comparison for tissue-specific instability detection
- Genotyping with concordance-based zygosity calling
HII (Haplotype Instability Index) — motif-normalized MAD (median absolute deviation) of read-level allele sizes within a haplotype. HII = 0 means stable; higher values indicate greater somatic mosaicism.
IAS (Instability Asymmetry Score) — normalized difference between the two haplotypes' HII values. IAS ≈ 1 indicates instability in one haplotype only (typical heterozygous carrier); IAS ≈ 0 indicates symmetric instability.
pip install .
# Genotype TR loci
mosaictr genotype --bam tagged.bam --loci loci.bed --output genotypes.bed
# Compute somatic instability
mosaictr instability --bam tagged.bam --loci loci.bed --output instability.tsv
# Compare instability across tissues
mosaictr compare --baseline blood.tsv --target colon.tsv --output comparison.tsvpip install .- Python >= 3.10
- pysam >= 0.22
- numpy >= 1.24
- click >= 8.0
- tqdm >= 4.0
mosaictr genotype \
--bam aligned.bam \
--loci loci.bed \
--output genotypes.bed \
--threads 1Options:
--min-mapq 5— Minimum mapping quality--min-flank 50— Minimum flanking bases--max-reads 200— Maximum reads per locus--ref ref.fa— Reference FASTA for parasail realignment (optional)--min-hp-reads 3— Minimum HP-tagged reads per haplotype--min-hp-frac 0.15— Minimum fraction of HP-tagged reads--concordance-threshold 0.7— HP concordance threshold for HET call--min-confidence 0.0— Minimum confidence to report a call (0 = no filter; 0.55 recommended for high-accuracy filtering)
mosaictr instability \
--bam aligned.bam \
--loci loci.bed \
--output instability.tsv \
--threads 1Options:
--min-instability 0.0— Minimum HII threshold for output filtering--min-hp-reads 3/--min-hp-frac 0.15— HP sufficiency thresholds--skip-hp-check— Skip HP tag check (uses gap-split/pooled fallback)
mosaictr compare \
--baseline blood_instability.tsv \
--target colon_instability.tsv \
--output comparison.tsvOptions:
--noise-threshold 0.45— HII threshold for calling unstable--min-delta 0.5— Minimum ΔHII to report--baseline-label/--target-label— Tissue labels
mosaictr matrix \
--inputs blood.tsv --inputs colon.tsv --inputs brain.tsv \
--labels blood --labels colon --labels brain \
--output hii_matrix.tsvBuilds a loci × samples HII matrix and classifies each locus as stable, tissue_variable, or constitutive.
mosaictr evaluate \
--predictions genotypes.bed \
--truth-bed giab_tier1.bed \
--catalog adotto_catalog.bed \
--output report.txtMosaicTR works best with HP-tagged BAMs for true per-haplotype analysis. Without HP tags, the tool falls back to gap-split (bimodal detection) or pooled analysis, which provides lower confidence results.
The instability module will log a warning if fewer than 50% of loci use HP-tagged analysis.
You need a phased VCF (from variant calling + phasing) and your aligned BAM.
WhatsHap (most common):
whatshap haplotag --reference ref.fa input.bam phased.vcf.gz -o tagged.bam
samtools index tagged.bamHiPhase (PacBio official):
hiphase --bam input.bam --vcf phased.vcf.gz --output-bam tagged.bam
samtools index tagged.bamLongPhase (nanopore/HiFi):
longphase haplotag -b input.bam -s phased.vcf.gz -r ref.fa -o tagged
samtools index tagged.bamchr4 3074876 3074933 CAG
chr9 27573528 27573546 AAGGG
chrX 147912050 147912110 CGG
Columns: chrom, start, end, motif sequence.
| Column | Description |
|---|---|
| chrom | Chromosome |
| start | Start position |
| end | End position |
| motif | Repeat motif sequence |
| allele1 | Allele 1 size (bp) |
| allele2 | Allele 2 size (bp) |
| zygosity | HOM or HET |
| confidence | Zygosity confidence score [0, 1] |
| n_reads | Total reads at locus |
| Column | Description |
|---|---|
| chrom, start, end, motif | Locus coordinates and motif |
| median_h1, median_h2 | Median allele size per haplotype (bp) |
| hii_h1, hii_h2 | Haplotype Instability Index (motif-normalized MAD) |
| ias | Instability Asymmetry Score (inter-haplotype difference) |
| n_h1, n_h2, n_total | Read counts per haplotype and total |
| analysis_path | hp-tagged, gap-split, or pooled |
MIT License. See LICENSE file.