Skip to Content
NotebooksAn error before compute

An error before compute

A naming mismatch caught with nothing executed. This page is rendered from a real run on every docs build — every value below was computed by the engine, not typed out. The notebook itself is ordinary Python you can download and run.

marimo edit examples/notebooks/02_an_error_before_compute.py # as a notebook python examples/notebooks/02_an_error_before_compute.py # or as a plain script

Read the source on GitHub 


2 — An error before compute

Here are two files describing the same two contigs, at the same lengths. One calls them chr1-style, the other bare. Every base agrees. Only the naming differs.

This is the class of bug that produces plausible, wrong numbers and no crash — and it is why check() runs before anything computes.

bare = lg.reference(str(fixtures / 'tiny_bare.fasta'), organism='test') aligned_prefixed = lg.alignment(str(fixtures / 'tiny_prefixed.sam'), organism='test') naming = (bare.dimension('contig_naming').value, aligned_prefixed.dimension('contig_naming').value) naming
('bare (Ensembl/NCBI style)', 'chr-prefixed (UCSC style)')
@lg.step(tool='bcftools') def call(ref: lg.Reference, aln: lg.Alignment) -> lg.Variants: return lg.sh('bcftools mpileup -f {ref} {aln} | bcftools call -mv -Oz -o {out}') problems = lg.dimension_errors('call', {'ref': bare, 'aln': aligned_prefixed})

What it says

ContigNamingError in step `call`: ref.contig_naming = bare (Ensembl/NCBI style) (from FASTA deflines: crates/ligase-core/tests/fixtures/tiny_bare.fasta) aln.contig_naming = chr-prefixed (UCSC style) (from SAM @SQ header: crates/ligase-core/tests/fixtures/tiny_prefixed.sam) The contigs are otherwise identical. Add a renaming step, or use one naming style throughout.

Three things worth noticing.

It names where each value came from — the FASTA deflines and the SAM @SQ header — so you can go and look rather than guess.

It says the contigs are otherwise identical, which tells you this is a naming problem and not the wrong genome.

And its type is ContigNamingError, not a generic error. A caller can branch on a naming mismatch without parsing English, which is what makes the v2 plan — inserting the renaming step automatically — possible at all.

Last updated on