Skip to main content

data_beans/
export.rs

1//! Write a backend out to the interchange formats scanpy and Seurat read.
2//!
3//! * [`to_mtx`]: a 10x Genomics Cell Ranger MEX triplet directory
4//!   (`matrix.mtx`, `features.tsv`, `barcodes.tsv`, gzipped by default),
5//!   loaded by `scanpy.read_10x_mtx(dir)` and Seurat `Read10X(dir)`.
6//! * [`to_h5ad`] (feature `hdf5`): an AnnData `.h5ad` file, loaded by
7//!   `anndata.read_h5ad`, with optional `obs` / `var` metadata tables.
8//!
9//! Both take a backend already open, so a caller holding one does not open
10//! it again; [`open_sparse_matrix_by_path`](crate::sparse_io::open_sparse_matrix_by_path)
11//! opens one from its file. These are what `data-beans to-mtx` and
12//! `data-beans to-h5ad` run, and write the same bytes.
13//!
14//! ```no_run
15//! use data_beans::export::{self, MtxExport};
16//! use data_beans::sparse_io::open_sparse_matrix_by_path;
17//!
18//! let data = open_sparse_matrix_by_path("sim.zarr.zip")?;
19//! // sim_mtx/{matrix.mtx.gz, features.tsv.gz, barcodes.tsv.gz}
20//! export::to_mtx(data.as_ref(), "sim_mtx", &MtxExport::default())?;
21//!
22//! #[cfg(feature = "hdf5")]
23//! {
24//!     let mut data = data;
25//!     let out = export::h5ad_path("sim.zarr.zip", None); // "sim.h5ad"
26//!     export::to_h5ad(data.as_mut(), &out, &export::H5adExport::default())?;
27//! }
28//! # anyhow::Ok(())
29//! ```
30
31#[cfg(feature = "hdf5")]
32pub(crate) mod h5ad;
33mod mtx;
34
35#[cfg(feature = "hdf5")]
36pub use h5ad::{h5ad_path, to_h5ad, H5adExport};
37pub use mtx::{to_mtx, MtxExport};