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

error when trying to overwrite a file #206

Open
vmedaert opened this issue Dec 5, 2024 · 2 comments
Open

error when trying to overwrite a file #206

vmedaert opened this issue Dec 5, 2024 · 2 comments

Comments

@vmedaert
Copy link

vmedaert commented Dec 5, 2024

An error occurs in anndataR::from_Seurat with output_class="HDF5AnnData" when trying to write to an existing file:

Error in initialize(...) : 
obs must be NULL when loading an existing .h5ad file
@lazappi
Copy link
Collaborator

lazappi commented Dec 5, 2024

Can you please provide an example of the code you ran?

@vmedaert
Copy link
Author

vmedaert commented Dec 6, 2024

Can you please provide an example of the code you ran?

# load old seurat object
old <- readRDS("./rds/seuratObj3531889.rds")

# create seurat object v5
seuratObj <- CreateSeuratObject(
  counts = GetAssayData(old, layer="counts"),
  data = GetAssayData(old, layer="data"),
  meta.data = [email protected]
)
seuratObj <- SetAssayData(
  seuratObj,
  layer="scale.data",
  new.data=GetAssayData(old, layer="scale.data")
)
seuratObj@assays[["RNA"]]@layers$counts@Dimnames <- old@assays[["RNA"]]$counts@Dimnames
seuratObj@assays[["RNA"]]@layers$data@Dimnames <- old@assays[["RNA"]]$data@Dimnames
seuratObj[["RNA"]]@meta.data$gene <- old@assays[["RNA"]]$counts@Dimnames[[1]]

# this call throws the error if "./annData/annData3531889.h5" already exists (so I have to delete it to be able to update the file)
anndataR::from_Seurat(
  seuratObj,
  "HDF5AnnData",
  file="./annData/annData3531889.h5"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants