# QC Reports & MultiQC

Every `ccnv` subcommand writes a self-identifying, stage-tagged JSON quality control and provenance report: `<prefix>.ccnv.extract_qc.json`, `<prefix>.ccnv.reference_qc.json` (disable with `--no-qc-report`), `<prefix>.ccnv.ref_qc.json`, or `<prefix>.ccnv.predict_qc.json`. Running with `--loglevel DEBUG` also prints version metadata and resolved parameters to `stderr`.

:::tip
**MultiQC Compatibility**: All stage-tagged `ccnv` QC JSON reports (`*.ccnv.extract_qc.json`, `*.ccnv.reference_qc.json`, `*.ccnv.ref_qc.json`, and `*.ccnv.predict_qc.json`) are compatible with MultiQC. Self-identifying filenames prevent collisions on shared sample prefixes and allow MultiQC to automatically discover and aggregate read accounting, fragmentomics, reference verdicts, fetal fraction metrics, and CNV summaries across runs.
:::

## Shared `"run"` Provenance & SHA-256 Fingerprints

Every stage QC JSON report embeds a `"run"` provenance object recording tool, Rust core (`ccnv._core`), and Parquet schema versions, every resolved CLI parameter (including defaults), invocation `argv`, logging verbosity, UTC start timestamp, elapsed wall-clock duration, and role-keyed input/output file fingerprints (`path`, `size_bytes`, `sha256`).

- **Disabling Checksums (`--no-checksum`)**: Preserves `path` and `size_bytes` while writing `"sha256": null` across all input and output entries.
- **Cohort Digest (`reference`)**: Cohort runs add an order-invariant aggregate `"cohort"` fingerprint (`count`, `total_size_bytes`, `sha256`) computed across all samplesheet entries.
- **Bundled Track Provenance (`predict`)**: Auto-loaded GRCh38 tracks under `--plot` appear as `"bundled:cytoBand_hg38.gz"` and `"bundled:genes_hg38.tsv.gz"` in `"run.inputs"`.
- **Primary Deliverables Only**: `"run.outputs"` records primary stage artifacts and excludes the QC JSON report itself as well as `.tbi`/`.csi` index sidecars.

```json title="run_provenance.json" expandable={16}
{
  "tool": "<string>",
  "version": "<string>",
  "core_version": "<string>",
  "schema_version": "<string>",
  "command": "<string>",
  "parameters": {
    "<param_name>": "<string | int | float | bool | list | null>"
  },
  "argv": ["<string>"],
  "loglevel": "<string>",
  "started_at": "<string>",
  "duration_s": "<float>",
  "inputs": {
    "<role>": {
      "path": "<string>",
      "size_bytes": "<int>",
      "sha256": "<string | null>"
    },
    "cohort": {
      "count": "<int>",
      "total_size_bytes": "<int>",
      "sha256": "<string | null>"
    }
  },
  "outputs": {
    "<role>": {
      "path": "<string>",
      "size_bytes": "<int>",
      "sha256": "<string | null>"
    }
  }
}
```

## `extract`

Written to `<prefix>.ccnv.extract_qc.json`. Summarizes target-contig read filter accounting, paired-end fragmentomics landmarks, and `"run"` fingerprints for `alignment`, optional `fasta`, and `sample_parquet`.

```json title="<prefix>.ccnv.extract_qc.json" expandable={16}
{
  "schema_version": "<string>",
  "sample": "<string>",
  "bin_size": "<int>",
  "paired_end": "<bool>",
  "contigs": "<int>",
  "num_bins": "<int>",
  "read_metrics": {
    "reads_seen": "<int>",
    "reads_kept": "<int>",
    "mate_dedup_skipped": "<int>",
    "reads_filtered": "<int>",
    "effective_reads_examined": "<int>",
    "effective_reads_kept": "<int>",
    "autosomal_reads_kept": "<int>",
    "sex_reads_kept": "<int>",
    "filter_unmapped": "<int>",
    "filter_no_start": "<int>",
    "filter_secondary": "<int>",
    "filter_supplementary": "<int>",
    "filter_duplicate": "<int>",
    "filter_improper_pair": "<int>",
    "filter_mapq": "<int>"
  },
  "fragmentomics": {
    "paired_end": "<bool>",
    "total_paired_fragments": "<int>",
    "chromatosome_mode_bp": "<float>",
    "core_shoulder_bp": "<float>",
    "sizing_shift_bp": "<float>",
    "self_referenced_peak_ratio": "<float>",
    "dinucleosome_fraction": "<float>",
    "high_mw_fraction": "<float>",
    "helical_10bp_amplitude": "<float>",
    "motif_diversity_score": "<float>",
    "warnings": ["<string>"]
  },
  "run": {
    "tool": "<string>",
    "version": "<string>",
    "core_version": "<string>",
    "schema_version": "<string>",
    "command": "<string>",
    "parameters": {
      "<param_name>": "<string | int | float | bool | list | null>"
    },
    "argv": ["<string>"],
    "loglevel": "<string>",
    "started_at": "<string>",
    "duration_s": "<float>",
    "inputs": {
      "alignment": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "fasta": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      }
    },
    "outputs": {
      "sample_parquet": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      }
    }
  }
}
```

