Skip to main content

ccnv

PyPI Version install with bioconda Bioconda Version DOI

ccnv is a Python 3.12+ toolkit (backed by a compiled Rust core) for copy-number variation (CNV) detection in whole-genome sequencing (WGS) data at any coverage, building on within-sample reference normalization (Straver et al., Nucleic Acids Research, 2014; Raman et al., Nucleic Acids Research, 2019).

Full documentation, architecture diagrams, and method details live at https://matthdsm.github.io/ccnv/.


How It Works

WGS read depth fluctuates across chromosomes even in diploid samples: GC-rich and AT-rich regions amplify unevenly, repetitive regions lose uniquely mapped reads, and each library carries its own fragment-length, DNA extraction, and sequencing batch effects. Comparing a test sample only against a static control average leaves sample-specific "genomic waves" behind whenever a new library differs slightly from the training panel.

ccnv solves this with two complementary normalization steps. First, between-sample modeling removes library-level GC, mappability, fragment-size, and cohort batch trends learned from normal controls. Second, within-sample normalization groups genomic windows that co-vary across controls into prototype sets on other chromosomes. Each window in a test sample is then scored against its matched off-chromosome prototypes in that same sample, canceling sample-specific technical waves while preventing a gain or loss on one chromosome from biasing its own baseline.

flowchart LR
    A["BAM / CRAM Reads"] -->|"1. ccnv extract"| B["Binned Sample (.ccnv)"]
    C["Control Samples or FASTA"] -->|"2. ccnv reference"| D["Reference Model (.ccnv)"]
    D -->|"3. ccnv ref-qc"| E["Usability Verdict (PASS / WARN / FAIL)"]
    B -->|"4. ccnv predict"| F["CNV Calls (BED.gz, VCF.gz, QC.json, HTML Plot)"]
    D -->|"4. ccnv predict"| F

Pipeline Stages

  1. ccnv extract — Alignment Streaming & Fragment Profiling: Reads a BAM or CRAM file once (in parallel genomic tiles when indexed, or sequentially on one thread without an index) and drops unmapped, secondary, supplementary, duplicate, and MAPQ = 0 reads. Proper read pairs are binned by fragment midpoint (5 kb windows by default) so reads spanning a bin edge are never counted twice; single-end reads are binned by 5' start coordinate. For paired-end data, it also stores per-bin fragment-length bands, short-fragment counts, fragment GC, and sample-wide insert-size and 5' motif counts in a compact .ccnv Parquet file. Contig names and lengths come directly from the alignment header, so ccnv works on any genome build or species and can coarsen finer .ccnv files automatically in memory when window sizes differ.
  2. ccnv reference — Cohort Modeling & Baseline Construction: Builds a reusable .ccnv reference from control .ccnv files listed in a YAML or JSON samplesheet. It scales library depths across 1 Mb blocks using median ratios (so an unexpected trisomy in a control cannot skew total depth), masks gap-heavy (N-rich) and low-mappability bins from optional FASTA and BigWig tracks, and regresses out GC, mappability, and fragment-length biases without dropping zero-count bins. It then separates autosomal, female_sex, and male_sex branches from X/Y dosage (setting sex-chromosome outliers aside), captures cohort batch waves via PCA, links each bin to off-chromosome prototype sets, and splits random low-coverage Poisson noise from repeatable biological variability so the model works across sequencing depths. Without a control cohort, --fasta builds a sequence-only flat germline reference.
  3. ccnv ref-qc — Reference Usability Audit: Audits a reference .ccnv model before use by checking unmasked bin counts, prototype distance distributions across branches, and male chrY coverage. It writes structured diagnostics to <prefix>_qc.json and logs a PASS, WARN, or FAIL verdict (--fasta references report WARN because empirical cohort noise estimates are missing).
  4. ccnv predict — Projection, Segmentation & Event Calling: Normalizes a test sample (.ccnv, BAM, or CRAM) using outlier-resistant regression onto the reference PCA waves so large CNVs or trisomies cannot pull the baseline, then computes log2 ratios and per-bin precision weights against off-chromosome prototypes while iteratively masking extreme regions. Chromosomes are split across large unmappable gaps such as centromeres (> 2 Mb by default) so calls never bridge chromosome arms, segmented via linear-time PELT change-point detection, and scored with both autocorrelation-adjusted Z-scores and integer copy-number likelihoods (CN = 0, 1, 2, 3, 4+), resolving homozygous deletions (CN = 0) down to 0.1x coverage as well as high-depth 30x+ WGS. Outputs include bgzipped/indexed BED and VCF files, <prefix>_qc.json, and a self-contained offline HTML genome plot (<prefix>_plot.html) with a collapsible aberrations table and TSV export.

