anndict.adata_dict.read_adata_dict#
- anndict.adata_dict.read_adata_dict(directory)[source]#
Read an
AdataDict
from a previously savedAdataDict
. To write anAdataDict
seewrite_adata_dict()
.- Parameters:
- directory
str
Base directory where the
.h5ad
files and hierarchy file are located.
- directory
- Return type:
- Returns:
An
AdataDict
reconstructed from the saved files.- Raises:
FileNotFoundError – If the directory or required metadata files don’t exist.
ValueError – If the metadata files are corrupted or in an unexpected format.
Examples
Case 1: Flat hierarchy
directory/ ├── adata_dict.hierarchy.json ├── adata_dict.db.json ├── <file_prefix>Donor1_Tissue1.h5ad ├── <file_prefix>Donor1_Tissue2.h5ad └── <file_prefix>Donor2_Tissue1.h5ad
The reconstructed AdataDict will be:
print(adata_dict) > { > ("Donor1", "Tissue1"): adata_d1_t1, > ("Donor1", "Tissue2"): adata_d1_t2, > ("Donor2", "Tissue1"): adata_d2_t1, > }
Case 2: Nested hierarchy
directory/ ├── adata_dict.hierarchy.json ├── adata_dict.db.json ├── Donor1/ │ ├── <file_prefix>Tissue1.h5ad │ └── <file_prefix>Tissue2.h5ad └── Donor2/ └── <file_prefix>Tissue1.h5ad
The reconstructed AdataDict will be:
print(adata_dict) > { > ("Donor1",): { > ("Tissue1",): adata_d1_t1, > ("Tissue2",): adata_d1_t2, > }, > ("Donor2",): { > ("Tissue1",): adata_d2_t1, > }, > }
Case 3: Nested hierarchy with multiple indices at the deepest level
directory/ ├── adata_dict.hierarchy.json ├── adata_dict.db.json ├── Donor1/ │ ├── <file_prefix>Tissue1_CellType1.h5ad │ ├── <file_prefix>Tissue1_CellType2.h5ad │ └── <file_prefix>Tissue2_CellType3.h5ad └── Donor2/ └── <file_prefix>Tissue1_CellType1.h5ad
The reconstructed AdataDict will be:
print(adata_dict) > { > ("Donor1",): { > ("Tissue1", "CellType1"): adata_d1_t1_c1, > ("Tissue1", "CellType2"): adata_d1_t1_c2, > ("Tissue2", "CellType3"): adata_d1_t2_c3, > }, > ("Donor2",): { > ("Tissue1", "CellType1"): adata_d2_t1_c1, > }, > }
See also
write_adata_dict()
To write an
AdataDict