Skip to content

Commit

Permalink
update for IO.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanliwei-coder committed Jun 28, 2024
1 parent a521bab commit 0c84c26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion stereo/io/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ def read_h5ms(file_path, use_raw=True, use_result=True):
# result = {}
for k in f.keys():
if k == 'sample':
for one_slice_key in f[k].keys():
slice_keys = list(f[k].keys())
slice_keys.sort(key=lambda k: int(k.split('_')[1]))
for one_slice_key in slice_keys:
data = _read_stereo_h5ad_from_group(f[k][one_slice_key], StereoExpData(), use_raw, use_result)
# encoding_type = f[k][one_slice_key].attrs.get('encoding-type', 'stereo_exp_data')
# if encoding_type == 'stereo_exp_data':
Expand Down
5 changes: 3 additions & 2 deletions stereo/io/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _write_one_h5ad(f: h5py.File, data: StereoExpData, use_raw=False, use_result
# h5ad.write(data.bin_size, f, 'bin_size')
# h5ad.write(data.merged, f, 'merged')

use_raw = use_raw and data.tl.raw is not None
if use_raw is True:
same_genes = np.array_equal(data.tl.raw.gene_names, data.gene_names)
same_cells = np.array_equal(data.tl.raw.cell_names, data.cell_names)
Expand Down Expand Up @@ -300,7 +301,7 @@ def write_h5ms(ms_data, output: str):
f.create_group('sample')
for idx, data in enumerate(ms_data._data_list):
f['sample'].create_group(f'sample_{idx}')
_write_one_h5ad(f['sample'][f'sample_{idx}'], data)
_write_one_h5ad(f['sample'][f'sample_{idx}'], data, use_raw=True, use_result=True)
# if isinstance(data, AnnBasedStereoExpData):
# _write_one_anndata(f['sample'][f'sample_{idx}'], data)
# else:
Expand All @@ -314,7 +315,7 @@ def write_h5ms(ms_data, output: str):
g = f['sample_merged'].create_group(scope_key)
if ms_data.merged_data and id(ms_data.merged_data) == id(merged_data):
g.attrs['merged_from_all'] = True
_write_one_h5ad(g, merged_data)
_write_one_h5ad(g, merged_data, use_raw=True, use_result=True)
# if isinstance(merged_data, AnnBasedStereoExpData):
# _write_one_anndata(g, merged_data)
# else:
Expand Down

0 comments on commit 0c84c26

Please sign in to comment.