# Outputs Overview

This section is the single canonical reference for every file produced by `ccnv` across all four pipeline stages (`extract`, `reference`, `ref-qc`, and `predict`), including [QC Reports & MultiQC](qc-reports.md) and the [Interactive HTML Genome Viewer](visualization.md).

Commands accept `--prefix` and append canonical suffixes automatically; omit file extensions in `--prefix`.

## Output Files by Stage

| Stage | Artifact | Controlling Flag | Description |
| :--- | :--- | :--- | :--- |
| `extract` | `<prefix>.ccnv` | always | Zstandard-compressed Schema `2.0.0` sample Parquet with binned counts, fragmentomic channels, and header metadata. |
| `extract` | `<prefix>.ccnv.extract_qc.json` | always | MultiQC-compatible stage QC report with read filter counters, fragmentomics, and `"run"` provenance ([QC Reports](qc-reports.md#extract)). |
| `reference` | `<prefix>.ccnv` | always | Zstandard-compressed Schema `2.0.0` reference Parquet with branch models, PCA loadings, prototypes, and optional prenatal models. |
| `reference` | `<prefix>.ccnv.reference_qc.json` | `--qc-report` (default) | MultiQC-compatible reference audit report with branch verdicts and `"run"` provenance; disable with `--no-qc-report` ([QC Reports](qc-reports.md#reference--ref-qc)). |
| `ref-qc` | `<prefix>.ccnv.ref_qc.json` | always | MultiQC-compatible standalone reference usability audit (`PASS`, `WARN`, `FAIL`) and `"run"` provenance ([QC Reports](qc-reports.md#reference--ref-qc)). |
| `predict` | `<prefix>_bins.bed.gz` (+ `.tbi`/`.csi`) | always | Per-bin normalized $\log_2$ ratios, Z-scores, precision weights, reference counts, mask status, and branch. |
| `predict` | `<prefix>_segments.bed.gz` (+ `.tbi`/`.csi`) | always | Segmented intervals with weighted $\log_2$ ratios, Z-scores, weights, bin counts, calls, and prenatal annotations. |
| `predict` | `<prefix>_calls.bed.gz` (+ `.tbi`/`.csi`) | always | Called `gain` and `loss` segments only (plus prenatal annotations when `--mode prenatal`). |
| `predict` | `<prefix>_segments.vcf.gz` (+ `.tbi`/`.csi`) | `--vcf` (default) | VCFv4.2 structural variant records for all segments; disable with `--no-vcf`. |
| `predict` | `<prefix>_calls.vcf.gz` (+ `.tbi`/`.csi`) | `--vcf` (default) | VCFv4.2 `<DUP>` and `<DEL>` records for called aberrations only; disable with `--no-vcf`. |
| `predict` | `<prefix>_bins.vcf.gz` (+ `.tbi`/`.csi`) | `--bins-vcf` (opt-in) | Per-bin VCFv4.2 records (only emitted when both `--vcf` and `--bins-vcf` are enabled). |
| `predict` | `<prefix>.ccnv.predict_qc.json` | always | MultiQC-compatible prediction QC report covering read accounting, CNV counts, fragmentomics, prenatal diagnostics, and `"run"` provenance ([QC Reports](qc-reports.md#predict)). |
| `predict` | `<prefix>_plot.html` | `--plot` (default) | Self-contained offline Plotly WebGL genome viewer with cytobands, clinical genes, aberrations table, and `<sample>_aberrations.tsv` export; disable with `--no-plot` ([Visualization](visualization.md)). |

## Coordinates, Sorting & Indexing

- **0-Based Half-Open Coordinates**: All internal bins, `.ccnv` Parquet tables, and BED deliverables use 0-based half-open `[start, end)` intervals. VCFv4.2 deliverables use 1-based closed coordinates per the VCFv4.2 specification.
- **Natural Contig Ordering**: Output records in BED, VCF, and HTML reports follow natural contig sort order (`chr1`–`chr22`, `chrX`, `chrY`, or organism-specific header contigs). Sample `.ccnv` Parquet files preserve exact alignment header contig order and partial final bin bounds.
- **Single-Pass BGZF & Automatic `.tbi` / `.csi` Indexing**: BED and VCF files are written in a single streaming pass via the compiled Rust `ccnv._core` writer (`noodles-bgzf`, `noodles-tabix`, `noodles-csi`). Standard Tabix (`.tbi`) indexes are emitted by default, switching automatically to `.csi` whenever any contig exceeds $512\text{ Mb}$.

## Parquet Artifacts (`<prefix>.ccnv`)

Both sample and reference `.ccnv` files are Zstandard-compressed Apache Arrow Parquet tables adhering to Schema `2.0.0`, validated before computation without persisting internal filesystem paths or clinical patient identifiers.

### Sample Parquet (`extract`)

Sample tables store 7 coordinate-free per-bin columns; bin intervals `[start, end)` are reconstructed deterministically from `ccnv.contig_order`, `ccnv.contig_lengths`, and `ccnv.bin_size` metadata.

| Column | Arrow Type | Description |
| :--- | :--- | :--- |
| `count` | `uint32` | Total retained reads (or paired-end dyad midpoints) in the bin. |
| `paired_count` | `uint32` | Proper paired-end fragments contributing to fragmentomic sums. |
| `frag_len_sum` | `uint64` | Sum of fragment insert lengths (bp) across paired fragments in the bin. |
| `short_frag_count` | `uint32` | Paired fragments with insert length in $[80, 150]\text{ bp}$. |
| `endpoint_count` | `uint32` | Fragment endpoint count falling inside the bin. |
| `frag_gc_sum` | `float32` | Sum of fragment GC fractions across paired fragments in the bin. |
| `frag_bands` | `list<uint32>[24]` | Counts across 24 fixed-edge variable-width (`20 bp`, `10 bp`, `50 bp`, `201 bp`) fragment length bands. |

JSON-encoded Parquet schema metadata records `ccnv.artifact_kind` (`"sample"`), `ccnv.schema_version` (schema version `2.0.0`), `ccnv.coordinate_system`, `ccnv.contig_order`, `ccnv.contig_lengths`, `ccnv.bin_size`, `ccnv.filters`, `ccnv.qc` (target-contig effective read accounting), and `ccnv.fragmentomics` (insert-size landmarks, 571-bin fragment length histogram, and 256-element 5' 4-mer end-motif counts; dropped only after non-nested in-memory rebinning).

### Reference Parquet (`reference`)

Reference tables store 17 columns partitioned by `branch` (`autosomal`, `female_sex`, `male_sex`, plus `prenatal_autosomal` at `100 kb` and `prenatal_ffy` at `5 kb` `chrY` in `--mode prenatal`), alongside scalar prenatal hyperparameters under `ccnv.prenatal` metadata.

| Column | Arrow Type | Description |
| :--- | :--- | :--- |
| `branch` | `string` | Model branch name (`autosomal`, `female_sex`, `male_sex`, `prenatal_autosomal`, `prenatal_ffy`). |
| `contig` | `string` | Contig name matching the alignment/FASTA header. |
| `start`, `end` | `uint32` | 0-based half-open bin interval `[start, end)`. |
| `masked` | `bool` | Whether the bin is excluded due to high `N` content, low mappability, or coverage filters. |
| `gc`, `mappability` | `float32` | Reference GC fraction and mean mappability score for the bin. |
| `gc_quantiles` | `fixed_size_list<float32, 8>` | 8-quantile `200 bp` sub-bin GC profile for coarse-grid Poisson bias correction. |
| `ref_frag_len`, `ref_ep_rate` | `float32` | Cohort reference mean fragment length and endpoint rate covariates. |
| `pca_mean`, `pca_loadings` | `float32`, `list<float32>` | Cohort variance-whitened PCA baseline mean and SVHT principal component loadings. |
| `proto_ids`, `proto_weights` | `fixed_size_list<uint16, 4>`, `fixed_size_list<float16, 4>` | $k=4$ nearest off-chromosome prototype indices and normalized inverse-distance weights. |
| `mean_distance` | `float32` | Mean weighted distance to assigned prototypes (used by `ref-qc`). |
| `null_mean`, `bio_dispersion` | `float32` | Empirical Bayes (`squeeze_var`) null log-ratio offset and depth-decomposed biological dispersion. |

## BED Deliverables (`predict`)

All BED outputs are bgzipped, tab-delimited, 0-based half-open, and indexed with `.tbi` or `.csi`. In `--mode prenatal`, male-fetus (`fetal_sex == "M"`) `5 kb` clean MSY `chrY` records from `prenatal_ffy` are included alongside autosomal and `chrX` records, and omitted when `fetal_sex == "F"`.

### `<prefix>_bins.bed.gz`

| Column | Description |
| :--- | :--- |
| `#contig`, `start`, `end` | 0-based half-open bin coordinates. |
| `id` | Stable bin identifier. |
| `ratio` | Within-sample normalized $\log_2$ copy-number ratio. |
| `zscore` | Per-bin standardized Z-score. |
| `weight` | Depth-decomposed Empirical Bayes inverse-variance precision weight. |
| `reference_size` | Number of off-chromosome reference prototypes used to normalize the bin. |
| `masked` | Boolean mask flag (`true` / `false`). |
| `branch` | Reference branch applied to the bin (`autosomal`, `female_sex`, `male_sex`, or `prenatal_ffy`). |

### `<prefix>_segments.bed.gz` & `<prefix>_calls.bed.gz`

| Column | Files | Description |
| :--- | :--- | :--- |
| `#contig`, `start`, `end` | `_segments`, `_calls` | 0-based half-open segment coordinates (never bridging gaps $\gt$ `--max-blacklist-gap`). |
| `ratio` | `_segments`, `_calls` | Precision-weighted mean segment $\log_2$ ratio. |
| `zscore` | `_segments`, `_calls` | Autocorrelation-adjusted dyadic BLUE segment Z-score. |
| `weight`, `bin_count` | `_segments` | Sum of bin precision weights and unmasked bin count in the segment. |
| `call` / `type` | `_segments` (`call`), `_calls` (`type`) | Segment event call (`gain`, `loss`, or neutral/empty in `_segments`; `gain` or `loss` only in `_calls`). |
| `expected_ratio`, `implied_ff` | prenatal only | Expected fetal $\log_2$ ratio shift at `active_ff` and implied fetal fraction for the segment. |
| `discordant`, `discordance_reason` | prenatal only | Boolean discordance flag and trigger (`SCA_DISCORDANT`, `SUB_FETAL_RATIO`, or `SUPER_FETAL_RATIO`). |
| `frag_short_ratio`, `frag_llr_size` | prenatal only | Segment short-fragment ratio ($[80, 150]\text{ bp}$) and fetal-vs-maternal fragment-length log-likelihood ratio. |
| `origin_call` | prenatal only | 5-state biological origin (`FETAL_CONSTITUTIONAL`, `PLACENTAL_MOSAIC`, `MATERNAL_UNINHERITED`, `MATERNAL_AND_FETAL_INHERITED`, `MATERNAL_MOSAIC`, or `INDETERMINATE`). |

## VCFv4.2 Deliverables (`predict`)

Generated by default (`--vcf`; disable with `--no-vcf`). `_segments.vcf.gz` contains all segments, `_calls.vcf.gz` contains called gains (`<DUP>`) and losses (`<DEL>`) only, and opt-in `_bins.vcf.gz` (`--bins-vcf`) emits per-bin `<CNV>` records.

| Field / Header | Scope | Type | Description |
| :--- | :--- | :--- | :--- |
| `ALT` (`<DUP>`, `<DEL>`, `<CNV>`) | all VCFs | Symbolic ALT | Duplication (`gain`), deletion (`loss`), or neutral/bin copy-number record. |
| `FILTER` (`PASS`, `MASKED`) | all (`MASKED` on `_bins`) | Filter | `PASS` for unmasked/called records; `MASKED` for masked bins in `_bins.vcf.gz`. |
| `INFO/END`, `INFO/SVTYPE` | all VCFs | `Integer`, `String` | 1-based inclusive end coordinate and structural variant type (`DUP`, `DEL`, `CNV`). |
| `INFO/BRANCH` | `_bins` | `String` | Model branch assigned to the bin. |
| `INFO/IMPRECISE` | `_segments`, `_calls` | `Flag` | Marks bin-resolution imprecise CNV breakpoints. |
| `FORMAT/LOG2R`, `FORMAT/ZSCORE`, `FORMAT/WEIGHT` | all VCFs | `Float` | Normalized $\log_2$ ratio, Z-score, and precision weight. |
| `FORMAT/REF_SIZE` | `_bins` | `Integer` | Number of within-sample reference prototypes used. |
| `FORMAT/BINS` | `_segments`, `_calls` | `Integer` | Number of unmasked bins spanning the segment. |
| `##fetalSex`, `##fetalFraction`, `##scaCall` | prenatal `_segments`, `_calls` | Header meta | Sample-level inferred fetal sex, `active_ff`, and SCA classification. |
| `INFO/DISCORDANT`, `INFO/DISC_REASON` | prenatal `_segments`, `_calls` | `Flag`, `String` | Prenatal dosage discordance flag and reason code. |
| `INFO/FRAG_SHORT_R`, `INFO/FRAG_LLR` | prenatal `_segments`, `_calls` | `Float` | Segment short-fragment fraction and fragment-length LLR. |
| `INFO/ORIGIN`, `INFO/MOSAIC_FRAC` | prenatal `_segments`, `_calls` | `String`, `Float` | Biological origin call and inferred mosaic fraction (when mosaic). |
| `FORMAT/EXP_LOG2R`, `FORMAT/IMPLIED_FF` | prenatal `_segments`, `_calls` | `Float` | Expected fetal $\log_2$ ratio and implied fetal fraction. |

## Related Output Guides

- [QC Reports & MultiQC](qc-reports.md): MultiQC-compatible stage QC JSON schemas, verdict rules, and SHA-256 `"run"` provenance.
- [Visualization](visualization.md): Self-contained offline HTML genome viewer (`<prefix>_plot.html`), interactive controls, `<sample>_aberrations.tsv` export, color legends, and bundled GRCh38 gene track provenance.
