I/O (gd.io)¶
The I/O module wraps standard AnnData and MuData readers and writers and
provides a safe, compact format for persisting the result tree stored in
.uns.
Reading annotated data¶
Read H5AD file. |
|
Read an H5MU file into a |
|
Read 10X Genomics H5 file. |
|
Read 10X Genomics MTX directory. |
- multigedi.io.read_h5ad(filename, *, backed=None)[source]¶
Read H5AD file.
Wrapper around
anndata.read_h5ad()with consistent interface.- Parameters:
- Return type:
Annotated data matrix.
Examples
>>> import multigedi as gd >>> adata = gd.read_h5ad("data.h5ad")
- multigedi.io.read_h5mu(filename, *, backed=None)[source]¶
Read an H5MU file into a
mudata.MuDataobject.Wrapper around
mudata.read_h5mu()with a consistent interface matchingmultigedi.io.read_h5ad().- Parameters:
- Return type:
Multi-modal annotated data container.
Examples
>>> import multigedi as gd >>> mdata = gd.io.read_h5mu("data.h5mu") >>> gd.tl.multigedi(mdata, modalities={"gene": {}}, sample_key="sample")
- multigedi.io.read_10x_h5(filename, *, genome=None, gex_only=True)[source]¶
Read 10X Genomics H5 file.
Reads gene expression data from 10X Genomics HDF5 format files, including those from Cell Ranger.
- Parameters:
- Returns:
X: Sparse count matrix (cells × genes)obs: Cell barcodesvar: Gene information (id, name, feature_type)
- Return type:
Annotated data matrix with
Notes
- Compatible with:
Cell Ranger v2 (matrix.h5)
Cell Ranger v3+ (filtered_feature_bc_matrix.h5)
Multi-modal outputs
Examples
>>> import multigedi as gd >>> adata = gd.read_10x_h5("filtered_feature_bc_matrix.h5") >>> adata AnnData object with n_obs × n_vars = 5000 × 20000
- multigedi.io.read_10x_mtx(path, *, var_names='gene_symbols', make_unique=True)[source]¶
Read 10X Genomics MTX directory.
Reads gene expression data from 10X Genomics Market Exchange format directory (matrix.mtx, genes.tsv/features.tsv, barcodes.tsv).
- Parameters:
- Return type:
Annotated data matrix.
Examples
>>> import multigedi as gd >>> adata = gd.read_10x_mtx("filtered_feature_bc_matrix/")
Examples¶
import multigedi as gd
adata = gd.read_h5ad("data.h5ad")
backed = gd.read_h5ad("large_data.h5ad", backed="r")
mdata = gd.io.read_h5mu("multimodal_data.h5mu")
counts = gd.read_10x_h5("filtered_feature_bc_matrix.h5")
matrix = gd.read_10x_mtx("filtered_feature_bc_matrix/")
read_10x_mtx accepts var_names and make_unique. Other Scanpy
reader options are not forwarded by this wrapper.
Writing annotated data¶
Write AnnData to H5AD file. |
|
Write a |
- multigedi.io.write_h5ad(adata, filename, *, compression='gzip', compression_opts=None)[source]¶
Write AnnData to H5AD file.
Wrapper around
anndata.AnnData.write_h5ad()with consistent interface.- Parameters:
- Return type:
Examples
>>> import multigedi as gd >>> gd.write_h5ad(adata, "results.h5ad")
- multigedi.io.write_h5mu(mdata, filename, *, compression='gzip', compression_opts=None)[source]¶
Write a
mudata.MuDataobject to an H5MU file.Wrapper around
mudata.MuData.write_h5mu()with a consistent interface matchingmultigedi.io.write_h5ad().- Parameters:
- Return type:
Examples
>>> import multigedi as gd >>> gd.io.write_h5mu(mdata, "results.h5mu")
Use H5AD or H5MU when the complete annotated object is required. These formats
retain the data matrices and the relevant obs, var, layers,
obsm, varm, and uns mappings.
gd.write_h5ad(adata, "results.h5ad", compression="gzip")
gd.io.write_h5mu(mdata, "multimodal_results.h5mu", compression="gzip")
Model-result persistence¶
Save one GEDI result tree from |
|
Load a safely serialized GEDI result tree into |
- multigedi.io.save_model(adata, filename, *, key='gedi', compression='gzip')[source]¶
Save one GEDI result tree from
.unsto a safe NPZ archive.The archive contains a versioned JSON manifest and separate NumPy array members. It does not contain pickle data. Supported result values are nested dictionaries with string keys, lists, tuples, Python scalars, NumPy scalars, and non-object NumPy arrays.
- Parameters:
adata (
AnnData|MuData) – AnnData or MuData container with GEDI results.filename (
str|Path) – Output path..npzis added when no suffix is supplied; other suffixes are rejected.key (
str, default:'gedi') – Key inadata.unsormdata.unscontaining the result tree.compression (
str|None, default:'gzip') –"gzip"writes a compressed NPZ archive.Nonewrites an uncompressed NPZ archive.
- Return type:
Notes
This function saves only
adata.uns[key](ormdata.uns[key]). It does not save the data matrix, annotations, layers, embeddings, or loadings. Use H5AD/H5MU persistence when the full annotated object is required.Examples
>>> import multigedi as gd >>> gd.tl.gedi(adata, batch_key="sample") >>> gd.io.save_model(adata, "gedi_model.npz")
- multigedi.io.load_model(adata, filename, *, key='gedi')[source]¶
Load a safely serialized GEDI result tree into
.uns.Only the versioned JSON-manifest NPZ format written by
save_model()is accepted. NumPy archives are always opened withallow_pickle=False; legacy archives containing stringified Python dictionaries are rejected.- Parameters:
- Return type:
Notes
Loading restores only
adata.uns[key](ormdata.uns[key]). It does not reconstruct or modifyX,obs,var,layers,obsm, orvarm. The destination is mutated only after the complete archive has passed validation.Examples
>>> import multigedi as gd >>> gd.io.load_model(adata, "gedi_model.npz") >>> adata.uns["gedi"]["model"]
save_model stores exactly one result tree, container.uns[key], in a
versioned NPZ archive. The format uses a strict JSON manifest and separate
NumPy array members. It does not use pickle or evaluate serialized Python
expressions. Nested dictionaries with string keys, lists, tuples, Python and
NumPy scalars, and non-object NumPy arrays are preserved.
For a single-modal result:
gd.tl.gedi(adata, batch_key="sample", n_latent=10)
gd.io.save_model(adata, "gedi_model.npz")
target = gd.read_h5ad("data.h5ad")
gd.io.load_model(target, "gedi_model.npz")
result = target.uns["gedi"]
For the canonical multi-modal result on the MuData container:
gd.io.save_model(mdata, "multigedi_model.npz", key="multigedi")
target = gd.io.read_h5mu("data.h5mu")
gd.io.load_model(target, "multigedi_model.npz", key="multigedi")
result = target.uns["multigedi"]
Important
load_model restores only container.uns[key]. It does not reconstruct
or modify the data matrix, annotations, layers, cell embeddings in obsm,
or feature loadings in varm. Use H5AD/H5MU to persist a complete analysis
object.
Note
Legacy NPZ files that stored stringified Python dictionaries are rejected.
Regenerate them from the original trusted analysis with the current
save_model. Object arrays are deliberately unsupported.
Top-level convenience exports¶
The AnnData and 10X helpers are also available at the package top level:
adata = gd.read_h5ad("data.h5ad")
gd.write_h5ad(adata, "output.h5ad")
H5MU and model-result persistence helpers are available through gd.io.