BiomedicalMachineLearning / stLearn

A novel machine learning pipeline to analyse spatial transcriptomics data
Other
176 stars 23 forks source link

save anndata object to h5ad file #262

Closed rialc13 closed 6 months ago

rialc13 commented 7 months ago

Hi,

After performing spatial trajectory analysis, I am trying to save the anndata object to h5ad file using the write_h5ad(file_name) function but am getting the following error -

image

I googled the error & many people suggested removing the adata.raw layer. I did that (using del bdata.raw), still I get the following (new) error -

image image

Can you please help? Thanks

duypham2108 commented 7 months ago

It seems Anndata prevents saving it in the new version if the key in a dictionary has an int type. We will try to fix it soon. One temporary solution is using pickle

# For saving
import pickle
with open('anndata.obj', 'wb') as fp:
    pickle.dump(data, fp)

# For loading
import pickle
with open('anndata.obj', 'rb') as fp:
    adata = pickle.load(fp)
rialc13 commented 7 months ago

Thank you so much! This worked!