Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Export a cube from another tool

A tool that holds cells, such as an analysis platform or an atlas, can hand its pseudobulk profiles to CytePool as a cube file: the sums of every sample, cell type and gene, the tables that describe them, the number of cells behind each profile, and a record of where they came from. This page builds a cube from sums computed outside CytePool, saves it, and checks it. Cube files and provenance records describes the file and the record in full.

The cells here are those of the simulated PBMC study (Datasets), standing in for the exporter’s store: 12 donors sampled before and after a stimulation, six cell types. python docs/datasets.py prepare simulated_pbmc writes them to the cache, and the code below opens them by name.

CytePool 0.1.dev42+g6991e63f8, numpy 2.5.4
19,151 cells x 2,000 genes in 24 samples
cell types: B cells, CD4 T cells, CD8 T cells, NK cells, Monocytes, Dendritic cells

Pool the cells where they are

The exporter sums the counts of the cells of every sample and cell type into an array on disk, shaped cell types x samples x genes as a cube’s layers are. Here numpy does it from the cells’ sparse counts. A numpy memmap opened from that file is a lazy layer: the cube reads one cell type at a time from it, so the sums never need to fit in memory together. HDF5 datasets and Zarr arrays work the same way.

counts: memmap of shape (6, 24, 2000), uint32
62,621,014 counts from 19,151 cells

Build the cube with a source record

Cube takes the layers, the sample, group and feature tables, the cell numbers and a provenance record. Its source is the exporter’s own account of where the data came from; CytePool stores it as given and never interprets it. The fields below are those that make a cube traceable to its cells: the tool and its version, the dataset, the frozen selection of cells (which stays in the exporter’s files), the annotations that defined samples and groups, and the settings.

Cube with 24 samples x 6 groups x 2,000 features
  layers: counts (uint32, lazy)
  filled: 144 of 144 sample x group entries have cells (100.0%)
  samples: sample_id, donor, condition
  groups: group_id
  features: feature_id

Save it and open it again

write_cube reads the lazy layer one cell type at a time, hashes each as it writes it, and stores the digests with the file. read_cube opens the file without reading its counts. Cube.history prints the provenance record, with the source first and the fingerprint last.

['features', 'groups', 'layers', 'n_cells', 'samples', 'zarr.json']
Cube with 24 samples x 6 groups x 2,000 features
  layers: counts (uint32, lazy)
  filled: 144 of 144 sample x group entries have cells (100.0%)
  samples: sample_id, donor, condition
  groups: group_id
  features: feature_id

Source, as the caller recorded it (unresolved: CytePool does not follow its references):
  tool: "example-exporter"
  version: "0.1"
  dataset: {"id": "simulated_pbmc", "file": "simulated_pbmc_cells.npz"}
  cell_selection: {"artifact": "selections/all-cells", "n_cells": 19151}
  samples: {"columns": ["donor", "condition"]}
  groups: {"column": "cell_type"}
  settings: {"layer": "raw counts", "filters": null}
References: CytePool resolves none on its own. The source record's references need the tool that wrote them. A fingerprint names a cube without saying where it is: Cube.fingerprint() of a cube at hand says whether it is that cube.
Fingerprint: sha256:b4a9d782cf081e10a8e835d66ae7b061874fc377ef838f168cf29911f79e7501

Check the export

The fingerprint names the cube’s values, not how it was made. Pooling the same cells with CytePool’s own from_cells therefore gives the same fingerprint when the export is right: a check an exporter can run on part of its data. On the opened file, Cube.verify_fingerprint recomputes the fingerprint from the stored values and checks every digest.

same values as from_cells: True
stored values verified:    True