You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't write old style (obsm compound dataset) h5ad in backed mode #188
Use case: I have an old style h5ad file (obsm stored as compound dataset) that I want to open in r+ mode and save back to disk. I don' expect the written file to have a dense matrix for X.
File contents: h5ls test.h5ad
X Group
obs Dataset {3}
obsm Dataset {3}
uns Group
var Dataset {3}
This code also fixes the issue, could go at the beginning of _write_h5ad and maybe is easier to understand:
if data.isbacked and filename == data.filename:
import h5py
h5_file = adata.file._file
# Fix old h5ad files in which obsm/varm were stored as compound datasets
if 'obsm' in h5_file.keys() and isinstance(h5_file['obsm'], h5py.Dataset):
del h5_file['obsm']
if 'varm' in h5_file.keys() and isinstance(h5_file['varm'], h5py.Dataset):
del h5_file['varm']
Ah, I had misunderstood what you were trying to do in the first instance. The old-style incompatibility error is triggered by trying to overwrite the structured array. However, when I tried to write your dataset (in backed mode) to a new file (i.e. adata = sc.read("test.h5ad", backed="r+"); adata.write("test2.h5ad")) that threw similar looking errors related to .X being sparse and backed.
Thanks for the PR correcting the issue! Just a heads up, that code is going be replaced in the near future, so it might not get a chance to merge.
Activity
ivirshup commentedon Aug 8, 2019
I can reproduce it, but I think there are a number of things going on. I've got a couple questions for clarification:
obsmwhich is anndarray?Address scverse#188, and test it a bunch
joshua-gould commentedon Aug 8, 2019
Use case: I have an old style h5ad file (obsm stored as compound dataset) that I want to open in r+ mode and save back to disk. I don' expect the written file to have a dense matrix for X.
File contents:
h5ls test.h5adjoshua-gould commentedon Aug 8, 2019
This code also fixes the issue, could go at the beginning of _write_h5ad and maybe is easier to understand:
ivirshup commentedon Aug 9, 2019
Ah, I had misunderstood what you were trying to do in the first instance. The old-style incompatibility error is triggered by trying to overwrite the structured array. However, when I tried to write your dataset (in backed mode) to a new file (i.e.
adata = sc.read("test.h5ad", backed="r+"); adata.write("test2.h5ad")) that threw similar looking errors related to.Xbeing sparse and backed.Thanks for the PR correcting the issue! Just a heads up, that code is going be replaced in the near future, so it might not get a chance to merge.
IO refactor (#167)
ivirshup commentedon Sep 10, 2019
Fixed by #167