Unable to remove cells from Anndata matrix by an added .obs

Hello,

Sorry if the title is not clear!

I have an anndata object:

adata
Out[10]: 
AnnData object with n_obs × n_vars = 13779 × 36601
    obs: 'doublet', 'doublet_score'
    var: 'gene_ids', 'feature_types'

I used DoubletDetection package to detect dublets in my reads matrix after creating the Anndata object immediately (before filtering or qc), and added the results to .obs like this:

import doubletdetection

clf = doubletdetection.BoostClassifier() 
doublets = clf.fit(adata.X).predict()
adata.obs['doublet'] = doublets
doublet_score = clf.doublet_score()
adata.obs['doublet_score'] = doublet_score

After detecting doublets it gives result as “0” for not a doublet and “1” for a doublet.

adata.obs['doublet'].value_counts()
Out[3]: 
0.0    12697
1.0     1074
Name: doublet, dtype: int64

What I want to do is remove all cells that have doublet value of “1” before continuing the rest of the analsysis, what I’ve tried to do is:

adata= adata[adata.obs["doublet"].isin[('0')],:]
or 
adata= adata[~adata.obs["doublet"].isin[('1')],:]

However, it does not remove doublets but either removes all cells or keep all cells

Out[38]: 
View of AnnData object with n_obs × n_vars = 0 × 36601
    obs: 'doublet', 'doublet_score'
    var: 'gene_ids', 'feature_types'

Out[42]: 
View of AnnData object with n_obs × n_vars = 13779 × 36601
    obs: 'doublet', 'doublet_score'
    var: 'gene_ids', 'feature_types'

How can I filter those cells? Is there a manual way like extracting the matrix with doublets data as a csv and deleting cells, then reading again?

Thanks in advance…

Have you checked the type of values in adata.obs.doublet? Currently you are filtering based on matching the string “0” or “1”, but you might need to do this with a regular integer 0/1.
I would do something like:
adata = adata[adata.obs[‘doublet’] == 0].copy()
I hope this helps!

Hi.

That worked!!! thank you very much.
Yes, I have been treating it as a string!
Thanks a lot.