Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to edit backed AnnData #369

Open
jpmcga opened this issue Dec 11, 2024 · 2 comments
Open

Unable to edit backed AnnData #369

jpmcga opened this issue Dec 11, 2024 · 2 comments
Labels
enhancement ✨ New feature or request

Comments

@jpmcga
Copy link

jpmcga commented Dec 11, 2024

Hi,

Thanks again for writing a wonderful package. I'm currently trying to implement the backed AnnData objects into a pipeline I'm building. I have a couple items of feedback to share, but I'll start with this one.

After I create backed AnnData objects via pp.import_data I'm unable to add new columns to .obs (i.e., adata.obs["barcode"] = adata.obs_names). Attempting to do so, I get the error

called `Result::unwrap()` on an `Err` value: H5Ldelete(): unable to delete link: no write intent on file note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I'm able to resolve this error by closing the AnnData object (adata.close()), and then rereading with write permissions (adata = snap.read(f"{file_name}.h5ad", "r+")). While this works, it's awkward and I have to do it again after running snap.metrics.tsse. I wonder if there's a better way to specify permissions when create backed AnnData objects. If not, perhaps an option to specify in import_data would be helpful.

Thanks!

@kaizhang
Copy link
Owner

This is wired. The following code works for me:

import snapatac2 as snap

fragment_file = snap.datasets.pbmc500(downsample=True)
data = snap.pp.import_data(
    fragment_file,
    chrom_sizes=snap.genome.hg38,
    file='test.h5ad',
    sorted_by_barcode=False,
)
data.obs['barcode'] = data.obs_names

print(data)

@jpmcga
Copy link
Author

jpmcga commented Dec 13, 2024

Thanks for the quick response! The code you shared works for me as well. However, I'm able to trigger the error by putting fragment_file and the file name in lists:

import snapatac2 as snap

if __name__ == '__main__':

    fragment_file = snap.datasets.pbmc500(downsample=True)
    data = snap.pp.import_data(
        [fragment_file],
        chrom_sizes=snap.genome.hg38,
        file=['test.h5ad'],
        sorted_by_barcode=False,
    )
    data[0].obs['barcode'] = data[0].obs_names

    print(data)

Any ideas? Thanks.

@kaizhang kaizhang added the enhancement ✨ New feature or request label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants