Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ jobs:
matrix:
os: [ubuntu-latest]
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: ubuntu-latest
python: "3.9"
include:
- os: ubuntu-24.04
python: "3.9"
- os: macos-latest
python: "3.13"
runs-on: ${{ matrix.os }}
Expand All @@ -25,6 +30,13 @@ jobs:
with:
python-version: ${{ matrix.python }}

- name: Install the optional genome aligner (filter-paralogs tests)
run: |
# mappy has no wheel for this macOS Python, and its source does not compile as the
# universal (arm64 + x86_64) binary that setup-python's interpreter asks for.
if [ "$RUNNER_OS" = "macOS" ]; then export ARCHFLAGS="-arch $(uname -m)"; fi
python -m pip install mappy

- name: Run tests
run: python -m unittest discover -s tests -v

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,6 @@ docs/book/
# macOS
.DS_Store
examples/madcats-demo/results/

# minimap2 indexes built by filter-paralogs
*.mmi
192 changes: 70 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,60 @@

**Marker-Anchored Discovery and Counting of Alleles from Targeted Sequencing.**

`madcats` is a command-line tool that turns targeted-sequencing FASTQs into
`madcats` is a command-line tool that converts targeted-sequencing FASTQ files into
[MADC](https://softwarehub.breedinginsight.org/learn/what-is-a-madc-file.html) microhaplotype count
tables. A MADC (Missing Allele Discovery Counts) table records the read count of every
microhaplotype in every sample. A microhaplotype is the short sequence a marker amplifies, so a
marker can have more than two alleles, and the variants beside its target SNP are kept. `madcats`
counts the alleles a panel was designed for and finds additional ones in the reads.
microhaplotype across all samples. Because a microhaplotype captures the full target window
amplified by a marker, a locus can carry more than two alleles while retaining secondary variants
alongside the target SNP. `madcats` counts the designed alleles in a panel and discovers additional
microhaplotypes directly from the reads.

The output is a raw MADC table. It goes through HapApp, which assigns fixed allele IDs for building
a microhaplotype database and comparing sequencing runs. For existing downstream pipelines, a MADC
converts to a VCF of SNP genotype calls, with
[BIGr and updog](https://softwarehub.breedinginsight.org/learn/madc-to-vcf.html) after HapApp.
`madcats` produces a raw MADC table. Downstream workflows typically pass this table through HapApp,
which assigns fixed allele IDs to support cross-project microhaplotype databases. For SNP-based
genotyping pipelines, the HapApp output can then be converted to a VCF and genotyped with
[BIGr and updog](https://softwarehub.breedinginsight.org/learn/madc-to-vcf.html).

`madcats` handles DArTag, AgriSeq (Ion Torrent), GT-seq, rhAmpSeq and Flex-Seq capture data.
It needs only the Python 3 standard library. Every analysis threshold can be adjusted via a command-line option, and
each run writes a JSON file with its parameters and read counts processed during the analysis run.
The same codebase supports DArTag, AgriSeq (Ion Torrent), GT-seq, rhAmpSeq, and Flex-Seq capture
data using only the Python 3 standard library. Every analysis threshold is exposed as a command-line
option, and each run writes a QC JSON file recording its parameters and per-sample read accounting.

> **A prior MADC is not an input.** Generation uses only the FASTQs plus the assay design: the
> DArTag primer/probe files, a probe design alone, or a platform-neutral Ref/Alt tag csv.
> **A prior MADC is not required.** Generation uses only the FASTQ files and the assay design,
> provided as DArTag primer and probe files, a probe design alone, or a platform-neutral Ref/Alt
> reference-tag CSV.

## Highlights

- Closely matches vendor output: read counts correlate at r = 0.9997 with the DArT MADC on a
sweetpotato DArTag panel, and dosage calls agree 95–99% across five DArTag panels.
- Designed to be platform independent, with testing performed on DArTag, GT-Seq, rhAmpSeq, Flex-Seq, and AgriSeq.
- Builds the panel from vendor design files (`madcats design`), from the probe design and the reads
when there is no primer file (`madcats infer-design`), or from your own Ref/Alt tag CSV.
- Reports a new microhaplotype only when several samples carry it, one sample has many reads of it,
or (optionally) it has enough high-quality reads.
- Merges sequencing errors back into the alleles they came from, without changing any sample's
Ref/Alt dosage.
- Handles indels, including ones the panel was not designed for.
- Works with AgriSeq-style reads that don't start at a primer (`madcats normalize-reads`) and with
paired-end reads (`madcats merge-pairs`).
- Writes raw MADC tables for HapApp, which prepares them for BIGr and other tools. Each row also
lists its variants and marker type.
- Runs samples in parallel and caches per-sample results, so reruns are fast.
- Closely matches vendor output, with r = 0.9997 read-count correlation against the DArT MADC on a
sweetpotato DArTag panel and 95–99% dosage agreement across five DArTag panels.
- Builds the panel definition from vendor design files (`madcats design`), infers it from the probe
design and reads when no primer file is available (`madcats infer-design`), or accepts a curated
Ref/Alt reference-tag CSV directly.
- Reports novel microhaplotypes only when they are reproducible across samples, reach high depth in
a single sample, or (optionally) pass a whole-tag base-quality threshold.
- Merges sequencing errors back into their parent alleles while protecting canonical and
evidence-passing alleles and restricting pooled merges to the same target allele.
- Handles both designed indels and novel undesigned indels through gapped alignment.
- Supports non-primer-started reads such as AgriSeq (`madcats normalize-reads`) and paired-end reads
(`madcats merge-pairs`).
- Includes an optional genome-based paralog filter (`madcats filter-paralogs`, experimental, requires
`pip install 'madcats[genome]'`) for panels where co-amplified paralogs inflate
heterozygosity. It works on MADCATS, vendor, and HapApp fixed-allele-ID MADCs.
- Processes samples in parallel and caches per-sample assignment results for fast reruns.

## Installation

### From PyPI (Recommended)

Requires Python 3.9 or newer.

```bash
pip install madcats
madcats --help
```

To keep it isolated from other Python packages, use [pipx](https://pipx.pypa.io/):
`pipx install madcats`.

### Pre-built Binaries

Standalone executables that need no Python installation are attached to each
[release](https://github.com/Breeding-Insight/MADCATS/releases):
- `madcats-linux-x86_64.tar.gz`: Linux
- `madcats-macos-x86_64.tar.gz`: macOS (Intel)
- `madcats-macos-aarch64.tar.gz`: macOS (Apple Silicon)

```bash
# Download and extract (example: Linux)
curl -LO https://github.com/Breeding-Insight/MADCATS/releases/latest/download/madcats-linux-x86_64.tar.gz
tar -xzf madcats-linux-x86_64.tar.gz
./madcats --help

# Optional: install to PATH
mkdir -p ~/bin && mv madcats ~/bin/
# Add to PATH if not already (add to ~/.bashrc or ~/.zshrc):
# export PATH="$HOME/bin:$PATH"
```

### From Source

```bash
git clone https://github.com/Breeding-Insight/MADCATS.git
cd MADCATS
pip install . # or: python3 madcats.py --help (no install needed)
```
Each [release](https://github.com/Breeding-Insight/MADCATS/releases) also has standalone executables
for Linux and macOS that need no Python. See
[Installation](https://madcats.readthedocs.io/en/latest/getting-started/installation.html) for
those, for `pipx`, for running from a clone, and for the optional aligner that `filter-paralogs`
needs.

## Quick Start

Expand All @@ -110,37 +86,25 @@ madcats validate \
--generated results/project_MADC.csv \
--expected vendor_MADC.csv \
--report results/validation.json
```

No primer file? Infer the panel from the probe design and the reads:

```bash
madcats infer-design \
--probe-design panel_probe-design.txt \
--fastq-dir fastqs/ \
--output reference_tags.csv
```

Reads that are not primer-started (for example AgriSeq on Ion Torrent) are normalized first:

```bash
madcats normalize-reads --probe-design markers.tsv --fastq-dir raw_fastqs/ --out-dir normalized/ --jobs 8
madcats generate --fastq-dir normalized/ --fastq-glob "*.fastq" \
--reference-tags normalized/window_reference_tags.csv \
--tag-length 41 --min-supporting-freq 0.10 --output project_MADC.csv
```
The tutorials cover the other routes, which are panels
[without a primer file](https://madcats.readthedocs.io/en/latest/tutorials/primer-free.html),
[AgriSeq and other reads that do not start at a primer](https://madcats.readthedocs.io/en/latest/tutorials/agriseq.html)
and [paired-end reads](https://madcats.readthedocs.io/en/latest/tutorials/paired-end.html).

## Documentation

Full documentation is available at [madcats.readthedocs.io](https://madcats.readthedocs.io), including:

- [Getting Started](https://madcats.readthedocs.io/en/latest/getting-started/installation.html): installation and first steps
- [Tutorials](https://madcats.readthedocs.io/en/latest/tutorials/dartag.html): walkthroughs for DArTag, primer-free, AgriSeq and paired-end data
- [Command Reference](https://madcats.readthedocs.io/en/latest/commands/overview.html): every subcommand and option
- [Evidence Model](https://madcats.readthedocs.io/en/latest/reference/evidence-model.html): how alleles are counted, discovered and denoised
- [Getting Started](https://madcats.readthedocs.io/en/latest/getting-started/installation.html) for installation and first steps
- [Tutorials](https://madcats.readthedocs.io/en/latest/tutorials/dartag.html) with step-by-step examples for DArTag, primer-free, AgriSeq, and paired-end data, plus the paralog filter
- [Command Reference](https://madcats.readthedocs.io/en/latest/commands/overview.html) for every subcommand and option
- [Evidence Model](https://madcats.readthedocs.io/en/latest/reference/evidence-model.html) on how MADCATS counts, discovers, and denoises alleles

The design rationale and version-by-version measurements behind every default are recorded in the
[development record](https://github.com/Breeding-Insight/MADCATS/blob/main/docs/DEVELOPMENT.md).
The [development record](https://github.com/Breeding-Insight/MADCATS/blob/main/docs/DEVELOPMENT.md)
documents the design rationale and version-by-version benchmarks behind each default.

## Commands

Expand All @@ -149,56 +113,43 @@ The design rationale and version-by-version measurements behind every default ar
| `madcats design` | Reconstruct Ref/Alt tags from vendor primer + probe-design files |
| `madcats infer-design` | Infer a reference-tag panel from the probe design plus FASTQ evidence |
| `madcats merge-pairs` | Merge overlapping paired-end reads into single fragments |
| `madcats normalize-reads` | Orient and window non-primer-started amplicon reads (e.g. AgriSeq) |
| `madcats window-scan` | Sweep candidate tag lengths and recommend one from the project's own reads |
| `madcats normalize-reads` | Orient and window non-primer-started amplicon reads (e.g., AgriSeq) |
| `madcats window-scan` | Sweep candidate tag lengths and recommend one from the project's reads |
| `madcats generate` | Generate the MADC count table |
| `madcats validate` | Compare a generated MADC against a reference MADC |
| `madcats filter-paralogs` | Drop or flag MADC rows that a reference genome places at another locus (experimental, requires `mappy`) |

Run `madcats <command> --help` for full options.

## Input Formats

### Reference tags (CSV)
The platform-neutral panel definition that `generate` consumes. Produced by `design`,
`infer-design` or `normalize-reads`, or curated by hand.
```
MarkerName,LeftPrimerSequence,RefSequence,AltSequence
Chr01_000123,ACGTTGCAGGTCAAGT,ACGTTGCAGGTCAAGTTCA...,ACGTTGCAGGTCAAGTTCG...
```
`VariantPositionInTagSequence`, `VariantRef`, `VariantAlt`, `RightPrimerSequence` and
`LocusGroup` are optional.

### Probe design (TSV/CSV)
`MarkerName` and `TargetSequence` with one bracketed variant: a SNP such as `[C/T]` or an
anchored indel such as `[A/ACTTG]`.

### FASTQs
One FASTQ (optionally gzipped) per sample in a folder. Sample columns are named by the FASTQ stem,
or by a `--sample-lookup` table.
Run `madcats <command> --help` for full options. `filter-paralogs` is new in 0.14.0 and is marked
experimental, so its options, defaults, and outputs may change in future releases.

## Output
## Input and Output

| File | Contents |
|------|----------|
| `project_MADC.csv` | MADC table: `AlleleID`, `CloneID`, `AlleleSequence`, summary columns, one read-count column per sample |
| `project_MADC.csv.qc.json` | Parameters, provenance, and per-sample read accounting |
| `project_MADC.csv.variants.csv` | One line per variant event per row (with `--annotations on`, the default) |
`generate` takes one FASTQ file per sample (plain or gzipped) and a reference-tag CSV panel
definition generated by `design`, `infer-design`, `normalize-reads`, or curated manually. It writes
the MADC count table, a QC JSON file with run parameters and per-sample read accounting, and a
sidecar CSV listing each row's variants. See
[Input Formats](https://madcats.readthedocs.io/en/latest/getting-started/input-formats.html) and
[Output Formats](https://madcats.readthedocs.io/en/latest/reference/output-formats.html). Breeding
Insight's [MADC file format overview](https://softwarehub.breedinginsight.org/learn/what-is-a-madc-file.html)
describes the table's columns.

## Validation

Each platform was checked against the best independent comparison available for its dataset.
"Genotype agreement" means updog dosage calls made from the MADCATS table (through HapApp and BIGr)
compared with the reference genotypes.
Each platform was evaluated against the best independent comparison available for its dataset.
"Genotype agreement" refers to updog dosage calls generated from the MADCATS table (via HapApp and
BIGr) compared with independent reference genotypes.

| Platform | Accuracy | Validated against |
|----------|----------|-------------------|
| DArTag (sweetpotato, red clover, blackberry, alfalfa, pecan) | count r = 0.9997; dosage agreement 95.4–98.8% | vendor MADC, vendor/updog dosage, families, skim-seq VCF |
| AgriSeq, Ion Torrent (honeybee, oyster) | 94.9% vs Torrent VariantCaller; 98.0% replicate concordance | vendor caller + replicates |
| DArTag (sweetpotato, red clover, blackberry, alfalfa, pecan) | count r = 0.9997, dosage agreement 95.4–98.8% | vendor MADC, vendor/updog dosage, families, skim-seq VCF |
| AgriSeq, Ion Torrent (honeybee, oyster) | 94.9% vs Torrent VariantCaller, 98.0% replicate concordance | vendor caller + replicates |
| GT-seq (delta smelt) | 99.49% | independent BWA/bcftools truth VCF |
| Flex-Seq capture (cranberry) | 95.13% genotype agreement | published population VCF + 20 trios |
| rhAmpSeq (8 grape families) | 99.92–99.99% family transmission | Mendelian constraints + same-reads head-to-head |

> Important Note: MADCATS has been tested on several published and unpublished DArTag species panels. For the performance across the other targeted genotyping platforms, additional validation is needed on available data.
Details: [Validation & Accuracy](https://madcats.readthedocs.io/en/latest/reference/validation.html).

See [Validation & Accuracy](https://madcats.readthedocs.io/en/latest/reference/validation.html) for details.

## Development

Expand All @@ -216,12 +167,9 @@ If MADCATS is useful in your work, please cite:
> Sandercock, A.M. (2026). MADCATS: Marker-Anchored Discovery and Counting of Alleles from Targeted
> Sequencing. GitHub repository: https://github.com/Breeding-Insight/MADCATS

*(A formal article/DOI is planned; this section will be updated when available.)*

For the MADC format, see Breeding Insight's
[MADC file format overview](https://softwarehub.breedinginsight.org/learn/what-is-a-madc-file.html).
*(A formal article/DOI is planned, and this section will be updated when available.)*

**AI assistance:** MADCATS was developed in collaboration with Claude Opus 5.5 and Fable 5.1
**AI assistance.** MADCATS was developed in collaboration with Claude Opus 5.5 and Fable 5.1
(Anthropic), which helped write its code and documentation. The authors directed the work, reviewed
and tested the results, and are ultimately responsible for the application.

Expand Down
Loading
Loading