This is a fork from PMBio's MuDataSeurat
Please refer to the original repo for more details
I find MuDataSeurat to be the most compatible tool for converting SeuratObject to H5AD/H5MU format. It does not require python runtime as well.
The original repository activity seems quite low, and unfortunately, the bugs have not been fixed promptly. Since I use MuDataSeruat quite often, I've decided to create my own fork and make my own version. I will do my best to ensure that it remains compatible with the latest pull requests from the original repository.
- Compatible with Seurat v5
- Tested and works with
anndata(>=0.8), andanndata-rs(>=0.2.0). - Export all missing reductions, such as
UMAP,tSNEetc. - Fixed stack overflow issue because of obs column containing NAs
- skip columns with all NA value
- fixed string array with NA
- Add two new keyword arguments to
WriteH5ADandWriteH5MU:scale.data: whether writescale.datatoanndata/mudataor not.sparse.type: storecsc_matrixorcsr_matrixinanndata/mudata
- Correctness fixes
.h5mufiles are now readable bymudata:obsm,varm,obsp,varp,obsmapandvarmapare always written.- Categorical (factor) columns keep their labels when a category is unused.
NAin string columns is stored as a missing value (ascategorical, since anndata has no nullable-string encoding) instead of the text"NaN".WriteH5ADnow errors on an unknownassayinstead of silently writing a different one.- Reductions whose names contain non-alphanumeric characters (
umap_harmony,pca_uncorrected,mrVI_umap, ...) are no longer dropped fromobsm. Seurat strips those characters when it derives a reduction key (umap_harmony->umapharmony_), which previously made such reductions fail the assay-matching check and be skipped silently. A reduction that is still not matched now raises a warning instead of disappearing.
Please install the main branch
remotes::install_github("zqfang/MuDataSeurat")MuDataSeurat only export 3 layers: count, data, scale.data
Therefore, You need JoinLayers for each modality first with seurat v5.
library(MuDataSeurat)
DefaultAssay(seu) = "RNA"
seu = JoinLayers(seu) # critical for seurat v5
## write unimodal h5ad
WriteH5AD(seu, "export.h5ad", assay="RNA", scale.data = FALSE, overwrite=TRUE)
## write multimodal h5mu
WriteH5MU(seu, "export.h5mu", overwrite=TRUE)seu <- ReadH5AD("export.h5ad")
seu <- ReadH5MU("export.h5mu")You may also use the native support of anndata in R: anndataR::read_h5ad