Skip to content

Commit

Permalink
Merge pull request #66 from TimMonko/measure_fix_tx_regex
Browse files Browse the repository at this point in the history
update measure container and add a new test
  • Loading branch information
TimMonko authored Sep 21, 2024
2 parents 40073c3 + 2e68ea0 commit 2e6382a
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/napari_ndev/_measure_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ def _init_id_regex_container(self):
def _init_tx_map_container(self):
"""Initialize the container for treatment map settings."""
self._tx_map_container = Container(layout='vertical')
self._tx_id = LineEdit(
self._update_tx_id_choices_button = PushButton(label='Update Treatment ID Choices')
self._tx_id = ComboBox(
label='Treatment ID',
choices=['id'],
value=None,
nullable=True,
tooltip='Usually, the treatment ID is the well ID or a unique identifier for each sample'
Expand All @@ -265,7 +267,12 @@ def _init_tx_map_container(self):
# TODO: Add example treatment regex result widget when example id string or id regex dict is changed

self._tx_map_container.extend(
[self._tx_id, self._tx_n_well, self._tx_dict]
[
self._update_tx_id_choices_button,
self._tx_id,
self._tx_n_well,
self._tx_dict,
]
)

def _init_grouping_container(self):
Expand Down Expand Up @@ -347,10 +354,20 @@ def _connect_events(self):
self._image_directory.changed.connect(self._update_image_choices)
self._label_directory.changed.connect(self._update_label_choices)
self._region_directory.changed.connect(self._update_region_choices)
self._update_tx_id_choices_button.clicked.connect(self._update_tx_id_choices)
self._measure_button.clicked.connect(self.batch_measure)
self._measured_data_path.changed.connect(self._update_grouping_cols)
self._group_measurements_button.clicked.connect(self.group_measurements)

def _update_tx_id_choices(self):
"""Update the choices for treatment ID."""
id_regex_dict = self._safe_dict_eval(self._id_regex_dict.value)
if id_regex_dict is None:
return
# add the keys to a list which already contains 'id'
regex_choices = list(id_regex_dict.keys())
self._tx_id.choices = ['id'] + regex_choices

def _update_grouping_cols(self):
"""Update the columns for grouping."""
if self._measured_data_path.value is None:
Expand Down
35 changes: 35 additions & 0 deletions src/napari_ndev/_tests/resources/Measure/.log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
2024-09-21 10:52:17,855 -
Label Image: Labels: Morphology
Intensity Channels: ['Labels: DAPI Class']
Num. Files: 4
Label Directory: C:\Users\timmo\napari-ndev\src\napari_ndev\_tests\resources\Measure\Labels
Image Directory: None
Region Directory: None
Output Directory: C:\Users\timmo\napari-ndev\src\napari_ndev\_tests\resources\Measure
ID Example: 2024-08-07 25x 24HIC NCOA4 647 FT 568 PHALL 488 DAPI OBL_2_1_P4-A9.ome__0__Image:0
ID Regex Dict: {
'scene': r'(P\d{1,3}-\w+).ome',
'well': r'-(\w+).ome',
'HIC': r'(\d{1,3})HIC',
'date': r'(\d{4}-\d{2}-\d{2})',
}

Tx ID: well
Tx N Well: 96
Tx Dict: {
'chelation':{
'Control': ['B1:C12'],
'50uM DFP': ['D1:E12'],
'100uM DFP': ['F1:G12'],
'100uM DFO': ['A1:A12', 'H1:H12'],
},
}

2024-09-21 10:52:17,858 - Processing file 2024-08-07 25x 24HIC NCOA4 647 FT 568 PHALL 488 DAPI OBL_2_1_P4-A9.ome.tiff
2024-09-21 10:52:17,921 - Processing scene 0
2024-09-21 10:52:18,082 - Processing file 2024-08-07 25x 24HIC NCOA4 647 FT 568 PHALL 488 DAPI OBL_56_55_P8-D9.ome.tiff
2024-09-21 10:52:18,139 - Processing scene 0
2024-09-21 10:52:18,303 - Processing file 2024-08-07 25x 48HIC NCOA4 647 FT 568 PHALL 488 DAPI OBL_36_35_P6-C9.ome.tiff
2024-09-21 10:52:18,361 - Processing scene 0
2024-09-21 10:52:18,520 - Processing file 2024-08-07 25x 72HIC NCOA4 647 FT 568 PHALL 488 DAPI OBL_22_21_P7-B9.ome.tiff
2024-09-21 10:52:18,584 - Processing scene 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
146 changes: 146 additions & 0 deletions src/napari_ndev/_tests/resources/Measure/measure_props_Morphology.csv

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions src/napari_ndev/_tests/test_measure_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,44 @@ def test_batch_measure_intensity(tmp_path):
]


def test_batch_measure_with_regex(tmp_path):
container = MeasureContainer()
label_directory = pathlib.Path(
'src/napari_ndev/_tests/resources/Measure/Labels'
)
output_folder = tmp_path / 'Output'
output_folder.mkdir()

container._label_directory.value = label_directory
container._id_regex_dict.value = r"""
{
'scene': r'(P\d{1,3}-\w+).ome',
'well': r'-(\w+).ome',
'HIC': r'(\d{1,3})HIC',
'date': r'(\d{4}-\d{2}-\d{2})',
}
"""
container._update_tx_id_choices_button.clicked()
assert container._tx_id.choices == (None, 'id','scene', 'well', 'HIC', 'date')

container._tx_id.value = 'well'
container._tx_n_well.value = 96
container._tx_dict.value = r"""
{
'chelation':{
'Control': ['B1:C12'],
'50uM DFP': ['D1:E12'],
'100uM DFP': ['F1:G12'],
'100uM DFO': ['A1:A12', 'H1:H12'],
},
}
"""

df = container.batch_measure()
assert 'scene' in df.columns
assert 'well' in df.columns
assert 'chelation' in df.columns

def test_group_measurements_no_agg_defaults():
container = MeasureContainer()
test_data_path = pathlib.Path(r'src/napari_ndev/_tests/resources/measure_props_Labels.csv')
Expand Down

0 comments on commit 2e6382a

Please sign in to comment.