Extract gene X sample from each cell cluster

Hello;

For eQTL analysis; after clustering; I want to extract the expression level of each gene in each cell type for each individual. Each cell cluster on the umap consists of multiple individuals. I wanted to extract the gene expression matrix for each individual in each cluster. However, the “vars” component of the Anndata gives me the gene expression summary for all individuals. How can I extract the gene expression for each person.

Thank you in advance;

I might be misunderstanding, but are you asking how you can get something like the mean per individual for each gene?

If so, this will be easier once we figure out how to include theislab/anndata#564, but for now you can do something like:

means = pd.DataFrame(index=adata.var_names)
for k, indices in adata.obs.grouby("person").indices.items():
    means[k] = np.ravel(adata.X[indices].mean(axis=0))
1 Like

Exactly! This is what I needed. Thank you so much. I appreciate your help!