-
Notifications
You must be signed in to change notification settings - Fork 31
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
(fix): obs filtering #148
(fix): obs filtering #148
Conversation
muon/_core/preproc.py
Outdated
# Collect elements to subset | ||
# NOTE: accessing them after subsetting .obs | ||
# will fail due to _validate_value() | ||
obsm = dict(data.obsm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably need to use _remove_unused_categories
on the dataframe - please open an issue in anndata about making this public
tests/test_muon_preproc.py
Outdated
A = pbmc3k_processed[:500,].copy() | ||
B = pbmc3k_processed[500:,].copy() | ||
mdata = mu.MuData({"A": A, "B": B}) | ||
np.random.seed(42) | ||
var_sel = np.random.choice(np.array([0, 1]), size=mdata.n_vars, replace=True) | ||
mdata.var["sel"] = var_sel | ||
mu.pp.filter_var(mdata, "sel", lambda y: y == 1) | ||
assert mdata.shape[1] == int(np.sum(var_sel)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this test as well to check the full object like assert_equal(mdata["B"], B_subset)
muon/_core/preproc.py
Outdated
@@ -756,6 +764,18 @@ def func(x): | |||
data.raw._n_obs = data.raw.X.shape[0] | |||
|
|||
else: | |||
# Subset .obs | |||
data._obs = data.obs[obs_subset] | |||
data._n_obs = data.obs.shape[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is necessary for AnnData
. Also please consider de-dupping all this logic - you can use getattr(data, f"{key}m")
and make key: Literal["obs", "var"]
an argument to a helper
Fixes #146