Skip to content

Commit

Permalink
add informative error message, fix iloc warning
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Apr 11, 2024
1 parent 7ec6a32 commit 064b87c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions bean/framework/ReporterScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions bean/mapping/GuideEditCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 064b87c

Please sign in to comment.