Forensic mtDNA Pipeline (FMP)
FMP-NimaGen reports the mtDNA haplotype of a sample, with its point and length
heteroplasmy, from reads of the IDseek® Mitochondrial DNA Full Genome Kit of
NimaGen. It is written in Nextflow.
Table of Contents
Quick Start
You need Linux or macOS, Nextflow
(with Java 17 or later) and Docker or Singularity. The pipeline is tested on
x86-64 Linux, and its test run also with Docker on an Apple Silicon Mac; see
Running with Docker or Singularity
for macOS.
git clone --depth 1 https://github.com/PeterResutik/FMP-NimaGen.git
cd FMP-NimaGen
# a test run on a 2800M control (a few minutes)
nextflow run main.nf -profile test,docker --outdir results_test
# your own run: put its folder, with all its files, into raw_data/ and give its name
nextflow run main.nf -profile docker --run my_run
With Singularity, write singularity instead of docker. The test run’s report,
results_test/p13_report/2800M-DVJ49_S1_L001_separate_frame.xlsx, should show
the 2800M haplotype, with these calls above 50%: T152C, A263G, -315.1C, T477C,
A750G, A1438G, G3010A, A4769G, A8860G, A15326G and T16519C. The results of your
run go to results/my_run/.
The first run with your own reads builds an index of the human mitogenomes in
resources/rtn_files/humans/ (about 20 minutes and 2.7 GB), so the pipeline
folder must be writable. Later runs reuse it.
Input says what the reads must look like, and Reading the
Report what the report’s columns mean.
Overview
The pipeline automates the following steps:
- Mapping and soft-clip removal (
p03–p04): read pairs are mapped to rCRS with bwa, and soft-clipped bases are removed.
- Read merging (
p05): FLASH merges each read pair into one read.
- Primer trimming (
p06): Cutadapt removes the primers and drops reads without a primer or outside the length limits (--minimum_length, --maximum_length), among them the reads that span two amplicons of a primer pool (see Reading the Report). The primer files are described in resources/primers/README.md.
- Mapping (
p07–p08): the merged reads are mapped to rCRS with their primers (for FDSTOOLS) and without (for rtn).
- NUMT filtering (
p09–p10): rtn removes reads that no human mitogenome in humans_NimaGen_2026-10-30.fa explains closely enough (--rtn_likelihood), which removes reads from nuclear copies of mtDNA (NUMTs); reads below --mapQ are removed too, and so are reads that the mapping cannot align end to end, as rtn judges only the aligned part of a read. rtn judges the reads without their primers (p09); p10 keeps the same reads, by name, for FDSTOOLS. With --rtn_positions, rtn sees the reads at base quality 2 at chosen positions, for example the 50 positions that change most often in human mtDNA (resources/rtn_files/positions/), so that differences there count little; FDSTOOLS keeps the original qualities.
- Quality control (
p11): read depth per amplicon.
- Variant calling (
p12): FDSTOOLS on the reads with primers. It distrusts bases below --baseQ (30; 0 switches this off): a read that differs from a more common sequence of the same length only at such bases counts for that sequence.
- Report (
p13): FDSTOOLS’ calls are written in one notation into one Excel table per sample.
Each step is a module in modules/ (one Nextflow process per file), numbered in the order the steps run (p00 to p13); main.nf connects them, and each result folder has the name of its step.
- Kit: the IDseek® Mitochondrial DNA Full Genome Kit of NimaGen (IDS-MTC96),
which amplifies the mtDNA in 100 overlapping amplicons in two primer pools. The
primer files in
resources/primers/ are those of this kit.
- Reads: paired-end FASTQ files of an Illumina MiSeq, 2 × 226 cycles, named
<sample>_R1_001.fastq.gz and <sample>_R2_001.fastq.gz. The names the MiSeq
writes, such as sample1_S1_L001_R1_001.fastq.gz, fit as they are. For another
read length, set --max_overlap to it.
- Where they go: put the run’s folder, with all its files, into
raw_data/ and
give its name: --run my_run takes the read pairs in raw_data/my_run/, at its
top or in any subfolder, and writes the results to results/my_run/. Every
sample needs exactly one R1 and one R2 file there; otherwise the run stops at
the start and names the sample. For reads elsewhere, --reads takes a pattern
in quotes, e.g. --reads '/path/to/fastq/*_{R1,R2}_001.fastq.gz', and
--outdir the folder of the results.
- Undetermined reads: files that start with
Undetermined are left out, and
the log says so; --undetermined true runs them like a sample.
- Controls: negative and positive controls are run like samples. A negative
control without reads gives a report that says so.
Installation and Setup
Nextflow Requirements and Installation
Nextflow requires:
- Bash 3.2 or later
- Java 17 (or later, up to Java 24)
It runs on Linux and macOS; on Windows, only inside WSL2.
Check your Java version:
java -version
If not installed, the easiest way is via SDKMAN!:
# Install SDKMAN
curl -s https://get.sdkman.io | bash
# Restart your terminal, then install Java
sdk install java 17.0.10-tem
# Confirm installation
java -version
Install Nextflow:
curl -s https://get.nextflow.io | bash
chmod +x nextflow
mv nextflow /usr/local/bin # or any directory in your PATH
nextflow -version
Clone the Repository
git clone --depth 1 https://github.com/PeterResutik/FMP-NimaGen.git
cd FMP-NimaGen
This is the latest release; --branch v0.7.0, for example, gives that version.
--depth 1 leaves out the history, about 380 MB.
Install rtn (only for Conda)
The Docker image holds rtn; with Conda, build it yourself. The NUMT filter runs
rtn, which is not part of the conda environment.
Build it from the fork with three fixes to how rtn scores reads
(it uses base qualities, which --rtn_positions needs, and no longer drops reads
with length variants in the C-stretches); this is tested on Linux:
git clone -b fixes https://github.com/PeterResutik/RtN.git
cd RtN
conda create -n rtn-build -c conda-forge jsoncpp
conda activate rtn-build
PREFIX=$CONDA_PREFIX ./build.sh
cp rtn /usr/local/bin/ # or any directory in your PATH
build.sh also needs git, make, autoconf, automake, a C/C++ compiler and the
development files of zlib, bzip2 and xz. It does not yet build on Apple Silicon.
rtn as released also runs with the pipeline, but without the fixes: it ignores base
qualities, so --rtn_positions has no effect, and it drops some reads with length
variants.
Running the Pipeline
Running with Docker or Singularity (Recommended)
The image peterresutik/nimagen-pipeline:0.8.0 holds every tool the pipeline
runs (the Conda environment and rtn with its three fixes), and GitHub runs the
tests in it. Nextflow, Java and the pipeline folder stay outside it. FDSTOOLS
downloads the chrM reference sequence from Ensembl the first time it runs and
keeps it in ~/.strnaming-cache; the image already holds it, so the containers
need neither internet access nor a home folder. With Docker:
nextflow run main.nf -profile docker
With Singularity (or Apptainer), for example on a cluster without Docker:
nextflow run main.nf -profile singularity
Nextflow pulls the image on the first run (Singularity converts it and keeps it in
work/singularity/, or in NXF_SINGULARITY_CACHEDIR if set). The image is built
for x86-64 Linux, because rtn’s alignment library uses x86 instructions; on Apple
Silicon, Docker runs it through emulation. On an Apple Silicon Mac with Docker
Desktop (Rosetta emulation), the test run (-profile test,docker) gives the same
report as on Linux; a full run with the whole humans index has not been tested on
a Mac. Docker Desktop runs the containers in a virtual machine with its own
memory limit (Settings, Resources), while Nextflow plans the rtn tasks
(--rtn_memory, 4 GB each) by the computer’s memory: give Docker enough memory,
or run fewer tasks at once with -qs. The image is built from lock files with the
exact version of every package (containers/), so every build gets the same
tools; FMP-NimaGen.yml names only the main versions. To build the image
yourself:
docker build --platform linux/amd64 -t peterresutik/nimagen-pipeline:0.8.0 .
Running with Conda
With the tools of FMP-NimaGen.yml and rtn built from the fork (see Install rtn
(only for Conda)), which is not possible on Apple
Silicon:
- Ensure you have Miniconda or Conda installed.
- Create the environment:
conda env create -f FMP-NimaGen.yml
- Activate the environment and run the pipeline:
conda activate FMP-NimaGen
nextflow run main.nf -profile local
The first run needs internet access: FDSTOOLS downloads the chrM reference
sequence from Ensembl and keeps it in ~/.strnaming-cache.
Resuming and Limiting a Run
To resume a previous run and skip already completed steps, add -resume.
Nextflow runs as many tasks at once as the computer has cores; to keep the
computer responsive during a run, limit them with -qs, e.g. -qs 4.
Output
Results go to results/ (--outdir), or to results/<run>/ with --run:
| Folder |
Contents |
p00_parameters.txt |
the options of the run |
p11_read_depth/<sample>/ |
read depth per amplicon (plot and tables) |
p12_fdstools/<sample>/ |
FDSTOOLS files (sequences per amplicon, statistics, HTML) |
p13_report/<sample>_separate_frame.xlsx |
the report (_shared_frame with --frame shared) |
pipeline_info/ |
run reports, only with --pipeline_info true: time, CPU and memory of every task (trace.txt), a timeline (timeline.html) and a summary (report.html) |
BAM and FASTQ intermediates are also copied unless --publish_bams false is set.
Two of them hold every mapped read of the NUMT filter, so that the removed reads
can be seen next to the kept ones:
p09_filter_numts/<sample>/*_all_reads.rtn.bam: the reads without primers, as
rtn judged them, with rtn’s tags ZH and ZN (the number of mismatches from
the closest human mitogenome and from the closest NUMT);
p10_reads_for_fdstools/<sample>/*_all_reads.rtn.bam: the same reads with
their primers.
A removed read has MAPQ 0, and every read has a tag ZF with the reason. In IGV,
group or colour the alignments by the tag ZF. IGV shows at most 100 reads per
50 bases by default, so most removed reads stay hidden at a high depth; to see
them all, untick “Downsample reads” (View, Preferences, Alignments). To see
where the variants of --pathogenic_list lie, load
resources/pathogenic/mitomap_confirmed_2026-11-18.bed as well.
ZF |
Meaning |
kept |
the read is used |
numt |
rtn removed the read: no human mitogenome explains it closely enough (--rtn_likelihood) |
clipped |
the mapping without primers (p08) could not align the read end to end, e.g. a chimera that holds part of the mtDNA twice |
mapq |
mapping quality below --mapQ, and rtn did not remove the read |
trimmed |
(p10 only) primer trimming (p06) removed the read (no primer, or shorter or longer than --minimum_length and --maximum_length), so rtn never judged it |
unmapped |
(p10 only) the read maps with its primers but not without them, so rtn never judged it |
Reading the Report
The report has one row per variant, sorted by position. The first column,
FMP, is the call. The columns after it show the reads FDSTOOLS counted for it.
Notation
| Example |
Meaning |
A263G |
substitution: rCRS base, position, base found |
A523- |
deletion of the rCRS base at 523 |
-309.1C |
insertion of a C after 309; a second inserted base is -309.2C |
T195Y |
point heteroplasmy: two or more bases at 195, written with the IUPAC code (Y is C and T) |
-309.2c |
lowercase: a length variant on part of the molecules only (between --lh_thresh and 100 minus --lh_thresh percent) |
LOW |
not a variant: an amplicon with fewer reads than --depth, named in marker; calls in marker_range rest on few reads |
In 16180–16193 and 300–315 the labels follow --frame: separate writes
each run of equal bases by its length, shared lays the sequence from the
left, as mitoLEAF and EMPOP do. In both frames, one base inside an A-run that
has all its A’s is an insertion: AAACA at 16180 is -16182.1C, where mitoLEAF
writes 16184A. Outside these regions a molecule is written with the fewest
changes from rCRS. That can differ from the spelling of the phylogeny: L1c1c
and L5b1 are written G247- where the phylogeny writes 247A 249del. The
molecule is the same.
Columns
| Column |
Meaning |
FMP |
the call |
vf_FDS |
share of the reads with the variant, in percent; with several bases at one position, one value per base (C 40, A 10) |
depth_flag |
for a point heteroplasmy that passes --min_vf_FDS but whose least common base is not above the depth rule at its read depth: the share (%) it would need to be above, e.g. 4.77; empty otherwise; not written with --depth_flag false |
rd_FDS, rd_total_FDS |
reads with the variant, and all reads at the position; in a LOW row, the reads of the amplicon |
variant_note |
remarks; not written with --variant_note false |
dominant_molecule |
in 16180–16193, 300–315 and 57–60: what the molecule with the most reads carries at this position, with that molecule’s share of the reads, e.g. -16193.1C (40.9%); empty if it carries no change there |
marker, marker_range, num_markers |
the amplicons FDSTOOLS’ depth and frequency come from (every amplicon with reads covering the position), their ranges, and their number |
pathogenic |
yes when the row carries a variant of --pathogenic_list (MITOMAP’s confirmed disease variants, see resources/pathogenic/), also as one base of a point heteroplasmy; such variants can then be left out of the haplotype; not written with --pathogenic remove or false |
With --pathogenic remove, the rows that carry a variant of the list are left
out, a point heteroplasmy with such a base included, and every report says so
in a note under its table, whether or not the sample had such a variant. A
variant that IGV shows in the reads but the report does not may be one of
them: resources/pathogenic/ has the list as a BED file to load next to the BAMs.
FDSTOOLS gives the reads and the share of the variant (rd_FDS, vf_FDS);
the reads without it follow from rd_total_FDS. Reads that run from one
amplicon’s left primer to the right primer of the next amplicon in the same
primer pool (001 to 003, 002 to 004, 003 to 005, 098 to 100) are whole mtDNA
molecules. FDSTOOLS would count such a read for every amplicon whose two primers
it holds, and at the positions where two of these amplicons overlap it would
count twice. The pipeline therefore leaves these reads out (--maximum_length
300; without its left primer, the longest amplicon has 255 bases and the shortest
of these products 331), so that a read counts once at each position. They have
ZF trimmed in the BAMs of p10.
Colours
The colour of the FMP cell shows the kind of row at a glance: yellow for
LOW, orange for a point heteroplasmy, blue for a lowercase length variant,
and green for the other variants (a lighter green for insertions and
deletions). Yellow rows are the ones to look at. The other columns have a
green background; a pathogenic cell that says yes is red, and a depth_flag
cell with a value is yellow.
Depth Rule
--min_vf_FDS is the same at every read depth, but with fewer reads the
method’s noise reaches higher shares: at 100 reads, 3 wrong reads already make
3%. The depth rule is the share a point heteroplasmy must be above at its read
depth so that at most 1 in --depth_risk samples has a false one. A row that
passes --min_vf_FDS but not the depth rule stays in the report, with the
share it would need in depth_flag; nothing is removed. The rule applies to the least common base
present, rCRS included, and not in 16180–16193, 300–315 and 57–60.
The read depth is that of one amplicon: the rule is calculated for a sample
whose amplicons each have that many reads, and a position read by two of them,
with twice the reads, is part of that calculation. At such a position the rule
takes half of rd_total_FDS.
The rule comes from a noise model of control samples (--noise_model): for
each control, how many wrong bases reach each share of its reads, from 0.1 to
2%. In a sample with n reads per amplicon their reads are binomial and their
number Poisson; the threshold is the lowest share at which the chance of at
least one above it stays within the risk. The shipped model,
resources/noise_model/2800M_8controls.tsv, holds the 2800M controls of 8
runs. With it, at 1 in 100 samples, a point heteroplasmy needs more than 5% at
100 reads, 2.6% at 500 and 2.2% at 1,000, and the rule is at or
below 2% from about 1,600 reads; at 1 in 1,000 (--depth_risk 1000) it needs
6%, 3.2% and 2.6%, and 2% from about 3,550 reads. A lab can build a model from
its own controls, or add them to the shipped one: see
resources/noise_model/README.md.
Main Options
| Option |
Default |
Meaning |
--run |
none |
a run’s folder in raw_data/: its read pairs, in any subfolder, instead of --reads |
--reads |
raw_data/*_{R1,R2}_001.fastq.gz |
input files, when there is no --run |
--undetermined |
false |
true runs the Undetermined_* files like a sample; otherwise they are left out |
--outdir |
results, or results/<run> with --run |
output folder |
--min_vf_FDS |
2 |
a base counts as present from this share (%) |
--minimum |
2 |
FDSTOOLS counts a sequence only if at least this many reads have it |
--baseQ |
30 |
the lowest base quality FDSTOOLS trusts: a read that differs from a more common sequence of the same length only at lower-quality bases counts for that sequence; 0 trusts every base |
--max_overlap |
226 |
FLASH counts the mismatches of an overlap over at most this many bases; set it to the read length, so that the whole overlap is checked |
--lh_thresh |
10 |
length variants: under 10% not reported, 10–90% minor (lowercase), above 90% major |
--depth |
20 |
amplicons with fewer reads are marked LOW |
--frame |
separate |
how 16180–16193 and 300–315 are written: separate or shared |
--variant_note |
true |
false leaves the variant_note column out of the report |
--pathogenic |
flag |
flag marks the rows that carry a variant of --pathogenic_list in the column pathogenic; remove leaves these rows out of the report, and a note under the table says so; false does neither |
--pathogenic_list |
resources/pathogenic/mitomap_confirmed_2026-11-18.tsv |
the variants --pathogenic marks or leaves out; resources/pathogenic/README.md says how to build a newer list |
--depth_flag |
true |
false leaves the depth_flag column out of the report |
--noise_model |
resources/noise_model/2800M_8controls.tsv |
the control samples the depth rule comes from; several files, comma-separated, are pooled |
--depth_risk |
100 |
the depth rule allows a false point heteroplasmy in at most 1 in this many samples, e.g. 1000 |
--mapQ |
30 |
reads with a lower mapping quality are removed |
--skip_numt_filter |
false |
skip rtn and the removal of reads that cannot be aligned end to end (for simulated reads) |
--rtn_positions |
none |
a file of positions rtn sees at base quality 2, such as resources/rtn_files/positions/recurrent_positions.tsv (none: off); only an rtn that uses base qualities, such as the fork at https://github.com/PeterResutik/RtN (branch fixes), counts them less |
--rtn_likelihood |
1e-9 |
the minimum likelihood a read must have under the human mitogenomes (rtn -L; rtn’s own default is 1e-5); a lower value removes fewer reads |
--rtn_memory |
4 GB |
memory per rtn task (p09), which holds the humans index (about 2 GB); Nextflow starts no more tasks than the computer’s memory holds |
--num_threads |
6 |
threads of FDSTOOLS tssv (p12); Nextflow reserves as many cores for each task, at most as many as the computer has |
--publish_bams |
true |
copy BAM and FASTQ intermediates to the results folder |
--pipeline_info |
false |
true writes the run reports into pipeline_info/ |
All options and their defaults are in the params block of nextflow.config. A
value given on the command line (--name value) or in a file passed with
-params-file overrides the default. All options and their values are printed at
the start of each run and saved in p00_parameters.txt.
Configuration
Profiles
-profile local: runs the tools installed in the active Conda environment (FMP-NimaGen.yml) and rtn.
-profile docker: runs every tool in the Docker image (see Running with Docker or Singularity).
-profile singularity: the same image with Singularity or Apptainer.
-profile test: a small run on the 2800M control in tests/data/, with a small
humans file, in a few minutes; together with one of the above, e.g.
nextflow run main.nf -profile test,docker. A way to try the pipeline.
Tests
The Python scripts in resources/scripts have unit tests in tests/. Run them
from the repository root in the Conda environment:
conda activate FMP-NimaGen
pytest
The whole pipeline is tested with nf-test on the
2800M control in tests/data/ (-profile test): the test checks the control’s
haplotype and that its report and FDSTOOLS’ sequences are as before
(tests/main.nf.test.snap). Run it from the repository root:
nf-test test --profile test,docker # or --profile test in the Conda environment, with rtn installed
A change meant to change the report also updates the snapshot
(nf-test test --profile test,docker --update-snapshot).
GitHub runs both, with the tools of the Docker image, on every push to main and
pipeline-rebuild and on every pull request (.github/workflows/tests.yml).
The tools that run the pipeline on simulated reads and evaluate it on real
samples are in tests/simulation/ and tests/evaluation/, each with a README.
Known Limitations
- A sequencing error of good base quality that comes back at the same position in
many samples cannot be told from a heteroplasmy. FDSTOOLS distrusts bases below
--baseQ, and depth_flag marks the heteroplasmies that noise can reach at
their read depth; a higher detection threshold (--min_vf_FDS) leaves such calls
out, real ones at low shares included.
- A variant under a primer can weaken the PCR of its amplicon, which then has
few reads or none, and its calls rest on those few reads. Seen so far: G3834A
under the right primer of amplicon 025 (very few reads), C16278T with A16293G
under the right primer of amplicon 097, and 16294T (often with 16296T), common
in haplogroup T, also under 097’s right primer: 097 then had 10–23% of the
sample’s median read depth. Only amplicon 097 covers 16102–16212. The read
depth per amplicon is in
p11_read_depth/.
- FDSTOOLS judges the base quality of identical reads together (their cubic
mean), not read by read (
--baseQ). A real variant at a position where the
quality is naturally low, such as the edge of a long homopolymer, can then be
counted for the main sequence.
Cleaning Up
Remove Cache and Temporary Files
Delete Nextflow’s cache and run history (-resume no longer works afterwards):
rm -rf .nextflow
Clean up intermediate pipeline files:
nextflow clean -f
Remove Output Files (Optional)
To delete generated results:
rm -r work
rm -r results
Use with caution: this permanently deletes output data.
Citation
If this pipeline is used in research, please cite this repository with its version, and the tools it runs: FDSTools, RtN! (see resources/rtn_files/numts/README.md), BWA, SAMtools, FLASH, Cutadapt and Nextflow.
Contributing
Contributions are welcome. Please open an issue or pull request via GitHub if you encounter problems or have suggestions.
For support or feedback, submit an issue on the GitHub repository.
To run the pipeline on a cluster, contact us the same way.
Use of AI
FMP-NimaGen was developed with the assistance of AI tools: versions 0.1.0 to
0.1.4 with ChatGPT (OpenAI), and from version 0.2.0 on with Claude Code
(Anthropic), an AI coding assistant with which code, tests and documentation
were drafted. Every change was reviewed, tested and committed by the author,
who is responsible for the pipeline and its results.
License
FMP-NimaGen is released under the MIT License.
Third-party material in this repository keeps its own terms:
resources/rtn_files/humans/humans_NimaGen_2026-10-30.fa.bz2 (and the earlier
humans_NimaGen_2026-10-19.fa.bz2) are built from
mitoLEAF (Mozilla Public
License 2.0), GenBank, and the 1000 Genomes Project and HGDP data (see
resources/rtn_files/humans/build/README.md);
tests/data/humans/humans_test.fa.bz2 is a part of it.
resources/rtn_files/numts/ holds the NUMT sequences of
RtN! as RtN! ships them, under RtN!'s GNU
General Public License, version 3 (resources/rtn_files/numts/README.md and
LICENSE.txt there).
The tools the pipeline runs (FDSTOOLS, bwa, samtools, rtn and others) are
not part of this repository and are covered by their own licences.
评论