From 11146790518ddd334c99f1af4cc067baf50c04b9 Mon Sep 17 00:00:00 2001 From: jykr Date: Thu, 11 Apr 2024 13:19:17 -0400 Subject: [PATCH] Ensure editing rate is calculated by finding bulk samples from the user-specified condition column --- bean/framework/ReporterScreen.py | 5 ++++- bean/notebooks/sample_quality_report.ipynb | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bean/framework/ReporterScreen.py b/bean/framework/ReporterScreen.py index 6ea0fad..fff5a09 100755 --- a/bean/framework/ReporterScreen.py +++ b/bean/framework/ReporterScreen.py @@ -483,6 +483,7 @@ def get_guide_edit_rate( return_result=False, count_layer="X_bcmatch", edit_layer="edits", + condition_col = "condition", unsorted_condition_label=None, ): """ @@ -506,10 +507,12 @@ def get_guide_edit_rate( ) if unsorted_condition_label is not None: bulk_idx = np.where( - self.samples.index.astype(str).map( + self.samples[condition_col].astype(str).map( lambda s: unsorted_condition_label in s ) )[0] + if len(bulk_idx) == 0: + raise ValueError(f"{unsorted_condition_label} is not found in ReporterScreen.samples['{condition_col}]. Check your input.") else: bulk_idx = np.arange(0, len(self.samples)).astype(int) diff --git a/bean/notebooks/sample_quality_report.ipynb b/bean/notebooks/sample_quality_report.ipynb index 616d390..99bc737 100755 --- a/bean/notebooks/sample_quality_report.ipynb +++ b/bean/notebooks/sample_quality_report.ipynb @@ -305,6 +305,7 @@ " bdata.get_guide_edit_rate(\n", " editable_base_start=edit_quantification_start_pos,\n", " editable_base_end=edit_quantification_end_pos,\n", + " condition_col=condition_label,\n", " unsorted_condition_label=ctrl_cond,\n", " )\n", " be.qc.plot_guide_edit_rates(bdata)"