Analysis Modes

  • Germline Mode (--mode germline, default): Profiles constitutional, clinical, or research WGS where copy-number changes affect the entire sample. Automatically selects the female (XX) or male (XY) sex-chromosome branch (unless overridden with --sex) so autosomes and sex chromosomes are called against their expected ploidy.
  • Prenatal cfDNA Mode (--mode prenatal): Built for non-invasive prenatal testing (NIPT) from maternal plasma cell-free DNA, where placental/fetal DNA typically makes up ~4–20% of fragments and scales down fetal log2 shifts accordingly. ccnv combines four independent fetal fraction signals (male chrY coverage, genome-wide autosomal depth patterns, chrX dosage, and shorter fetal vs. longer maternal fragment lengths) into one outlier-resistant estimate, up-weights fetal-enriched fragment sizes, and normalizes chrX against the diploid XX branch plus male-fetus (fetal_sex == "M") 5 kb chrY bins against a calibrated 1-copy MSY baseline on prenatal_ffy (omitting chrY when fetal_sex == "F"). It also screens singleton sex-chromosome aneuploidies (XX, XY, XO, XXX, XXY, XYY) alongside twin sex pairs (FF, FM, MM, via --twins or automatic detection, reporting sca and twin metrics in <prefix>_qc.json), flags segments whose shift disagrees with the sample's fetal fraction, and couples read depth with fragment lengths to distinguish fetal constitutional CNVs, confined placental mosaicism, inherited CNVs, and maternal CNVs.

Installation

PyPI (pip / uv)

Pre-compiled manylinux_2_28 (x86_64, aarch64) and macOS (arm64) wheels are published to PyPI:

pip install ccnv
# or isolated CLI installation via uv:
uv tool install ccnv
ccnv --help

Bioconda

conda install -c conda-forge -c bioconda ccnv
# or using mamba / pixi global:
mamba install -c conda-forge -c bioconda ccnv
pixi global install -c conda-forge -c bioconda ccnv
ccnv --help

pip (from source)

python -m pip install .
ccnv --help

Pixi (from source)

pixi install
pixi run ccnv --help

Docker

Multi-platform container images (linux/amd64 and linux/arm64) are published to GHCR:

docker pull ghcr.io/matthdsm/ccnv:latest
docker run --rm ghcr.io/matthdsm/ccnv:latest ccnv --help

Galaxy

IUC-compatible Galaxy wrappers (ccnv_extract, ccnv_reference, ccnv_ref_qc, ccnv_predict) and ToolShed suite metadata live under galaxy/. See the CLI Reference for dataset staging and workflow output details.


Quickstart

# 1. Extract BAM or CRAM alignments into binned sample Parquet (.ccnv)
ccnv extract sample.bam --prefix sample --bin-size 5000

# 2a. Build a germline reference model from a cohort samplesheet
ccnv reference -s cohort.yaml --prefix reference --bin-size 5000 --gc genome.fa --mappability mappability.bw

# 2b. Or build a flat uniform-depth germline reference from a FASTA
ccnv reference --fasta genome.fa --prefix reference --bin-size 5000 --mappability mappability.bw

# 2c. Or build a unified prenatal reference from a maternal cfDNA cohort samplesheet
ccnv reference -s cohort.yaml --mode prenatal --prefix prenatal_ref --bin-size 5000

