scanpy add metadata
1
0
Entering edit mode
9 months ago
Andy ▴ 120

Hello,

I am trying to create anndata in Python, and I want to add metadata to each object.

I want to add a donor_id to my objects. Since one object is an RDS file that includes over 20 subjects and contains metadata called donor_id, I want to create one and be able to distinguish those 20 subjects separately. I have written my code as follows:

p9.obs['donor_id']='p9'

However, when I try to save the file, I receive this error message:

TypeError: Can't implicitly convert non-string objects to strings

How should I revise my code to avoid this error?

Thanks Andy

scanpy metadata • 1.3k views
ADD COMMENT
1
Entering edit mode
7 months ago
yl759 ▴ 120

I had this issue before, and I would love to learn the correct way of doing it. Instead, I use pickle to save the object.

import pickle

# your preprocess...
p9.obs['donor_id']='p9'

# save to file
with open(path_to_save, "wb") as file:
    pickle.dump(p9, file)

# load from file
with open(path_to_file, "rb") as file:
    p9 = pickle.load(file)
ADD COMMENT

Login before adding your answer.

Traffic: 1830 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6