Hi guys,
I would like to filter cells by an arbitrary threshold set on the expression of a specific gene (elav) at the very begging of the pipeline. I am new to scanpy and relatively new to python.
this is what I do at the begining but I am having trouble getting it to work (see third command) with setting the corresponding threshold:
adata = adata[adata.obs['n_genes'] < 3500, :]
adata = adata[adata.obs['percent_mito'] < 0.5, :]
adata = adata[adata.var['elav'] > 0.5, :]
This last part doesn't seem to work. All help appreciated!
Try
adata = adata[adata[: , 'elav'].X > 0.5, :]
var only contain the metadata for the genes. The expression is housed in X, just as the metadata for the observations (cells) are stored in obs.
And you should be able to index adata with gene names directly as adata[:, <list of names>]. if they exist in the var_names list, adata.var_names.
For me,
adata[(adata[:,'elav'].X>0).flatten(), : ] works
otherwise, it gives error.
This issue has been mentioned on Scanpy. There might be relevant details there:
https://scanpy.discourse.group/t/filtering-cells-by-expression-of-specific-gene/256/2
Most helpful comment
Try
varonly contain the metadata for the genes. The expression is housed inX, just as the metadata for the observations (cells) are stored inobs.And you should be able to index adata with gene names directly as
adata[:, <list of names>]. if they exist in thevar_nameslist,adata.var_names.