A command-line toolkit for extracting fragmentomic features from cell-free DNA sequencing data (BAM/CRAM). It provides subcommands for fragment size distributions, cleavage-site motifs, 5β²-end sequence patterns, genome-wide bin counts, nucleosome positioning, and more. Pre-trained models for DNASE1L3 activity prediction, fetal-fraction estimation and UMAP-based fragmentome embedding are available separately (see Models below).
git clone https://github.com/jasperlinthorst/fragmentomics.git
cd fragmentomics
pip install .After installation the cfstats command is available on your PATH.
A reference FASTA (e.g. hg38flat.fa) is required for most subcommands; pass
it with -r / --reference.
Key dependencies (pinned in setup.py): numpy, scikit-learn, pandas, pysam,
biopython, scipy, statsmodels, plotly, huggingface_hub.
# Fragment size distribution (paired-end data)
cfstats fszd -r hg38.fa sample.cram
# Cleavage-site motifs (4-mer, normalised to frequencies)
cfstats csm -r hg38.fa --norm freq sample.cram
# 5β²-end k-mer patterns
cfstats 5pends -r hg38.fa sample.cram
# Genome-wide bin counts (1 Mb bins)
cfstats bincounts -r hg38.fa -b 1000000 sample.cram
# DNASE1L3 prediction via remote API
cfstats dnase1l3 --hf-token $HF_TOKEN -r hg38.fa sample.cram
# Fetal fraction estimation via remote API
cfstats ff --hf-token $HF_TOKEN -r hg38.fa sample.cramPrediction models are available through the Hugging Face Hub and can be accessed through an access token (the --hf-token flag). Contact j.linthorst@amsterdamumc.nl to get access.
A demo of the models is available at https://huggingface.co/spaces/jasperlinthorst/cfstats-demo.
These flags apply to all subcommands:
| Flag | Description | Default |
|---|---|---|
-r, --reference |
Reference FASTA (required for CRAM and reference-dependent features) | β |
-F |
SAM exclusion flag (like samtools -F) |
3852 |
-f |
SAM required flag (like samtools -f) |
β |
-q |
Minimum mapping quality | 60 |
-o |
Limit to n observations (subsampling) | all |
--norm |
Normalisation: counts, freq, or rpx |
counts |
-x |
RPX normalisation unit | 1 000 000 |
--nproc |
Parallel processes | 1 |
--header |
Print a header line with feature names | off |
--noname |
Omit sample name prefix | off |
--seed |
Random seed | 42 |
--loglevel |
Logging verbosity | WARNING |
Extract the distribution of fragment sizes (paired-end data only).
cfstats fszd -r hg38.fa sample.cram
cfstats fszd -r hg38.fa --norm freq -l 60 -u 600 sample.cram
cfstats fszd --bamlist samples.txt -r hg38.fa --nproc 4| Flag | Description | Default |
|---|---|---|
-l, --lower |
Minimum fragment length | 60 |
-u, --upper |
Maximum fragment length | 1000 |
--noinsert |
Infer size from sequence (long-read / unpaired) | off |
--bamlist |
File with one BAM/CRAM path per line | β |
Extract k-length motifs at the 5β² cleavage sites using the reference sequence.
cfstats csm -r hg38.fa sample.cram
cfstats csm -r hg38.fa -k 6 --norm freq sample.cram
cfstats csm -r hg38.fa --pp sample.cram # purine/pyrimidine collapse| Flag | Description | Default |
|---|---|---|
-k |
Motif length | 4 |
--pp |
Collapse to purine/pyrimidine | off |
Same as csm, but stratified by fragment size.
cfstats csmbsz -r hg38.fa -l 60 -u 600 sample.cramAdditional flags: -l, -u, --noinsert (see fszd).
Extract k-mer frequencies at the 5β² ends of fragments.
cfstats 5pends -r hg38.fa sample.cram
cfstats 5pends -r hg38.fa --useref -k 6 sample.cram| Flag | Description | Default |
|---|---|---|
-k |
Pattern length | 4 |
--useref |
Use reference instead of read sequence | off |
--uselexsmallest |
Count only the lexicographically smallest k-mer | off |
Same as 5pends, but stratified by fragment size.
cfstats 5pendsbsz -r hg38.fa -l 60 -u 600 sample.cramCount reads in fixed-size genomic bins.
cfstats bincounts -r hg38.fa sample.cram
cfstats bincounts -r hg38.fa -b 50000 --gccorrect sample.cram
cfstats bincounts -r hg38.fa --bamlist samples.txt --nproc 8| Flag | Description | Default |
|---|---|---|
-b, --binsize |
Bin size (bp) | 1 000 000 |
--gccorrect |
Apply GC-content correction | off |
--frac |
LOESS smoothing fraction for GC correction | 0.5 |
--bamlist |
File with one BAM/CRAM path per line | β |
Compute the ratio of short-to-long fragments per genomic bin (inspired by Cristiano et al., Nature 2019).
cfstats delfi -r hg38.fa -b 1000000 sample.cram| Flag | Description | Default |
|---|---|---|
--short-lower / --short-upper |
Short fragment range | 100β150 |
--long-lower / --long-upper |
Long fragment range | 150β200 |
Predict DNASE1L3 nuclease activity from fragmentomic features (SVC classifier).
# Using the remote API (recommended β no local model needed):
cfstats dnase1l3 --hf-token $HF_TOKEN -r hg38.fa sample.cram
# Using a local model file:
cfstats dnase1l3 --model SVC_all_k4.joblib --confirm-licence -r hg38.fa sample.cram| Flag | Description | Default |
|---|---|---|
--hf-token |
HF API token β use remote API instead of local model | β |
--model |
Path to local model file | bundled |
--confirm-licence |
Accept research-only licence non-interactively | off |
Estimate the fetal fraction from bin-count profiles.
# Using the remote API:
cfstats ff --hf-token $HF_TOKEN -r hg38.fa sample.cram
# Using a local model file:
cfstats ff --model ffpredictor_50kautosomalbins.pickle --confirm-licence -r hg38.fa sample.cram| Flag | Description | Default |
|---|---|---|
--hf-token |
HF API token β use remote API | β |
--model |
Path to local model file | bundled |
--confirm-licence |
Accept research-only licence non-interactively | off |
Call chromosomal gains/deletions relative to a reference cohort.
cfstats nipt reference_bincounts.tsv -r hg38.fa sample.cram --ff 0.10| Flag | Description | Default |
|---|---|---|
--ff |
Assumed fetal fraction | 0.10 |
-b |
Bin size | 1 000 000 |
--gccorrect |
GC correction | off |
Extract Fourier-transformed coverage across gene bodies (Snyder et al., Cell 2016).
cfstats fourier -r hg38.fa genes.gff sample.cramCall nucleosome positions from Windowed Protection Scores.
cfstats nucs -r hg38.fa sample.cram
cfstats nucs -r hg38.fa --chrom chr22 --start 0 --end 50000000 sample.cram| Flag | Description | Default |
|---|---|---|
--chrom |
Restrict to chromosome | all |
--start / --end |
Genomic region | full chrom |
-k |
WPS window size | 120 |
--min-len / --max-len |
Fragment length filter | 120β180 |
--min-prominence |
Peak prominence threshold | 5.0 |
--min-distance |
Minimum inter-nucleosome distance | 147 |
Plot samples in the UMAP fragmentome embedding space.
cfstats plot --mapping umap_model.pkl -r hg38.fa sample.cramLaunch a web application (Dash) for interactive exploration of a fragmentome database stored in ClickHouse.
cfstats fragmentome --ch-host localhost --ch-port 8123
cfstats fragmentome --hf-token $HF_TOKEN # use remote UMAP API for uploadsPre-trained models for dnase1l3, ff, and the UMAP fragmentome embedding are
not included in this repository. They are hosted privately and available
under a research-only licence (see cfstats/models/LICENSE).
There are two ways to use the models:
The models are served via a private Hugging Face Space. Pass --hf-token to any
model-dependent subcommand and inference runs server-side β no local model files
or GPU needed.
export HF_TOKEN="hf_..."
cfstats dnase1l3 --hf-token $HF_TOKEN -r hg38.fa sample.cram
cfstats ff --hf-token $HF_TOKEN -r hg38.fa sample.cramTo obtain an API token, contact the author (see below).
If you have received the model files directly from the author, point --model
to the file:
cfstats dnase1l3 --model /path/to/SVC_all_k4.joblib --confirm-licence -r hg38.fa sample.cram
cfstats ff --model /path/to/ffpredictor_50kautosomalbins.pickle --confirm-licence -r hg38.fa sample.cramYou will be asked to accept the research-only licence interactively (use
--confirm-licence to skip in scripts).
# Fragment size distribution (frequencies)
cfstats fszd --norm freq -r hg38.fa sample.cram > sample.fszd.tsv
# Cleavage-site motifs (frequencies)
cfstats csm --norm freq -r hg38.fa sample.cram > sample.csm.tsv
# 5β²-end patterns (frequencies)
cfstats 5pends --norm freq -r hg38.fa sample.cram > sample.5pends.tsv
# Bin counts (50 kb bins, for fetal fraction)
cfstats bincounts -r hg38.fa -b 50000 -q 1 -F 1024 sample.cram > sample.bincounts.tsv# Create a file list
ls /data/crams/*.cram > samples.txt
# Extract fragment size distributions for all samples (8 threads)
cfstats fszd --bamlist samples.txt --nproc 8 --norm freq -r hg38.fa > all.fszd.tsv# DNASE1L3 activity (remote API)
cfstats dnase1l3 --hf-token $HF_TOKEN -r hg38.fa sample.cram
# Fetal fraction (remote API)
cfstats ff --hf-token $HF_TOKEN -r hg38.fa sample.cramcfstats/
βββ __main__.py # CLI entry point and argument parsing
βββ fszd.py # Fragment size distribution
βββ csm.py # Cleavage-site motifs
βββ fpends.py # 5β²-end sequence patterns
βββ bincounts.py # Genome-wide bin counts
βββ delfi.py # DELFI-like short/long ratio
βββ dnase1l3.py # DNASE1L3 prediction logic
βββ ff.py # Fetal fraction estimation
βββ nipt.py # NIPT aneuploidy screening
βββ ft.py # Fourier-transformed coverage
βββ nucs.py # Nucleosome calling (WPS)
βββ fragmentome.py # Interactive Dash explorer
βββ db.py # ClickHouse database layer
βββ utils.py # Shared utilities
βββ models/
βββ __init__.py # Model loading + remote API helpers
βββ LICENSE # Research-only model licence
All source code is released under the MIT License.
Trained models are provided strictly for non-commercial, academic, and
research purposes. See cfstats/models/LICENSE for
full terms. For commercial or clinical licensing enquiries, contact the author.
Jasper Linthorst β jasper.linthorst@gmail.com
- Model files and API tokens are available on request for research purposes.
- For commercial licensing, please get in touch.