Skip to content

Commit

Permalink
Merge pull request #26 from fractal-napari-plugins-collection/1536_we…
Browse files Browse the repository at this point in the history
…ll_plates

Add support for matching 1536 well names
  • Loading branch information
jluethi authored Oct 10, 2024
2 parents 51b79a0 + aeada5a commit 7bda04f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 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]+)(\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]+)(\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]+)(\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,13 +414,24 @@ def _validate_wells(
"""
if wells is not None:
wells = [wells] if isinstance(wells, str) else wells
matches = [re.match(r"([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 = [
re.match(r"([A-Z]+)/(\d+)", well["path"])
re.match(r"([A-Z][a-z]*)/(\d+)", well["path"])
for well in metadata.attrs["plate"]["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
2 changes: 1 addition & 1 deletion src/napari_ome_zarr_navigator/roi_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,6 @@ def remove_existing_label_layers(viewer):
for layer in viewer.layers:
# FIXME: Generalize well name catching
if type(layer) == napari.layers.Labels and re.match(
r"[A-Z]\d+_*", layer.name
r"[A-Z][a-z]*\d+_*", layer.name
):
viewer.layers.remove(layer)

0 comments on commit 7bda04f

Please sign in to comment.