Skip to content

Can't write old style (obsm compound dataset) h5ad in backed mode #188

Closed

Description

@joshua-gould
import anndata as ad
adata = ad.read('test.h5ad', backed='r+')
adata.write('test.h5ad')

RuntimeError: Unable to create link (message type not found)
anndata==0.6.22.post1
test.h5ad.zip

Activity

  1. ivirshup commented on Aug 8, 2019

    @ivirshup
    Member

    I can reproduce it, but I think there are a number of things going on. I've got a couple questions for clarification:

    • What are you expecting this to do? What's the use case here?
    • Does the anndata object actually have an obsm which is an ndarray?
    • Do you expect the written file to have a dense matrix?
  2. added a commit that references this issue on Aug 8, 2019
  3. joshua-gould commented on Aug 8, 2019

    @joshua-gould
    ContributorAuthor

    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}

  4. joshua-gould commented on Aug 8, 2019

    @joshua-gould
    ContributorAuthor

    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']
    
  5. ivirshup commented on Aug 9, 2019

    @ivirshup
    Member

    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.

  6. added a commit that references this issue on Sep 5, 2019
  7. ivirshup commented on Sep 10, 2019

    @ivirshup
    Member

    Fixed by #167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions