GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • Getting started
  • Guides
  • Inspect and export
  • Subset and split
  • Concatenate
  • Change dtype, layout or density
  • Convert formats
  • Pipelines and containers
  • Reference
  • Commands
  • Formats
  • 10x Genomics HDF5
  • CellBender

This view

  • Original page
  • New address

GeezerVison is showing cellgeni.github.io — Developers

Developers

  1. Setting up
  2. Repository layout
  3. The layers
    1. Adding a format to convert
  4. Rules the code relies on
  5. Tests
  6. The documentation site
  7. Benchmarks
  8. Releases

Setting up

git clone https://github.com/cellgeni/adata-cli.git
cd adata-cli
uv sync --extra dev
uv run adata --help
uv run pytest -m "not integration"     # the unit suite CI gates on, a few minutes

The tool itself depends on h5py, zarr, numcodecs, numpy, Pillow, Typer and Rich; the pickle extra adds pandas and scipy, and the spatial extra pyarrow. A module src/adata imports gets a line in pyproject.toml, with a floor: CI’s floors job installs each direct dependency at its floor and runs the unit suite on them. anndata, pandas, scipy and pyarrow come with the dev extra, as the reference the tests check against; scanpy, loompy, mudata and older anndata releases are installed by the integration tests in environments of their own.

Repository layout

Path Contents
src/adata/cli.py The Typer app: every command’s options and help, and errors turned into Error: and exit code 1
src/adata/commands/ One module per command: planning, refusals, progress, staging the outputs
src/adata/core/ The streaming algorithms: the subset fan-out writer, on-disk concat, recast and its out-of-core transpose, the CSR bucket builder, the query language
src/adata/elements/ The AnnData on-disk spec: encodings, readers for every layout since anndata 0.7, writers of the current one
src/adata/storage/ One interface over h5py and zarr
src/adata/conversion/ adata convert: one module per format, through AnnData
src/adata/formats/ The file types of export and import: npy, Matrix Market, CSV, JSON, images, and the check of an element’s kind and dimensions before an import writes it; what the converters read: Parquet, GeoJSON polygons, pycisTopic’s pickles; and pandas frames written as anndata writes them
src/adata/util/ Output staging, path checks, names, and literal for putting a value into Rich markup
tests/ The test suite; Testing describes it
benchmarks/ The comparative benchmark against anndata and scanpy
docs/ This site
Dockerfile The image published to quay.io/cellgeni/adata-cli
.github/workflows/ Tests, PyPI publishing, the image, the benchmark
AGENTS.md The same ground as this page, written for coding agents
STATUS.md What is released, in progress and next

The layers

Each layer calls only those below it:

cli.py ──► commands/ ──► core/, conversion/, formats/ ──► elements/ ──► storage/

The one exception: storage/ uses elements/ (the spec, strings, and the readers and writers that copy_tree and create_dataset need to copy an element faithfully).

  • cli.py parses options and checks cheap things such as --zarr-format. Its console writes to stderr; only data and out_console go to stdout, which is what lets output pipe cleanly. Off a terminal, in a log file or a pipe, neither writes colour, cursor or spinner codes, and a message on stderr stays on one line. raise _fail(e) turns an exception into that line, Error: ..., and exit code 1. main(argv) runs the arguments it is given and raises SystemExit for the caller; run as the command, a failed run ends the process at once. --chunk and --no-space-check are defined once, as _chunk_option and _space_check_option; a new command reuses them.
  • commands/ orchestrates one command: what to read, what to refuse, what to write where, and which Zarr version.
  • core/ holds the algorithms that stream. subset.py’s writer serves subset and split, and reads each matrix once for every output. csr_build.py builds CSR from entries in any order through row-range buckets on disk; the transpose and every out-of-order reader use it. scatter.py does the same for the rows of a table that comes in another order than the matrix beside it.
  • elements/spec.py is the single source of truth for encoding-type and encoding-version. read.py accepts every layout from anndata 0.7 on; write.py always writes the current one; strings.py reconciles how HDF5 and Zarr spell text.
  • storage/ hides the backend. open_store(path, mode, zarr_format=...) returns a Store; use its is_group, is_dataset, create_dataset and copy_tree rather than branching on h5py or zarr.

Adding a format to convert

