From e12d56d8ea8bb2545c5246c6d8ad3a433846d285 Mon Sep 17 00:00:00 2001 From: reif Date: Sun, 2 Jun 2024 16:13:17 +0000 Subject: [PATCH] add easier and non-repetitive implementation to fix the random_sample_size --- src/sliders.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/sliders.py b/src/sliders.py index 4fe3035..51a6b9e 100644 --- a/src/sliders.py +++ b/src/sliders.py @@ -78,19 +78,13 @@ def random_sample(): adata = _adata_qc.get() if adata is None: return - - obs_number = adata.n_obs - sample_size = input['random_sample_size']() - - if int(sample_size) > int(obs_number): - sample_size = obs_number - ui.update_slider('random_sample_size', value=sample_size, max=obs_number) - - + + sample_size = input['random_sample_size'].get() + if adata is None: return - adata_sample = adata[np.random.choice(adata.obs.index, sample_size, replace=False)] + adata_sample = adata[np.random.choice(adata.obs.index, min(sample_size, len(adata.obs)), replace=False)] _adata_sample.set(adata_sample) @output