opendvp.io.export_adata#
- export_adata(adata, path_to_dir, checkpoint_name, export_as_cvs=False, metadata_cols=None, metadata_index=None, parquet=False, perseus=False)#
Save an AnnData object as both .h5ad and optionally .parquet, .csv, or Perseus files in a checkpoint directory.
- Parameters:
adata (anndata.AnnData) – AnnData object to save.
path_to_dir (str or pathlib.Path) – Directory where the checkpoint folder will be created.
checkpoint_name (str) – Name for the checkpoint folder and file prefix.
export_as_cvs (bool, optional) – If True, exports the data and metadata as .csv (tab-delimited) or .parquet files. Default is False.
metadata_cols (list, optional) – List of columns from adata.obs to include in the metadata file. If None, all columns are included.
metadata_index (str, optional) – Column from adata.obs to use as index in the exported files. If None, uses the default index.
parquet (bool, optional) – If True, exports as .parquet files instead of .csv. Only used if export_as_cvs is True.
perseus (bool, optional) – If True, exports Perseus-compatible files in a subfolder. Default is False.
- Returns:
This function saves files to disk and does not return a value.
- Return type:
None
Examples
>>> from opendvp.io.export_adata import export_adata >>> import anndata as ad >>> import numpy as np >>> import pandas as pd >>> X = np.random.rand(10, 5) >>> obs = pd.DataFrame({"celltype": ["A"] * 5 + ["B"] * 5}, index=[f"cell{i}" for i in range(10)]) >>> var = pd.DataFrame(index=[f"gene{i}" for i in range(5)]) >>> adata = ad.AnnData(X=X, obs=obs, var=var) >>> export_adata(adata, path_to_dir="checkpoints", checkpoint_name="test", export_as_cvs=True, perseus=True)