Single-cell and spatial tables: h5ad, table, attach¶
Convert AnnData files and keyed tables to point stores, add columns with
zvtools attach, and export to h5ad or CSV. Chunk shape, --overwrite and
the export options are in Converting files.
Format |
In / out |
Extra |
Positions |
|---|---|---|---|
|
in, out |
|
an |
|
in (out as |
— |
the named |
zvtools convert cells.h5ad cells.zv --chunk-shape 500,500,500 --gene Gad1 --gene Pvalb
from zarr_vectors_tools.convert.ingest.h5ad import ingest_h5ad
ingest_h5ad("cells.h5ad", "cells.zv", (500.0, 500.0, 500.0), genes=["Gad1", "Pvalb"])
Each cell or row becomes one point. Without --spatial-key, the first of
spatial, X_spatial, spatial_fov, X_umap, X_tsne, X_pca present is
used. --chunk-shape needs one entry per position column. The viewer shows 3D
stores only.
Option |
Format |
Effect |
|---|---|---|
|
h5ad |
The |
|
h5ad |
Which of its columns to use. |
|
h5ad |
Store only these |
|
h5ad |
Store this gene’s expression as |
|
h5ad |
Read expression from |
|
h5ad |
Leave |
|
h5ad |
Drop cells with NaN coordinates. Without it they stop the ingest. |
|
table |
Required. Coordinate columns in axis order. |
|
table |
Row identifier, hashed into |
|
table |
Store only these columns (repeatable). |
|
table |
|
|
both |
Group cells into objects by this column. |
|
h5ad |
Add |
What the store holds¶
Numeric columns keep their dtype. Text and categorical columns become int32 codes that carry their labels; missing values are -1. Booleans become uint8.
h5ad_rowortable_row: the source row, which export uses to restore order.zv_join_key: the hashedobs_namesor--key-column, whichattachjoins on.With
--object-id-column, each object’svertex_count.
A table ingest drops rows with NaN coordinates. Every name: Headers and attributes.
Keyed tables¶
Use --format table when positions are named columns, rows carry an
identifier, or columns hold text:
zvtools convert coords.csv atlas.zv --format table \
--position-columns x,y,z --key-column cell_label --chunk-shape 500,500,500
Adding columns: zvtools attach¶
zvtools attach STORE FILE adds vertex attributes from a table or an h5ad,
matching rows to points by key. Row order need not match. The store needs a
zv_join_key.
zvtools attach atlas.zv metadata.csv --key-column cell_label --column cluster
Points with no row get NaN (floats) or -1 (codes); --missing error refuses
instead. --gene, --layer, --overwrite and --level also work; see the
CLI reference. Each attribute costs one file per chunk,
so when adding many, pass the same --shard N to convert and every attach.
Export to h5ad¶
zvtools convert cells.zv roundtrip.h5ad
Genes go to X, obs columns to obs with their categories, positions to
obsm. The row attribute restores the source order and obs_names: if you
pass --attribute, include it. A CSV export writes category columns as their
labels.