From 064b87cd4c18342e90bb85f5959720b5c58682d3 Mon Sep 17 00:00:00 2001 From: jykr Date: Thu, 11 Apr 2024 15:02:21 -0400 Subject: [PATCH] add informative error message, fix iloc warning --- bean/framework/ReporterScreen.py | 13 ++++++++----- bean/mapping/GuideEditCounter.py | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bean/framework/ReporterScreen.py b/bean/framework/ReporterScreen.py index f8a4629..2ab6069 100755 --- a/bean/framework/ReporterScreen.py +++ b/bean/framework/ReporterScreen.py @@ -901,14 +901,17 @@ def _convert_obj_column_to_str(df, obj_column): return df -def concat(screens: Collection[ReporterScreen], *args, axis=1, **kwargs): +def concat(screens: Sequence[ReporterScreen], *args, axis: Literal[0, 1] = 1, **kwargs): """Concatenate multiple Screen objects.""" # TODO: var/obs info not concated if doesn't overlap # TODO: concat 2 times: allele_counts merging doesn't work? - if axis == 1 and not all( - screen.guides.index.equals(screens[0].guides.index) for screen in screens - ): - raise ValueError("Guide index doesn't match.") + same_index_as_0 = np.array( + [screen.guides.index.equals(screens[0].guides.index) for screen in screens] + ) + if axis == 1 and not all(same_index_as_0): + raise ValueError( + f"Guide index doesn't match: {[screens[0].guides.index] + [screens[i].guides.index for i in np.where(~same_index_as_0)[0]]}" + ) adata = ad.concat(screens, *args, axis=axis, **kwargs) if axis == 1: diff --git a/bean/mapping/GuideEditCounter.py b/bean/mapping/GuideEditCounter.py index 5f1f276..c2f1c2b 100755 --- a/bean/mapping/GuideEditCounter.py +++ b/bean/mapping/GuideEditCounter.py @@ -384,8 +384,8 @@ def _get_strand_offset_from_guide_index(self, guide_idx: int) -> Tuple[int, int] guide_strand = strand_str_to_int[strand] offset = _get_stranded_guide_offset( strand=guide_strand, - start_pos=self.screen.guides.start_pos.iloc[guide_idx], - guide_len=self.screen.guides.guide_len.iloc[guide_idx], + start_pos=self.screen.guides.iloc[guide_idx].start_pos, + guide_len=self.screen.guides.iloc[guide_idx].guide_len, ) else: guide_strand = 1 @@ -394,7 +394,7 @@ def _get_strand_offset_from_guide_index(self, guide_idx: int) -> Tuple[int, int] else: guide_strand = 1 if self.target_pos_col in self.screen.guides.columns: - offset = -(self.screen.guides[self.target_pos_col][guide_idx] - 1) + offset = -(self.screen.guides.iloc[guide_idx][self.target_pos_col] - 1) else: offset = 0 return (guide_strand, offset)