anndata.AnnData.write
- AnnData.write(filename=None, compression=None, compression_opts=None, force_dense=None, as_dense=())
Write
.h5ad
-formatted hdf5 file.Note
Setting compression to
'gzip'
can save disk space but will slow down writing and subsequent reading. Prior to v0.6.16, this was the default for parametercompression
.Generally, if you have sparse data that are stored as a dense matrix, you can dramatically improve performance and reduce disk space by converting to a
csr_matrix
:from scipy.sparse import csr_matrix adata.X = csr_matrix(adata.X)
- Parameters
- filename :
PathLike
|None
Optional
[PathLike
] (default:None
) Filename of data file. Defaults to backing file.
- compression : {‘gzip’, ‘lzf’} |
None
Optional
[Literal
[‘gzip’, ‘lzf’]] (default:None
) See the h5py Filter pipeline.
- compression_opts :
int
|Any
|None
Union
[int
,Any
,None
] (default:None
) See the h5py Filter pipeline.
- as_dense :
Sequence
[str
] (default:()
) Sparse arrays in AnnData object to write as dense. Currently only supports
X
andraw/X
.- force_dense :
bool
|None
Optional
[bool
] (default:None
) Write sparse data as a dense matrix. Defaults to
True
if object is backed, otherwise toFalse
.
- filename :