## `reference` & `ref-qc`

Written to `<prefix>.ccnv.reference_qc.json` (during `ccnv reference`, unless `--no-qc-report` is set) and `<prefix>.ccnv.ref_qc.json` (during `ccnv ref-qc`). Both share the same schema covering overall usability verdict (`PASS`, `WARN`, `FAIL`), cohort sex inference diagnostics, per-branch prototype distance summaries, and an optional `"prenatal"` block for `--mode prenatal` references.

For `ccnv ref-qc`, `"run.inputs"` contains only `"reference"` and `"run.outputs"` is `{}`; for `ccnv reference`, `"run.inputs"` records `samplesheet` and aggregate `cohort` (or `fasta`) plus optional `gc`/`mappability` tracks, and `"run.outputs"` records `reference_parquet`.

```json title="<prefix>.ccnv.reference_qc.json" expandable={16}
{
  "schema_version": "<string>",
  "overall_verdict": "<string>",
  "worst_severity": "<int>",
  "messages": ["<string>"],
  "parameters": {
    "bin_size": "<int>",
    "mode": "<string>",
    "prenatal_bin_size": "<int | null>",
    "pca_components": "<int>",
    "min_ref_bins": "<int>",
    "flat": "<bool>",
    "autosomal_contigs": ["<string>"],
    "sex_contigs": ["<string>"],
    "sex_signal_contig": "<string | null>",
    "sex_cutoff": "<float | null>",
    "sex_source": "<string>",
    "gc_corrected": "<bool>",
    "mappability_corrected": "<bool>",
    "fragmentomics_corrected": "<bool>",
    "min_mappability": "<float>"
  },
  "cohort": {
    "sample_count": "<int>",
    "sample_sexes": ["<string>"],
    "sex_inference": {
      "passed": "<bool>",
      "cutoff": "<float | null>",
      "fractions": ["<float>"],
      "reason": "<string>",
      "quarantined_indices": ["<int>"]
    }
  },
  "branches": {
    "<branch>": {
      "n_bins": "<int>",
      "n_valid": "<int>",
      "n_masked": "<int>",
      "mask_pct": "<float>",
      "mean_of_means": "<float | null>",
      "std_of_means": "<float | null>",
      "n_mean_outlier": "<int>",
      "outlier_pct": "<float>",
      "n_low_refs": "<int>",
      "signal_contig_metrics": "<object | null>",
      "verdict": "<string>",
      "message": "<string>"
    }
  },
  "prenatal": {
    "usable_autosomal_bins": "<int>",
    "informative_ffy_bins": "<int>",
    "yfrac_threshold": "<float | null>",
    "female_chrx_ratio_std": "<float | null>"
  },
  "reference_path": "<string>",
  "run": {
    "tool": "<string>",
    "version": "<string>",
    "core_version": "<string>",
    "schema_version": "<string>",
    "command": "<string>",
    "parameters": {
      "<param_name>": "<string | int | float | bool | list | null>"
    },
    "argv": ["<string>"],
    "loglevel": "<string>",
    "started_at": "<string>",
    "duration_s": "<float>",
    "inputs": {
      "samplesheet": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "fasta": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "gc": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "mappability": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "cohort": {
        "count": "<int>",
        "total_size_bytes": "<int>",
        "sha256": "<string | null>"
      }
    },
    "outputs": {
      "reference_parquet": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      }
    }
  }
}
```

## `predict`

