Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION: Subset expression matrix from custom genes #91

Closed
cartal opened this issue Dec 26, 2018 · 1 comment
Closed

QUESTION: Subset expression matrix from custom genes #91

cartal opened this issue Dec 26, 2018 · 1 comment

Comments

@cartal
Copy link

cartal commented Dec 26, 2018

Hi,

I have asked this question before in Scanpy, but I wasn't sure I made it clear. So I'm giving it a try again:

Say I have the PBMC 3K dataset, and after clustering and DEG in Scanpy, I have 120 genes specific for cluster 1 and 80 genes specific for cluster 3. Now, what I would like is to take these 200 genes and export them as an expression matrix (csv or tab), where rownames are the gene symbols (i.e: IFNG, IL10, etc) and colnames are the cell ids (barcodes) present within each cluster.

How do I get this from an h5ad file?

Thanks!

@cartal cartal changed the title Subset expression matrix from custom genes QUESTION: Subset expression matrix from custom genes Dec 26, 2018
@falexwolf
Copy link
Member

Why isn't this answer (scverse/scanpy#262 (comment)) working for you?

Obviously, you'd need to subset the anndata object before:

import scanpy.api as sc
adata = sc.datasets.pbmc68k_reduced()
# this writes everything, the data matrix and annotations end up in separate files
adata[:, ['HES4', 'TNFRSF4', 'SSU72']].copy().write_csvs('./test/', skip_data=False)
# this writes only the data matrix
adata[:, ['HES4', 'TNFRSF4', 'SSU72']].to_df().to_csv('./matrix.csv')

Hope this helps!

PS: Please, next time reference your previous issue. Also, provide a small example such as the one above.

@cartal cartal closed this as completed Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants