Reading and Writing
Reading and writing AnnData objects.
Reading¶
Use anndata.io.read_h5ad to load a previously saved .h5ad file, or val.datasets.polis.load to import directly from a Polis conversation.
Writing¶
valency_anndata.write ¶
write(
filename: Path | str,
adata: AnnData,
*,
include: Sequence[str] | None = None,
ext: Literal["h5", "csv", "txt", "npz"] | None = None,
compression: Literal["gzip", "lzf"] | None = "gzip",
compression_opts: int | None = None,
) -> None
Write an AnnData object to file with automatic sanitization.
Wraps scanpy.write but first copies and sanitizes adata so that
problematic fields (mixed-type uns["statements"] columns, categorical
kmeans_* labels with NA) do not cause serialization errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Path | str
|
Output path. If the filename has no file extension it is interpreted the same way as scanpy.write. |
required |
adata
|
AnnData
|
Annotated data matrix. Not mutated — a sanitized copy is written. |
required |
include
|
Sequence[str] | None
|
When not |
None
|
ext
|
Literal['h5', 'csv', 'txt', 'npz'] | None
|
File extension from which to infer file format. |
None
|
compression
|
Literal['gzip', 'lzf'] | None
|
See |
'gzip'
|
compression_opts
|
int | None
|
See |
None
|
Examples:
Basic — write everything:
Advanced — selectively include keys with glob patterns:
val.write(
"export.h5ad",
adata,
include=["obsm/X_pca", "obsm/X_pacmap", "obs/kmeans_*", "uns/*"],
)