smftools.informatics.partition_store#
Zarr partition + thin molecule-index spine + partition catalog helpers.
write_dense_cache_from_spine is the actively-used piece: it builds the
optional dense zarr cache (smftools load / cli.load_adata.load_dense_cache)
from a raw ragged store, and is what AdataPaths.store/.spine/.catalog
point at.
The lower-level write_partitioned_store/build_spine/write_catalog/
write_experiment_store functions predate the raw/load split (they were the
storage layer for the original 1.0.0 output re-architecture spike, partitioning
an arbitrary in-memory AnnData by (Reference_strand, Sample) with no genomic
windowing). Nothing in the current pipeline writes that format anymore -- the
CLI command and load_adata_core auto-emit that used to produce it have been
removed. They're kept only because materialize()'s generic dense-partition
read path (tests/unit/informatics/test_partition_read.py,
test_partition_store.py) still uses them as a convenient way to build an
arbitrary multi-reference/multi-sample dense fixture without needing a full
ragged/CIGAR-based raw store. Do not wire them back into production code; if
that read path needs new coverage, build it from write_dense_cache_from_spine
or write_raw_store instead.
The partition + spine writes go through smftools.readwrite.safe_write_zarr()
/ safe_write_h5ad(), so the same sanitization + pickle-backup behavior used
by the monolithic path applies here too. Partitions are written zarr v3.
Functions
|
Build the thin molecule-index spine AnnData from written partitions. |
|
Write the partition catalog parquet (one row per partition). |
|
Materialize and persist a reference-partitioned dense cache. |
|
Write a full experiment store: partitions + spine + catalog, and register them. |
|
Split adata by |
Classes
|
Metadata for one written |
- class smftools.informatics.partition_store.PartitionInfo(partition_id, reference, sample, group_path, n_reads, n_positions, read_ids=<factory>)#
Bases:
objectMetadata for one written
(reference, sample)partition.- Fields:
partition_id: Stable identifier (
"<slug_ref>/<slug_sample>"). reference: ExactReference_strandvalue for this partition. sample: ExactSamplevalue for this partition. group_path: Partition zarr path, relative to the experiment output dir. n_reads: Number of molecules (obs rows) in the partition. n_positions: Number of positions (var) in the partition. read_ids: Read names in stored order (index i ->partition_rowi).
- smftools.informatics.partition_store.write_partitioned_store(adata, output_dir, *, reference_col='Reference_strand', sample_col='Sample', obs_chunk=10000, zarr_format=3, backup=True, verbose=False)#
Split adata by
(reference, sample)and write one zarr partition each.- Parameters:
adata (
AnnData) -- In-memory AnnData to partition (X + layers + obs + var + uns).output_dir (
str|Path) -- Experiment output directory; partitions go underoutput_dir/store/<slug_ref>/<slug_sample>.reference_col (
str(default:'Reference_strand')) -- obs column identifying the reference (default Reference_strand).sample_col (
str(default:'Sample')) -- obs column identifying the sample (default Sample).obs_chunk (
int(default:10000)) -- zarr chunk size along the obs axis.zarr_format (
int(default:3)) -- zarr on-disk format to write (default v3).backup (
bool(default:True)) -- Passed to safe_write_zarr (pickle non-serializable uns/obs).verbose (
bool(default:False)) -- Verbose sanitization logging.
- Returns:
One entry per written partition, with read order.
- Return type:
- Raises:
KeyError -- If
reference_colorsample_colis missing fromadata.obs.
- smftools.informatics.partition_store.build_spine(adata, partitions, *, identity_cols=None, bam_path=None, extra_uns=None)#
Build the thin molecule-index spine AnnData from written partitions.
One obs row per molecule, indexed by read name, with identity columns plus pointer columns (
partitiongroup path,partition_rowposition within that partition, andbam_path). Carries noXor layers.- Parameters:
adata (
AnnData) -- The source AnnData (for identity columns and uns pointers).partitions (
Sequence[PartitionInfo]) -- Partition metadata fromwrite_partitioned_store().identity_cols (
Optional[Sequence[str]] (default:None)) -- obs columns to copy as identity; defaults to those inDEFAULT_IDENTITY_COLSthat exist onadata.bam_path (
str|None(default:None)) -- Optional aligned-BAM path recorded for every molecule.extra_uns (
dict|None(default:None)) -- Extra key/values to store in the spineuns.
- Returns:
The spine (obs-only) object.
- Return type:
- smftools.informatics.partition_store.write_catalog(catalog_path, partitions, *, experiment=None, modality=None, config_hash=None)#
Write the partition catalog parquet (one row per partition).
- Parameters:
partitions (
Sequence[PartitionInfo]) -- Partition metadata fromwrite_partitioned_store().experiment (
str|None(default:None)) -- Optional experiment name recorded on every row.modality (
str|None(default:None)) -- Optional smf modality recorded on every row.config_hash (
str|None(default:None)) -- Optional config hash recorded on every row (staleness check).
- Returns:
The written catalog path.
- Return type:
Path
- smftools.informatics.partition_store.write_experiment_store(adata, output_dir, *, experiment=None, modality=None, config_hash=None, bam_path=None, reference_col='Reference_strand', sample_col='Sample', obs_chunk=10000, zarr_format=3, verbose=False)#
Write a full experiment store: partitions + spine + catalog, and register them.
- Parameters:
adata (
AnnData) -- The in-memory experiment AnnData to convert.experiment (
str|None(default:None)) -- Experiment name (recorded in catalog and spine uns).modality (
str|None(default:None)) -- smf modality (recorded in catalog).config_hash (
str|None(default:None)) -- Config hash (recorded in catalog for staleness detection).bam_path (
str|None(default:None)) -- Aligned-BAM path recorded per molecule in the spine.reference_col (
str(default:'Reference_strand')) -- obs column identifying the reference.sample_col (
str(default:'Sample')) -- obs column identifying the sample.obs_chunk (
int(default:10000)) -- zarr obs-axis chunk size.zarr_format (
int(default:3)) -- zarr on-disk format (default v3).verbose (
bool(default:False)) -- Verbose sanitization logging.
- Returns:
Paths for
store,spine,catalog,manifest.- Return type:
- smftools.informatics.partition_store.write_dense_cache_from_spine(spine_path, *, output_dir=None, obs_chunk=10000, zarr_format=3, verbose=False)#
Materialize and persist a reference-partitioned dense cache.
Each reference is densified independently from the ragged store, ordered by barcode, and written before the next reference is loaded. This bounds peak memory by the largest reference partition and preserves one shared row layout.