Metadata-Version: 2.4
Name: assemblytrace
Version: 1.1.0
Summary: Assembly-version compatibility, seqcol identity, reconstructable differences, annotation transfer, PROV and RO-Crate exports
Author-email: Maciej Kochanowski <maciej.kochanowski@piwet.pulawy.pl>
License-Expression: MIT
Project-URL: Homepage, https://github.com/maciejkochanowski/AssemblyTrace
Project-URL: Issues, https://github.com/maciejkochanowski/AssemblyTrace/issues
Keywords: bioinformatics,genome assembly,provenance,refget,seqcol,RO-Crate,PROV,FASTA,GFF3,annotation lift
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: biopython<2,>=1.81
Requires-Dist: pysam>=0.22; platform_system != "Windows"
Provides-Extra: bam
Requires-Dist: pysam>=0.22; extra == "bam"
Provides-Extra: validation
Requires-Dist: biopython>=1.81; extra == "validation"
Requires-Dist: scipy>=1.10; extra == "validation"
Requires-Dist: requests>=2.28; extra == "validation"
Requires-Dist: matplotlib>=3.7; extra == "validation"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: coverage>=7; extra == "test"
Dynamic: license-file

# AssemblyTrace

A genome project accumulates assembly versions (a draft, polishing rounds,
curated and renamed copies for submission) and a directory of files made from
one of them. Their metadata can be missing or inconsistent. AssemblyTrace
examines the files to answer:

1. **Which versions does the project hold, and how exactly do they differ?**
   Every FASTA receives GA4GH refget sequence-collection digests; versions are
   diffed without an external aligner, and events from resolved comparisons
   rebuild the target sequence exactly.
2. **Which versions are consistent with each file?** Annotations, proteins,
   alignments, variant calls and QC reports are assessed from reference-bound
   evidence, with separate likelihood ratios and posterior probabilities.
   Files incompatible with every candidate are flagged; insufficient evidence
   remains unresolved.
3. **Where does an annotation go in another version?** GFF3/GTF, BED and VCF
   records are moved exactly through the events of the pair.

Install from PyPI, or from a source checkout or unpacked source archive
(`python -m pip install .`):

```bash
python -m pip install assemblytrace
assemblytrace --version
assemblytrace scan /path/to/project --out-dir audit
```

The package version is `1.1.0`; the source commit and distribution hashes
identify the evaluated build. Installing an unpinned package from a public
index does not select this checkout.

Linux, macOS and Windows, Python 3.10 or newer; Biopython and, except on
Windows, pysam (MD tags of indexed BAM) are the dependencies.

## Use it in your browser

<https://maciejkochanowski.github.io/AssemblyTrace/> runs `scan` and `diff`
without installing anything: choose a project folder, several files or two
FASTA files, or try the bundled example, and download the report and all
outputs as a ZIP. Your files are read inside the browser tab by Python
compiled to WebAssembly (Pyodide) and are never uploaded. Browser memory
limits the data size, so use the command-line tool for large genomes. The page
lives in `web/` and is published by `.github/workflows/pages.yml`.

## Commands

| Command | What it does |
|---|---|
| `scan PROJECT --out-dir DIR` | versions, their differences, attribution of every file, provenance records, HTML report |
| `diff A.fa B.fa` | alignment-free events between two versions of one assembly |
| `lift FILE --from A.fa --to B.fa --output OUT` | exact transfer of GFF3/GTF, BED or VCF coordinates between versions |
| `seqcol A.fa` | GA4GH refget sequence-collection digests |
| `verify PROJECT --lock FILE` | verify pinned files; exit 2 on drift, unreadable content or incomplete verification |
| `identity`, `annotation`, `release-check`, `changes`, `paf-changes`, `normalize-indels`, `snapshot`, `capture-run`, `resolve` | single-artefact checks and provenance manifests |

## How it works

**Versions.** Every FASTA receives refget seqcol digests (identical to the
GA4GH reference implementation). Files with the same digest are one version;
files with the same sequences under other names form one content class. The
lineage of versions is taken from workflow records (shell scripts are read
with their variables and loops spelled out) or from the release you declare;
it is not guessed from sequence similarity, which places polished siblings
closer to each other than to their source. Where no record names a version's
source, the versions it can have been made from are listed.