AnnData is the hub, so a format needs an importer, an exporter or both, never a converter to another format.

  1. Add a Format to FORMATS in conversion/__init__.py, with a content sniffer. The first sniffer to match wins, so a specific format (cellbender, which is also a 10x matrix) goes before a general one, and the folder formats (visium, xenium) go before 10x-mtx, which would otherwise claim their MEX subfolders.
  2. Write the converter module; tenx.py is the model, and features.py holds the feature table every 10x-style format shares. A format that pairs a 10x matrix with a table (visium.py, xenium.py) uses spatial.py to match the table to the matrix’s barcodes and write it in their order, and to read the analysis/ folder Xenium and Space Ranger (spots, bins and cells) share.
  3. Add fixtures shaped like the real tool’s output to tests/conftest.py, and a comparison against the reader people use in tests/test_external_readers.py.
  4. Give it a page under docs/reference/formats/ and a row in the tables on the formats index and the convert section of Commands.

Rules the code relies on

None of these fails a test at once when broken, so they are worth knowing before changing anything that writes:

  • Never write a store in place. Every write goes through util/staging.staged_outputs: write to out.adata-tmp.<ext>, move an existing output aside to out.adata-old.<ext>, rename into place, then delete the old one. It refuses to start over leftovers (naming them all), claims each output with a lock file (out.h5ad.adata-lock, taken over when its process is dead on this host) so two runs cannot write one output, follows an output that is a symlink, turns SIGTERM and SIGHUP into its cleanup, and syncs a replacement and gives it the old output’s mode and group before the old one goes. With --inplace the source is the output, so open it inside the staging block, where it is closed before being renamed aside.
  • Store.close raises. A failed HDF5 flush or Zarr consolidation leaves an incomplete store; raising it is what lets staging discard it. It stays quiet only while another exception propagates.
  • Check the output before opening anything, with util/path.output_target (for commands with --inplace) or check_output. One check for every writer: the output may not be the input under any alias (hard links and case-only aliases included), lie inside a Zarr input, or be a folder or non-HDF5 file that a store would replace; and --inplace with -o is refused. A symlinked --inplace source is followed, so the link survives. Opening a Zarr output for writing empties the directory being read.
  • Check free space before writing a large HDF5 store, with util/staging.check_free_space, giving the estimate as a function so a Zarr output never measures the source. A full disk part way through an HDF5 write can abort inside the library, past any cleanup. --no-space-check skips it.
  • Validate before the output exists. Resolve selections, check casts and plan, so that a refusal writes nothing. An empty selection is a refusal, not an empty store. What only the data can show, such as an index out of range, refuses during the write, and staging keeps the output from appearing.
  • Escape what the store or the user wrote before Rich prints it. Rich reads [word] as a style tag: printed as it is, pct_counts[mt] shows as pct_counts, and [/x] crashes the command. Names, labels, paths and attribute values go through util/markup.literal in every message, status line, progress description and tree label; it escapes as rich.markup.escape does, but a trailing backslash prints once whatever follows. Never write brackets around a value in a template: a value with an unclosed [ closes into a tag there. Help text is markup too, so a literal [ in a docstring is written \\[.
  • Zarr outputs keep the source’s version. Pass zarr_format= to open_store; without it zarr-python writes v3, upgrading a v2 input. concat uses the version its Zarr inputs share.
  • Outputs keep the source’s index dtypes, chunking and compression. Changing them is recast’s job, or an explicit flag’s. Zarr v3 shards are kept too: fit_chunks clamps them with the chunk, and given itemsize cuts a unit too large to hold along its rows.
  • A streamed output is written through storage.RowWriter, flushed after the last block. A write to part of a Zarr shard rewrites the whole shard, and Zarr keeps no chunk cache, so a --chunk block written straight into the array costs a whole unit a block.
  • Memory is set by --chunk. Loading a whole matrix or column is a regression unless it is behind an explicit --in-memory. --chunk is defined once in cli.py (_chunk_option, with min=1); reuse it.
  • A writable Zarr store rewrites its consolidated metadata on close. anndata trusts that index, and new members are invisible without it.

Tests

  • Every backend in one test body. tests/conftest.py::new_store is parametrised over h5ad, zarr2 and zarr3.
  • An oracle, not self-consistency. anndata reads back what is written, scipy checks recast, scanpy, loompy and mudata check the conversions. test_anndata_versions.py builds environments with anndata 0.7.8 to 0.13, pinned exactly, and checks both directions: each release’s store is read, and from 0.8 the release reads back subset, convert, split and concat outputs.
  • Complexity guards that count, not time. tests/test_performance.py counts the elements and bytes read through hooks on h5py and zarr. A change that adds reads per row or per group fails it on any machine. The same hooks (tests/perf_counters.py) count the largest read, which is the block a loop holds, and the whole chunks and shards each read decodes and each write encodes.
  • Memory measured as a share of the input. perf_counters.peak_rss runs adata in a fresh interpreter and returns the peak memory it added; the memory guards grow a store along n_obs and n_var, built by tests/perf_fixtures.py as anndata writes it (h5ad, Zarr v2 and anndata 0.13’s sharded Zarr v3), and assert the peak stays a small share of it.
  • The docs are tested. tests/test_docs_are_accurate.py checks every adata … line in the README, these pages and the --help examples against the real Click tree; that each command has a section and a contents entry in Commands and a mention in the app help; that every relative link names a page and an anchor that exist; that every page has the front matter the sidebar needs; and that every test file has a row in Testing’s map.
uv run pytest -m "not integration and not perf" --cov=adata --cov-fail-under=90  # CI's coverage job
uv run pytest -m perf                                                # the cost guards, CI's own job
ADATA_REQUIRE_VERSION_FIXTURES=1 uv run pytest tests/test_anndata_versions.py -m integration

integration tests need the network on their first run, to build their environments. CI runs the unit suite on Python 3.12 and 3.13 and again at each dependency’s floor, the cost guards, the anndata-release and external-reader tests as jobs of their own, a lint of the workflows and a build and smoke test of the image. It also installs the package alone from a fresh resolution, without the lock, imports every module and runs convert, so a module-level import of something undeclared fails there. Don’t import click, which typer 0.26 and later no longer install. House style: test names read as sentences, a regression test’s docstring says what used to go wrong, and comments say why. No linter or formatter runs on the code (CI lints only the workflows); match the code around you.

Testing has the detail: what each file covers, what the guards count and why, and the anndata releases checked.

The documentation site

The site is Just the Docs, built by GitHub Pages from docs/ on main. Each page needs title and nav_order front matter, and parent (and grand_parent under Formats) to sit in the sidebar. Link between pages as page.md, relative to the page; anything else needs an absolute URL, since pages are served at /page/. A page that moves keeps its old URL with redirect_from.

To preview it, with Ruby and Bundler:

cd docs
bundle install
bundle exec jekyll serve      # http://localhost:4000/adata-cli/

The benchmark page, reference/benchmarks.md, is generated: edit benchmarks/page_template.md instead.

Benchmarks

uv run python -m benchmarks.run --tier smoke --case concat-inner --out results.json
uv run python -m benchmarks.report results.json

The Benchmark workflow runs the ci tier on every tag and commits the results to Benchmarks and docs/benchmarks/<tag>.json. It reports and never gates; the complexity guards gate.

Releases

  1. Branch release/X.Y.Z.
  2. Set the version in pyproject.toml and in the pyadata-cli entry of uv.lock.
  3. Add a ## X.Y.Z section at the top of docs/changelog.md: a summary paragraph, then whichever of ### Added, ### Changed and ### Fixed apply, each entry led by a bold line and an issue link.
  4. Merge, then push a tag with no v prefix. The tag runs publish.yml, which checks the tag against pyproject.toml and docs/changelog.md, tests (tests.yml, including a build and smoke test of the image), publishes to PyPI. Then, side by side, it calls quay-on-tag.yml to build the image, check that it runs, and push that image, and creates the GitHub release from the changelog section. If the tests fail or a check does not pass, nothing is published. :latest moves only to the highest X.Y.Z tag. Don’t create the release by hand. The tag also runs benchmark.yml (the benchmark page, which it also appends to the release notes), whose measuring job has a read-only token; the job that commits the results installs nothing.

A manual Publish dispatch to TestPyPI publishes there alone, from any ref; one to PyPI publishes, pushes the image and creates the release, only when run from a tag, and fails from a branch. Workflows pin third-party actions by commit SHA, with the version in a comment, and pass tags and inputs to scripts through env:. tests/test_release_pipeline.py and the workflow lint job check both.

h5ad as a command name, info and convert with recast’s flags are deprecated and stay until 1.0.0.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.