# 3. Audit reference quality control metrics
ccnv ref-qc reference.ccnv

# 4a. Predict copy-number gains and losses from .ccnv, .bam, or .cram (with --fasta)
ccnv predict sample.ccnv reference.ccnv --prefix results/sample

# 4b. Or run prenatal prediction with fetal fraction estimation and sex chromosome analysis
ccnv predict sample.ccnv prenatal_ref.ccnv --mode prenatal --prefix results/sample_prenatal

Outputs include bgzipped/indexed BED tables, VCFv4.2 files, self-contained offline Plotly HTML reports (_plot.html, including an interactive aberrations table and TSV export), and structured JSON metrics (<prefix>_qc.json).


Documentation

Visit the documentation site for detailed guides:

  • Pipeline Architecture: 4-stage execution model and storage contracts.
  • CLI Reference: Flag specification, inputs, outputs, and exit codes.
  • Visualization Overview: Self-contained offline HTML genome viewer tracks, clinical gene annotations and bundled catalog provenance, aberrations table, TSV export, controls, and color legends.
  • API Reference: Module-by-module function reference and call-graph DAGs.
  • Mathematical Methodology: Statistical models, assumptions, and citations.

Development & Verification

pixi run format      # Format code with Ruff
pixi run lint        # Lint code with Ruff
pixi run test        # Run unit & contract test suite
pixi run hooks       # Run pre-commit hooks with Prek
pixi run docs-build  # Build documentation site with Zensical
pixi run docs-serve  # Serve documentation site locally

All changes must be submitted via pull request and recorded in CHANGELOG.md.


License

Licensed under the GNU Affero General Public License v3 or later (AGPL-3.0-or-later). See LICENSE.md.

Metadata

Release files for ccnv 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ccnv 1.2.0
File Size Uploaded Provenance Actions
ccnv-1.2.0.tar.gz 997.3 kB With provenance Details for ccnv-1.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ccnv 1.2.0
File Interpreter ABI Platform Actions
ccnv-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for ccnv-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl
ccnv-1.2.0-cp312-abi3-manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64 Details for ccnv-1.2.0-cp312-abi3-manylinux_2_28_aarch64.whl
ccnv-1.2.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for ccnv-1.2.0-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 6.8 MB

Release files / ccnv-1.2.0.tar.gz

Download URL ccnv-1.2.0.tar.gz
Size 997.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dedd4ae556939efb0defd61db3e3ce9be3daad6c05f0f0db2aeded43c3e0dcce
BLAKE2b-256 checksum
How to use checksums
df9df06da815ed3b521943fd058d81a455ba6e7ef0c66c41c374ff150c120975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / ccnv-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL ccnv-1.2.0-cp312-abi3-manylinux_2_28_x86_64.whl
Size 2.0 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
271f0e3c0ace5e5a92194e04bfcce17228da15d6fa0cc2bf15e9950ebdb9141a
BLAKE2b-256 checksum
How to use checksums
7a000004049570601cdcf83571cec7f2501de379cb9e12a0d26550ca790d4758
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / ccnv-1.2.0-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL ccnv-1.2.0-cp312-abi3-manylinux_2_28_aarch64.whl
Size 2.0 MB
Tags CPython 3.12 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
84c6c9facc62f1e3ffd7222684fbf7a896cd476bbc27693b2f4c2b13f890dfb2
BLAKE2b-256 checksum
How to use checksums
e985808198393428f32d500d07609fcb1f3280f94f1853f5e18e5a635714f780
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / ccnv-1.2.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL ccnv-1.2.0-cp312-abi3-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c0c03fc332332c5a3d78cdd02e50b8fdd8612f4e7970e51fecd75bd12f32242d
BLAKE2b-256 checksum
How to use checksums
2577fbcfd63aa5bc4a2bc63354874d0626574a64e51bc42275c93a50a41fc347
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for ccnv 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for ccnv-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.0 This release

4 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page