**Differences.** Paired contigs are diffed by an anchored walk that
resynchronises on exact 40-mers; indels are left-aligned, and in tandem
arrays the anchor with the longest exact match is preferred so a unit
inserted in a satellite stays one event. A stretch with no shared anchor
within 128 kb (a rebuilt rDNA array, a large insertion) becomes one
replacement event, and the walk continues behind it; an exact inversion is
one event. A contig rotated to a new start or reverse complemented (a circular
replicon reoriented to dnaA) is oriented before the walk, contigs whose
names were swapped or reused are paired by content, and contigs merged, split
or moved between versions (scaffolding, a closed genome made from a draft) are
diffed through frames: blocks of the earlier version, between anchors unique
in both versions, joined in the order the later contig holds them. The events turn one
version into the other exactly; `curation/` holds them as VCF, ready for
`bcftools consensus`, and as BED tracks.

**Attribution.** Reads carry the sample's alleles whichever version they were
aligned to, so read sequences never decide provenance. The evidence is
reference-bound: @SQ names, lengths and M5 digests, @PG command lines,
reference bases implied by MD tags, VCF REF alleles, proteins against what
each version encodes (gene models moved exactly into every version), CDS
reading frames and QC statistics. Evidence comes in groups whose weight is
bounded (one header stated a thousand times is still one header). Version
selection and Bayes factors use likelihoods; posterior probabilities use an
equal prior mass for each content class, split among its versions. A difference
in prior mass is not evidence, and identical likelihoods stay undecided.
Content-class resolution is reported separately: the sequence content may be
resolved while its renamed versions remain indistinguishable. All probabilities
are conditional on the listed candidates and the model. Incompatible or
conflicting evidence is reported explicitly. Names, lengths and statistics fit any version of the same layout,
listed or not, so an attribution resting on them alone is never reported as
confident. Workflow records (scripts, job logs, command lines in headers,
Snakemake metadata) are checked against the content, and files linked by a
derivation are attributed jointly, so a regenerated file that broke a chain
is found.

**Lift.** Coordinates move through the events of the pair, so a feature lands
exactly where its sequence went; a feature an event touches is marked (a CDS
also with the state of its reading frame in the target), a feature inside an
exact inversion is mirrored onto the other strand, and one whose end falls in
a deleted span is reported unmapped.

**Outputs.** `report.html` (the result in plain language with what to do
next, the versions, the version of every file and the provenance of the run;
self-contained, no network access), `scan.json`, `attribution.tsv`, `events.tsv`,
`claims.tsv`, `inventory.tsv`, per lineage transition in `curation/` the
changes as VCF and BED, `prov.json` (W3C PROV-JSON),
`assemblytrace-ro-crate-metadata.json` (a detached RO-Crate 1.2 with a
Process Run Crate action) and `assemblytrace.lock.json`. A compact
`scan-summary.json` records completion independently of the audit verdict.
After path-safety checks, an incomplete marker is written before any export
is replaced; the completed record is published last. A completed scan can
correctly return `fail` and exit 2.

**Integrity.** `verify` reports `pass` only when every pinned entry can be
verified and no drift is found. Damaged or unreadable pinned content gives
`fail`; an entry without a pinned digest gives `partial` unless another
failure is present. Both `fail` and `partial` exit with code 2. The `coverage`
fields show how many pinned entries were verified. A project without an
assembly produces a controlled report with no candidate versions. Coordinate
operations reject duplicate contig identifiers, and output paths are checked
against inputs before reports and change tracks are written.

## Validation

`validation/make_example_project.py` builds a small project that the test
suite scans end to end. `validation/attribution_benchmark.py` scores
attribution on a real genome with negative controls;
`validation/attribution_real.py` scores projects whose files were made by real
tools from known versions; `validation/diff_compare.py` compares the diff with
minimap2/paftools and MUMmer dnadiff and checks that each method's changes
rebuild the later version; `validation/hg002_compare.py` compares diff and
lift with the official HG002 Q100 patches. The data, the development and
held-out sets and the results are in `docs/SPECIFICATION.md` and
`docs/VALIDATION_PROTOCOL.md`. A held-out claim applies to its named frozen
commit; rerunning a previously inspected dataset after a code change is a
regression check. File-level percentages describe those files, while
generalization to new projects requires project-level validation.

`validation/publication_tables.py` validates row-level scoring outputs and
source hashes, reconciles listed, omitted and mixed-origin denominators, and
writes JSON, CSV and Markdown tables with project/seed summaries. Optional
confidence intervals resample whole projects or seeds. It can update the
canonical manuscript's managed blocks from supplied results; the protocol
contains the reproducible command and interpretation rules.

```bash
python -m pip install -e '.[test,bam]'
python -m pytest -q
```

## Scope

AssemblyTrace does not assemble, map or polish reads, and does not say which
version is right. Attribution states what the files show; a file without
informative evidence stays unattributed. See `docs/SPECIFICATION.md` and
`docs/LIMITATIONS.md`.

MIT licence.
