Skip to content

Commit

Permalink
fix string to allele conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Oct 16, 2023
1 parent 3205411 commit ed99b29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions bean/framework/Edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def from_str(cls, edit_str): # pos:strand:start>end
def match_str(cls, edit_str):
if isinstance(edit_str, Edit):
return True
pattern = r"((chr)?\d+:)?-?\d+:-?\d+:[+-]:[A-Z*-]>[A-Z*-]"
pattern = r"(((chr)?\d+|nan):)?-?\d+:-?\d+:[+-]:[A-Z*-]>[A-Z*-]"
pattern2 = r"[\w*]!-?\d+:-?\d+:[+-]:[A-Z*-]>[A-Z*-]"
return re.fullmatch(pattern, edit_str) or re.fullmatch(pattern2, edit_str)

Expand Down Expand Up @@ -151,9 +151,11 @@ def from_str(cls, allele_str): # pos:strand:start>end
for edit_str in allele_str.split(","):
edit = Edit.from_str(edit_str)
edits.add(edit)
except ValueError:
except ValueError as e:
if allele_str.strip() == "":
return cls(None)
else:
raise e
return cls(edits)

@classmethod
Expand Down
7 changes: 5 additions & 2 deletions bean/framework/ReporterScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,10 @@ def concat(screens: Collection[ReporterScreen], *args, axis=1, **kwargs):

if max(len(screen_uns_df) for screen_uns_df in screen_uns_dfs) == 0:
continue
merge_on = screen[0].uns[k].columns[:2].tolist()
if "guide_reporter_allele" in k:
merge_on = screen[0].uns[k].columns[:3].tolist()
else:
merge_on = screen[0].uns[k].columns[:2].tolist()
try:
edit_cls = type(screens[0].uns[k][merge_on[1]][0])
except IndexError:
Expand All @@ -920,7 +923,7 @@ def concat(screens: Collection[ReporterScreen], *args, axis=1, **kwargs):
for i, screen in enumerate(screens):
if screen.uns[k][merge_on].duplicated().any():
raise ValueError(
f"{i}-th ReporterScreen .uns['{k}'] has duplicated row. Aborting."
f"{i}-th ReporterScreen .uns['{k}'] has duplicated row. Aborting.: {screen.uns[k][merge_on].loc[screen.uns[k][merge_on].duplicated()]}"
)
if i == 0:
adata.uns[k] = screen.uns[k]
Expand Down

0 comments on commit ed99b29

Please sign in to comment.