# Structural variant execution notes

This lesson runs Truvari 5.5.0 on twelve real HG002 benchmark records.
It constructs the comparison from controlled changes to those records.
Its scores do not measure a variant caller's performance.

## Environment

The runner uses `bti-advanced-dna:0.1.0` with a frozen `uv` project at `/opt/advanced_dna`.
The shared image recipe and lock are in `guides/dnaseq/advanced_container/`.
That build recipe is in the private companion repository.
The public bundle does not contain the image recipe.
The runner allows two CPUs and 4 GB of memory.
It denies network access.
The Python fences on the page own the analysis source.
The Python analysis requires Truvari 5.5.0, pysam 0.24.1, NumPy, and Matplotlib.

## Source data

The official GIAB directory supplies these downloads.

| File | Purpose |
|---|---|
| `HG002_SVs_Tier1_v0.6.vcf.gz` | The VCF supplies GRCh37 HG002 sequence alleles and genotypes. |
| `HG002_SVs_Tier1_noVDJorXorY_v0.6.2.bed` | The BED file supplies the corrected confident regions. |
| `README_SV_v0.6.txt` | The release notes define the benchmark and its limits. |

The exact URLs, byte counts, and SHA256 digests are in `inputs/source_manifest.json`.
The source VCF header declares GRCh37 and HG002.
The source publication is Zook and colleagues, 2020, DOI `10.1038/s41587-020-0538-8`.
The NIST GIAB FAQ permits publication with attribution to the data sources.
The lesson cites the structural benchmark publication.

The preparation script requires the downloaded files as arguments.
It selects the first six eligible insertions and six eligible deletions on chromosome 20.
Each variant is biallelic, has explicit ACGT alleles, and spans 50 to 500 changed bases.
Each record has `FILTER=PASS` and a nonreference HG002 genotype.
Each analysis window extends 100 reference bases beyond the record's reference span.
Every window must fit inside one published Tier 1 interval.
The selection rejects another PASS variant of at least 50 bases within the window plus 1,000 reference bases.

The fixture keeps the selected VCF lines unchanged, including all original metadata.
The source manifest stores their original identifiers and individual line digests.
It also stores the three prepared file digests.
The chromosome 20 Tier 1 BED retains the source coordinates.

Run this command after you download the official files into a `downloads` directory.

```bash
uv run --no-project python prepare_inputs.py \
  --vcf downloads/HG002_SVs_Tier1_v0.6.vcf.gz \
  --bed downloads/HG002_SVs_Tier1_noVDJorXorY_v0.6.2.bed \
  --readme downloads/README_SV_v0.6.txt
```

## Controlled comparison

The analysis writes reduced VCF headers with the same baseline alleles and genotypes.
It retains the original identifier in `SOURCE_ID` and uses short identifiers for result inspection.
It omits the final two baseline records from the comparison.
It duplicates the third comparison record.
It substitutes every tenth inserted base in the first insertion, while retaining its anchor base.
The site labels these operations as controlled changes.

Both Truvari runs use one match per record and the same sample, size, region, and genotype filters.
They differ only in the minimum sequence score, which is 0.9 or 1.0.
The independent checker computes edit distance without Truvari or edlib.
It confirms each candidate has at most one eligible baseline record.
It checks matched identifiers, unmatched identifiers, exclusive result partitions, denominators, and all three summary metrics.
The page explains why this assignment shortcut applies only to the isolated fixture.

The first run has ten matches, one extra comparison record, and two missed baseline records.
The strict run has nine matches, two extra comparison records, and three missed baseline records.
Both runs evaluate eleven comparison records and twelve baseline records.
Genotype and phase accuracy are outside this exercise.

The sequence score follows the versioned Truvari source definition.
The page links that source and the copied MIT notice.
The allele input, fixture preparation, VCF writer, and result checks are original lesson code.

## Public downloads

Run the gate before you copy the figure or create the bundle.
This command copies the fresh results and creates the lesson bundle.

```bash
uv run --no-project python package_downloads.py
```

The ZIP contains the four inputs, the runner, the analysis, the preparation script, and these notes.
It also contains the two generated VCFs, their indexes, the change record, and the metric table.
The bundle includes the Truvari MIT notice.
