Skip to content

Commit

Permalink
Refactor well splitting into function & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jluethi committed Oct 10, 2024
1 parent 026ea49 commit aeada5a
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/napari_ome_zarr_navigator/img_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,8 @@ def filter_df(self):
self.well.value = wells[0]

def load_roi(self):
matches = [
re.match(r"([A-Z][a-z]*)(\d+)", well) for well in self.well.value
]
row_alpha = [m.group(1) for m in matches]
col_str = [m.group(2) for m in matches]
if len(row_alpha) != 1 or len(col_str) != 1:
wells = get_row_cols(self.well.value)
if len(wells) != 1:
msg = "Please select a single well."
logger.info(msg)
napari.utils.notifications.show_info(msg)
Expand All @@ -234,8 +230,8 @@ def load_roi(self):
self.roi_loader = ROILoaderPlate(
self.viewer,
str(self.zarr_root),
row_alpha[0],
col_str[0],
wells[0][0],
wells[0][1],
self,
self.is_plate,
)
Expand All @@ -247,10 +243,7 @@ def load_roi(self):
)

def load_default_roi(self):
matches = [
re.match(r"([A-Z][a-z]*)(\d+)", well) for well in self.well.value
]
wells = [(m.group(1), m.group(2)) for m in matches]
wells = get_row_cols(self.well.value)

# Loop over all selected wells
for well in wells:
Expand Down Expand Up @@ -281,14 +274,11 @@ def load_default_roi(self):
)

def go_to_well(self):
matches = [
re.match(r"([A-Z][a-z]*)(\d+)", well) for well in self.well.value
]
wells = [(m.group(1), m.group(2)) for m in matches]
wells = get_row_cols(self.well.value)

for layer in self.viewer.layers:
if type(layer) == napari.layers.Shapes and re.match(
r"([a-z]*)(\d+)", layer.name
r"([A-Z][a-z]*)(\d+)", layer.name
):
self.viewer.layers.remove(layer)

Expand Down Expand Up @@ -424,8 +414,7 @@ def _validate_wells(
"""
if wells is not None:
wells = [wells] if isinstance(wells, str) else wells
matches = [re.match(r"([A-Z][a-z]*)(\d+)", well) for well in wells]
wells = {(m.group(1), m.group(2)) for m in matches}
wells = get_row_cols(wells)
else:
with zarr.open(zarr_url) as metadata:
matches = [
Expand All @@ -434,3 +423,15 @@ def _validate_wells(
]
wells = {(m.group(1), m.group(2)) for m in matches}
return wells


def get_row_cols(well_list):
"""
Given a well list, provide a list of rows & columns
The well list i
"""
matches = [re.match(r"([A-Z][a-z]*)(\d+)", well) for well in well_list]
wells = [(m.group(1), m.group(2)) for m in matches]
return wells

0 comments on commit aeada5a

Please sign in to comment.