, adata, extension=None, compression='gzip', compression_opts=None)[source]#

Write AnnData objects to file.

It is possbile to either write an AnnData object to a .csv file or a .h5ad file. The .h5ad file can be used as a cache to save the current state of the object and to retrieve it faster once needed. This preserves the object state at the time of writing. It is possible to write both, encoded and unencoded objects.

  • filename (str | Path) – File name or path to write the file to

  • adata (AnnData) – Annotated data matrix.

  • extension (str | bool) – File extension. One of ‘h5ad’, ‘csv’. Defaults to None which infers the extension from the filename.

  • compression (Optional[Literal['gzip', 'lzf']]) – Optional file compression. One of ‘gzip’, ‘lzf’. Defaults to ‘gzip’

  • compression_opts (int | None) – See

Return type:



>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>>"mimic_2.h5ad", adata)