How to overlay obs identities from one object to another?

Hi!

I have created an object adata.
Within this object adata a set of clusters was subset and re-clustered as a separate object adata2 with it’s own identities.
How to overlay identities from adata2 onto adata identities?

adata.obs["cell_labels_subset"] = adata.obs["cell_labels"][:]
adata.obs["cell_labels_subset"].loc[adata.obs.index.isin(list(adata2.obs.index))] = adata2.obs["cell_labels_subset_subset_annotation"].values()

resulted in
TypeError: 'Categorical' object is not callable

Could you please help?

Thanks!

Have you tried with scanpy.tl.ingest?

@naikon, I think your issue is coming from placing the parenthesis after .values. Since there is no way to call that object, you are getting an error.

I would also recommend you instead do:

adata.obs["cell_labels_subset"] = adata.obs["cell_labels"].copy()
adata.obs.loc[adata2.obs_names, "cell_labels_subset"] = adata2.obs["cell_labels_subset_subset_annotation"]

This should be a bit more simple, and will make sure the Series are aligned.

You could also do:

adata,obs["cell_labels_subset"] = adata.obs["cell_labels"].copy()
adata,obs["cell_labels_subset"].update(adata2.obs["cell_labels_subset_subset_annotation"])
1 Like