This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to subset anndata by clusters and their gene markers?

Hello, I want to subset anndata on basis of each cluster and their gene id/marker but having trouble executing it. Not sure how I can subset .obs, since the cluster information is stored in observation, which subsequently subsets corresponding ...

I tried using adata_dub_gene_6 = adata[adata.obs["leiden"] == "6"].var which was no different from doing just adata.var which outputs all the genes (metadata) of the anndata.

Thank you!

anndata python scanpy scrna scvi

1 answer

You can define a subset with adata_dub_gene_6 = adata[adata.obs['leiden'].isin('6')], you should treat your obs like a Pandas DataFrame.

With isin(['5', '6']) you can select a list of values and retrieve it from adata.

Log in to answer this question.