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

Why we cannot tranfer adata along with functions? #2030

Closed
hyjforesight opened this issue Nov 1, 2021 · 1 comment
Closed

Why we cannot tranfer adata along with functions? #2030

hyjforesight opened this issue Nov 1, 2021 · 1 comment

Comments

@hyjforesight
Copy link

hyjforesight commented Nov 1, 2021

Hello all,
For these 2 functions,
sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)
the authors make inplace=True as default.

Because I want to tranfer the output into an variable, I change these functions to

a=sc.pp.filter_cells(adata, min_genes=200, inplace=False)
sc.pp.filter_genes(a, min_cells=3, inplace=False)

but it creates errors and the output of a is NoType:

aceback (most recent call last):
FileC:\Users\Yuanjian\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\interactiveshell.py”, line 3343, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 2, in
sc.pp.filter_genes(a, min_cells=3, inplace=False) # exclude genes only expressed in <3 cells
FileC:\Users\Yuanjian\AppData\Local\Programs\Python\Python36\lib\site-packages\scanpy\preprocessing_simple.py”, line 259, in filter_genes
X if min_cells is None and max_cells is None else X > 0, axis=0

Does anybody know why inplace=False doesn’t work?
Thanks!
Best,
YJ

@ivirshup
Copy link
Member

I would agree the results of sc.pp.filter_genes(..., inplace=False) are not the most intuitive. Instead of returning a filtered anndata, it returns which cells would have been filtered and the stats which were used to make this decision. This is documented under the Returns section for these functions.

What you might want is

mask, _ = sc.pp.filter_cells(adata, min_genes=200, inplace=False)
a = adata[mask].copy()

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