Written to `<prefix>.ccnv.predict_qc.json`. Records inferred sample `sex`, effective read accounting and $\lambda_{\text{GC}}$, `cnv_summary`, paired-end `fragmentomics` diagnostics (`WARN_HIGH_LEUKOCYTE_DNA` when `high_mw_fraction > 0.05`), `prenatal` diagnostics (`null` in germline mode; fused fetal fraction estimators, `sca`, `twin`, `origin_summary`, and analytical LODs in prenatal mode), and `"run"` provenance across all inputs and primary deliverables.

```json title="<prefix>.ccnv.predict_qc.json" expandable={18}
{
  "schema_version": "<string>",
  "mode": "<string>",
  "sample": "<string>",
  "sex": "<string | null>",
  "read_metrics": {
    "effective_reads_examined": "<int>",
    "effective_reads_kept": "<int>",
    "autosomal_reads_kept": "<int>",
    "sex_reads_kept": "<int>",
    "filter_drops": {
      "unmapped": "<int>",
      "mapq": "<int>",
      "duplicate": "<int>",
      "secondary": "<int>",
      "supplementary": "<int>",
      "improper_pair": "<int>",
      "no_start": "<int>"
    },
    "total_bins": "<int>",
    "usable_bins": "<int>",
    "masked_bins": "<int>",
    "mean_bin_count": "<float>",
    "median_bin_count": "<float>",
    "lambda_gc": "<float | null>"
  },
  "cnv_summary": {
    "total_segments": "<int>",
    "gain_calls": "<int>",
    "loss_calls": "<int>",
    "discordant_segments": "<int>"
  },
  "fragmentomics": {
    "paired_end": "<bool>",
    "total_paired_fragments": "<int>",
    "chromatosome_mode_bp": "<float>",
    "core_shoulder_bp": "<float>",
    "sizing_shift_bp": "<float>",
    "self_referenced_peak_ratio": "<float>",
    "dinucleosome_fraction": "<float>",
    "high_mw_fraction": "<float>",
    "helical_10bp_amplitude": "<float>",
    "motif_diversity_score": "<float>",
    "warnings": ["<string>"]
  },
  "prenatal": {
    "fetal_sex": "<string>",
    "gestation": "<string>",
    "fetal_sexes": ["<string>"],
    "male_ff": "<float | null>",
    "female_ff": "<float | null>",
    "twin_confidence": "<float | null>",
    "active_ff": "<float>",
    "effective_ff": "<float>",
    "active_ff_se": "<float | null>",
    "active_ff_source": "<string>",
    "ffy": "<float | null>",
    "ffx": "<float | null>",
    "ffa": "<float | null>",
    "ff_size": "<float | null>",
    "chrx_ratio": "<float | null>",
    "chry_score": "<float | null>",
    "yfrac_threshold": "<float | null>",
    "sca": {
      "call": "<string>",
      "is_aneuploid": "<bool>",
      "confidence": "<float>",
      "chrx_zscore": "<float | null>",
      "ff_delta": "<float | null>"
    },
    "twin": {
      "call": "<string>",
      "fetal_sexes": ["<string>"],
      "is_twin": "<bool>",
      "twin_probability": "<float>",
      "confidence": "<float>",
      "posteriors": {
        "FF": "<float>",
        "FM": "<float>",
        "MM": "<float>"
      },
      "male_ff": "<float | null>",
      "female_ff": "<float | null>"
    },
    "low_ff_warning": "<bool>",
    "warnings": ["<string>"],
    "origin_summary": {
      "<origin_call>": "<int>"
    },
    "lod_ff_35mb": "<float | null>",
    "lod_ff_3mb": "<float | null>"
  },
  "run": {
    "tool": "<string>",
    "version": "<string>",
    "core_version": "<string>",
    "schema_version": "<string>",
    "command": "<string>",
    "parameters": {
      "<param_name>": "<string | int | float | bool | list | null>"
    },
    "argv": ["<string>"],
    "loglevel": "<string>",
    "started_at": "<string>",
    "duration_s": "<float>",
    "inputs": {
      "sample": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "reference": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "fasta": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "gc": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "mappability": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "cytobands": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "genes": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      }
    },
    "outputs": {
      "bins_bed": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "segments_bed": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "calls_bed": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "bins_vcf": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "segments_vcf": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "calls_vcf": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      },
      "plot_html": {
        "path": "<string>",
        "size_bytes": "<int>",
        "sha256": "<string | null>"
      }
    }
  }
}
```
