celldetective 1.4.2__py3-none-any.whl → 1.5.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- celldetective/__init__.py +25 -0
- celldetective/__main__.py +62 -43
- celldetective/_version.py +1 -1
- celldetective/extra_properties.py +477 -399
- celldetective/filters.py +192 -97
- celldetective/gui/InitWindow.py +541 -411
- celldetective/gui/__init__.py +0 -15
- celldetective/gui/about.py +44 -39
- celldetective/gui/analyze_block.py +120 -84
- celldetective/gui/base/__init__.py +0 -0
- celldetective/gui/base/channel_norm_generator.py +335 -0
- celldetective/gui/base/components.py +249 -0
- celldetective/gui/base/feature_choice.py +92 -0
- celldetective/gui/base/figure_canvas.py +52 -0
- celldetective/gui/base/list_widget.py +133 -0
- celldetective/gui/{styles.py → base/styles.py} +92 -36
- celldetective/gui/base/utils.py +33 -0
- celldetective/gui/base_annotator.py +900 -767
- celldetective/gui/classifier_widget.py +6 -22
- celldetective/gui/configure_new_exp.py +777 -671
- celldetective/gui/control_panel.py +635 -524
- celldetective/gui/dynamic_progress.py +449 -0
- celldetective/gui/event_annotator.py +2023 -1662
- celldetective/gui/generic_signal_plot.py +1292 -944
- celldetective/gui/gui_utils.py +899 -1289
- celldetective/gui/interactions_block.py +658 -0
- celldetective/gui/interactive_timeseries_viewer.py +447 -0
- celldetective/gui/json_readers.py +48 -15
- celldetective/gui/layouts/__init__.py +5 -0
- celldetective/gui/layouts/background_model_free_layout.py +537 -0
- celldetective/gui/layouts/channel_offset_layout.py +134 -0
- celldetective/gui/layouts/local_correction_layout.py +91 -0
- celldetective/gui/layouts/model_fit_layout.py +372 -0
- celldetective/gui/layouts/operation_layout.py +68 -0
- celldetective/gui/layouts/protocol_designer_layout.py +96 -0
- celldetective/gui/pair_event_annotator.py +3130 -2435
- celldetective/gui/plot_measurements.py +586 -267
- celldetective/gui/plot_signals_ui.py +724 -506
- celldetective/gui/preprocessing_block.py +395 -0
- celldetective/gui/process_block.py +1678 -1831
- celldetective/gui/seg_model_loader.py +580 -473
- celldetective/gui/settings/__init__.py +0 -7
- celldetective/gui/settings/_cellpose_model_params.py +181 -0
- celldetective/gui/settings/_event_detection_model_params.py +95 -0
- celldetective/gui/settings/_segmentation_model_params.py +159 -0
- celldetective/gui/settings/_settings_base.py +77 -65
- celldetective/gui/settings/_settings_event_model_training.py +752 -526
- celldetective/gui/settings/_settings_measurements.py +1133 -964
- celldetective/gui/settings/_settings_neighborhood.py +574 -488
- celldetective/gui/settings/_settings_segmentation_model_training.py +779 -564
- celldetective/gui/settings/_settings_signal_annotator.py +329 -305
- celldetective/gui/settings/_settings_tracking.py +1304 -1094
- celldetective/gui/settings/_stardist_model_params.py +98 -0
- celldetective/gui/survival_ui.py +422 -312
- celldetective/gui/tableUI.py +1665 -1701
- celldetective/gui/table_ops/_maths.py +295 -0
- celldetective/gui/table_ops/_merge_groups.py +140 -0
- celldetective/gui/table_ops/_merge_one_hot.py +95 -0
- celldetective/gui/table_ops/_query_table.py +43 -0
- celldetective/gui/table_ops/_rename_col.py +44 -0
- celldetective/gui/thresholds_gui.py +382 -179
- celldetective/gui/viewers/__init__.py +0 -0
- celldetective/gui/viewers/base_viewer.py +700 -0
- celldetective/gui/viewers/channel_offset_viewer.py +331 -0
- celldetective/gui/viewers/contour_viewer.py +394 -0
- celldetective/gui/viewers/size_viewer.py +153 -0
- celldetective/gui/viewers/spot_detection_viewer.py +341 -0
- celldetective/gui/viewers/threshold_viewer.py +309 -0
- celldetective/gui/workers.py +403 -126
- celldetective/log_manager.py +92 -0
- celldetective/measure.py +1895 -1478
- celldetective/napari/__init__.py +0 -0
- celldetective/napari/utils.py +1025 -0
- celldetective/neighborhood.py +1914 -1448
- celldetective/preprocessing.py +1620 -1220
- celldetective/processes/__init__.py +0 -0
- celldetective/processes/background_correction.py +271 -0
- celldetective/processes/compute_neighborhood.py +894 -0
- celldetective/processes/detect_events.py +246 -0
- celldetective/processes/downloader.py +137 -0
- celldetective/processes/measure_cells.py +565 -0
- celldetective/processes/segment_cells.py +760 -0
- celldetective/processes/track_cells.py +435 -0
- celldetective/processes/train_segmentation_model.py +694 -0
- celldetective/processes/train_signal_model.py +265 -0
- celldetective/processes/unified_process.py +292 -0
- celldetective/regionprops/_regionprops.py +358 -317
- celldetective/relative_measurements.py +987 -710
- celldetective/scripts/measure_cells.py +313 -212
- celldetective/scripts/measure_relative.py +90 -46
- celldetective/scripts/segment_cells.py +165 -104
- celldetective/scripts/segment_cells_thresholds.py +96 -68
- celldetective/scripts/track_cells.py +198 -149
- celldetective/scripts/train_segmentation_model.py +324 -201
- celldetective/scripts/train_signal_model.py +87 -45
- celldetective/segmentation.py +844 -749
- celldetective/signals.py +3514 -2861
- celldetective/tracking.py +30 -15
- celldetective/utils/__init__.py +0 -0
- celldetective/utils/cellpose_utils/__init__.py +133 -0
- celldetective/utils/color_mappings.py +42 -0
- celldetective/utils/data_cleaning.py +630 -0
- celldetective/utils/data_loaders.py +450 -0
- celldetective/utils/dataset_helpers.py +207 -0
- celldetective/utils/downloaders.py +235 -0
- celldetective/utils/event_detection/__init__.py +8 -0
- celldetective/utils/experiment.py +1782 -0
- celldetective/utils/image_augmenters.py +308 -0
- celldetective/utils/image_cleaning.py +74 -0
- celldetective/utils/image_loaders.py +926 -0
- celldetective/utils/image_transforms.py +335 -0
- celldetective/utils/io.py +62 -0
- celldetective/utils/mask_cleaning.py +348 -0
- celldetective/utils/mask_transforms.py +5 -0
- celldetective/utils/masks.py +184 -0
- celldetective/utils/maths.py +351 -0
- celldetective/utils/model_getters.py +325 -0
- celldetective/utils/model_loaders.py +296 -0
- celldetective/utils/normalization.py +380 -0
- celldetective/utils/parsing.py +465 -0
- celldetective/utils/plots/__init__.py +0 -0
- celldetective/utils/plots/regression.py +53 -0
- celldetective/utils/resources.py +34 -0
- celldetective/utils/stardist_utils/__init__.py +104 -0
- celldetective/utils/stats.py +90 -0
- celldetective/utils/types.py +21 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/METADATA +1 -1
- celldetective-1.5.0b1.dist-info/RECORD +187 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/WHEEL +1 -1
- tests/gui/test_new_project.py +129 -117
- tests/gui/test_project.py +127 -79
- tests/test_filters.py +39 -15
- tests/test_notebooks.py +8 -0
- tests/test_tracking.py +232 -13
- tests/test_utils.py +123 -77
- celldetective/gui/base_components.py +0 -23
- celldetective/gui/layouts.py +0 -1602
- celldetective/gui/processes/compute_neighborhood.py +0 -594
- celldetective/gui/processes/downloader.py +0 -111
- celldetective/gui/processes/measure_cells.py +0 -360
- celldetective/gui/processes/segment_cells.py +0 -499
- celldetective/gui/processes/track_cells.py +0 -303
- celldetective/gui/processes/train_segmentation_model.py +0 -270
- celldetective/gui/processes/train_signal_model.py +0 -108
- celldetective/gui/table_ops/merge_groups.py +0 -118
- celldetective/gui/viewers.py +0 -1354
- celldetective/io.py +0 -3663
- celldetective/utils.py +0 -3108
- celldetective-1.4.2.dist-info/RECORD +0 -123
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/entry_points.txt +0 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/licenses/LICENSE +0 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/top_level.txt +0 -0
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
from PyQt5.QtWidgets import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
from PyQt5.QtWidgets import (
|
|
2
|
+
QGridLayout,
|
|
3
|
+
QComboBox,
|
|
4
|
+
QVBoxLayout,
|
|
5
|
+
QLabel,
|
|
6
|
+
QLineEdit,
|
|
7
|
+
QHBoxLayout,
|
|
8
|
+
QRadioButton,
|
|
9
|
+
QFileDialog,
|
|
10
|
+
QPushButton,
|
|
11
|
+
QMessageBox,
|
|
12
|
+
)
|
|
13
|
+
from PyQt5.QtCore import Qt, QSize, QTimer
|
|
14
|
+
from celldetective.gui.base.components import generic_message
|
|
15
|
+
from celldetective.gui.base.utils import center_window
|
|
16
|
+
from celldetective.gui.base.channel_norm_generator import ChannelNormGenerator
|
|
17
|
+
from celldetective.gui.base.components import CelldetectiveWidget
|
|
6
18
|
from PyQt5.QtGui import QDoubleValidator
|
|
7
19
|
from superqt.fonticon import icon
|
|
8
20
|
from fonticon_mdi6 import MDI6
|
|
@@ -11,475 +23,570 @@ from glob import glob
|
|
|
11
23
|
import os
|
|
12
24
|
import json
|
|
13
25
|
import shutil
|
|
14
|
-
from celldetective.gui import Styles
|
|
15
26
|
import gc
|
|
16
|
-
from cellpose.models import CellposeModel
|
|
17
27
|
|
|
18
28
|
|
|
19
29
|
class SegmentationModelLoader(CelldetectiveWidget):
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
30
|
+
"""
|
|
31
|
+
Upload a segmentation model or define a Threshold pipeline.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, parent_window):
|
|
35
|
+
|
|
36
|
+
super().__init__()
|
|
37
|
+
self.parent_window = parent_window
|
|
38
|
+
self.mode = self.parent_window.mode
|
|
39
|
+
self.target_folder = f"segmentation_{self.mode}"
|
|
40
|
+
self.setWindowTitle("Upload model")
|
|
41
|
+
self.generate_content()
|
|
42
|
+
|
|
43
|
+
def generate_content(self):
|
|
44
|
+
|
|
45
|
+
self.layout = QGridLayout(self)
|
|
46
|
+
self.layout.addWidget(QLabel("Select:"), 0, 0, 1, 1)
|
|
47
|
+
self.layout.setSpacing(5)
|
|
48
|
+
|
|
49
|
+
option_layout = QHBoxLayout()
|
|
50
|
+
option_layout.setContentsMargins(10, 10, 10, 10)
|
|
51
|
+
|
|
52
|
+
# Create radio buttons
|
|
53
|
+
self.stardist_button = QRadioButton("StarDist")
|
|
54
|
+
# self.stardist_button.setIcon(QIcon(abs_path+f"/icons/star.png"))
|
|
55
|
+
|
|
56
|
+
self.cellpose_button = QRadioButton("Cellpose")
|
|
57
|
+
# self.cellpose_button.setIcon(QIcon(abs_path+f"/icons/cellpose_utils.png"))
|
|
58
|
+
|
|
59
|
+
self.threshold_button = QRadioButton("Threshold")
|
|
60
|
+
|
|
61
|
+
option_layout.addWidget(self.threshold_button)
|
|
62
|
+
option_layout.addWidget(self.stardist_button)
|
|
63
|
+
option_layout.addWidget(self.cellpose_button)
|
|
64
|
+
|
|
65
|
+
self.layout.addLayout(option_layout, 1, 0, 1, 2, alignment=Qt.AlignCenter)
|
|
66
|
+
self.generate_base_block()
|
|
67
|
+
self.layout.addLayout(self.base_block, 2, 0, 1, 2)
|
|
68
|
+
# self.combos = self.channel_layout.channel_cbs
|
|
69
|
+
# self.cb_labels = self.channel_layout.channel_labels
|
|
70
|
+
|
|
71
|
+
self.generate_cellpose_options()
|
|
72
|
+
self.layout.addLayout(self.cellpose_block, 3, 0, 1, 2)
|
|
73
|
+
self.generate_threshold_options()
|
|
74
|
+
|
|
75
|
+
# Create file dialog
|
|
76
|
+
self.file_dialog = QFileDialog()
|
|
77
|
+
|
|
78
|
+
# Create button to open file dialog
|
|
79
|
+
self.open_dialog_button = QPushButton("Choose File")
|
|
80
|
+
self.open_dialog_button.clicked.connect(self.showDialog)
|
|
81
|
+
self.file_label = QLabel("No file chosen", self)
|
|
82
|
+
self.layout.addWidget(self.open_dialog_button, 9, 0, 1, 1)
|
|
83
|
+
self.layout.addWidget(self.file_label, 9, 1, 1, 1)
|
|
84
|
+
|
|
85
|
+
self.merge_lbl = QLabel("Merging option: ")
|
|
86
|
+
self.merge_cb = QComboBox()
|
|
87
|
+
self.merge_cb.addItems(["OR"])
|
|
88
|
+
merge_hbox = QHBoxLayout()
|
|
89
|
+
merge_hbox.addWidget(self.merge_lbl, 33)
|
|
90
|
+
merge_hbox.addWidget(self.merge_cb, 66)
|
|
91
|
+
self.layout.addLayout(merge_hbox, 10, 0, 1, 2)
|
|
92
|
+
self.merge_lbl.hide()
|
|
93
|
+
self.merge_cb.hide()
|
|
94
|
+
|
|
95
|
+
self.upload_button = QPushButton("Upload")
|
|
96
|
+
self.upload_button.clicked.connect(self.upload_model)
|
|
97
|
+
self.upload_button.setIcon(icon(MDI6.upload, color="white"))
|
|
98
|
+
self.upload_button.setIconSize(QSize(25, 25))
|
|
99
|
+
self.upload_button.setStyleSheet(self.button_style_sheet)
|
|
100
|
+
self.upload_button.setEnabled(False)
|
|
101
|
+
self.layout.addWidget(self.upload_button, 11, 0, 1, 1)
|
|
102
|
+
|
|
103
|
+
self.base_block_options = [
|
|
104
|
+
self.calibration_label,
|
|
105
|
+
self.spatial_calib_le,
|
|
106
|
+
*self.channel_layout.channel_cbs,
|
|
107
|
+
*self.channel_layout.channel_labels,
|
|
108
|
+
*self.channel_layout.normalization_mode_btns,
|
|
109
|
+
*self.channel_layout.normalization_clip_btns,
|
|
110
|
+
*self.channel_layout.normalization_min_value_lbl,
|
|
111
|
+
*self.channel_layout.normalization_min_value_le,
|
|
112
|
+
*self.channel_layout.normalization_max_value_lbl,
|
|
113
|
+
*self.channel_layout.normalization_max_value_le,
|
|
114
|
+
self.channel_layout.add_col_btn,
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
self.stardist_button.toggled.connect(self.show_seg_options)
|
|
118
|
+
self.cellpose_button.toggled.connect(self.show_seg_options)
|
|
119
|
+
self.threshold_button.toggled.connect(self.show_seg_options)
|
|
120
|
+
|
|
121
|
+
for cb in self.channel_layout.channel_cbs:
|
|
122
|
+
cb.activated.connect(self.unlock_upload)
|
|
123
|
+
|
|
124
|
+
self.setLayout(self.layout)
|
|
125
|
+
|
|
126
|
+
self.threshold_button.setChecked(True)
|
|
127
|
+
self.show()
|
|
128
|
+
|
|
129
|
+
def unlock_upload(self):
|
|
130
|
+
if self.stardist_button.isChecked():
|
|
131
|
+
if np.any(
|
|
132
|
+
[c.currentText() != "--" for c in self.channel_layout.channel_cbs]
|
|
133
|
+
):
|
|
134
|
+
self.upload_button.setEnabled(True)
|
|
135
|
+
else:
|
|
136
|
+
self.upload_button.setEnabled(False)
|
|
137
|
+
elif self.cellpose_button.isChecked():
|
|
138
|
+
if np.any(
|
|
139
|
+
[c.currentText() != "--" for c in self.channel_layout.channel_cbs]
|
|
140
|
+
):
|
|
141
|
+
self.upload_button.setEnabled(True)
|
|
142
|
+
else:
|
|
143
|
+
self.upload_button.setEnabled(False)
|
|
144
|
+
|
|
145
|
+
def generate_base_block(self):
|
|
146
|
+
"""
|
|
147
|
+
Create widgets common to StarDist and Cellpose.
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
self.base_block = QVBoxLayout()
|
|
151
|
+
|
|
152
|
+
pixel_calib_layout = QHBoxLayout()
|
|
153
|
+
self.calibration_label = QLabel("input spatial\ncalibration: ")
|
|
154
|
+
self.spatial_calib_le = QLineEdit("0,1")
|
|
155
|
+
self.qdv = QDoubleValidator(
|
|
156
|
+
0.0,
|
|
157
|
+
np.amax(
|
|
158
|
+
[
|
|
159
|
+
self.parent_window.parent_window.shape_x,
|
|
160
|
+
self.parent_window.parent_window.shape_y,
|
|
161
|
+
]
|
|
162
|
+
),
|
|
163
|
+
8,
|
|
164
|
+
notation=QDoubleValidator.StandardNotation,
|
|
165
|
+
)
|
|
166
|
+
self.spatial_calib_le.setValidator(self.qdv)
|
|
167
|
+
pixel_calib_layout.addWidget(self.calibration_label, 30)
|
|
168
|
+
pixel_calib_layout.addWidget(self.spatial_calib_le, 70)
|
|
169
|
+
self.base_block.addLayout(pixel_calib_layout)
|
|
170
|
+
|
|
171
|
+
self.channel_layout = ChannelNormGenerator(
|
|
172
|
+
self, mode="channels", init_n_channels=2
|
|
173
|
+
)
|
|
174
|
+
self.channel_layout.setContentsMargins(0, 0, 0, 0)
|
|
175
|
+
self.base_block.addLayout(self.channel_layout)
|
|
176
|
+
|
|
177
|
+
def generate_cellpose_options(self):
|
|
178
|
+
"""
|
|
179
|
+
Create Cellpose specific fields to use the model properly when calling it from the app.
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
self.cellpose_block = QVBoxLayout()
|
|
183
|
+
self.cp_diameter_label = QLabel("cell\ndiameter: ")
|
|
184
|
+
self.cp_diameter_le = QLineEdit("30,0")
|
|
185
|
+
self.cp_diameter_le.setValidator(self.qdv)
|
|
186
|
+
diam_hbox = QHBoxLayout()
|
|
187
|
+
diam_hbox.addWidget(self.cp_diameter_label, 30)
|
|
188
|
+
diam_hbox.addWidget(self.cp_diameter_le, 70)
|
|
189
|
+
self.cellpose_block.addLayout(diam_hbox)
|
|
190
|
+
|
|
191
|
+
qdv_prob = QDoubleValidator(
|
|
192
|
+
-6, 6, 8, notation=QDoubleValidator.StandardNotation
|
|
193
|
+
)
|
|
194
|
+
self.cp_cellprob_label = QLabel("cellprob\nthreshold: ")
|
|
195
|
+
self.cp_cellprob_le = QLineEdit("0,0")
|
|
196
|
+
self.cp_cellprob_le.setValidator(qdv_prob)
|
|
197
|
+
cellprob_hbox = QHBoxLayout()
|
|
198
|
+
cellprob_hbox.addWidget(self.cp_cellprob_label, 30)
|
|
199
|
+
cellprob_hbox.addWidget(self.cp_cellprob_le, 70)
|
|
200
|
+
self.cellpose_block.addLayout(cellprob_hbox)
|
|
201
|
+
|
|
202
|
+
self.cp_flow_label = QLabel("flow threshold: ")
|
|
203
|
+
self.cp_flow_le = QLineEdit("0,4")
|
|
204
|
+
self.cp_flow_le.setValidator(qdv_prob)
|
|
205
|
+
flow_hbox = QHBoxLayout()
|
|
206
|
+
flow_hbox.addWidget(self.cp_flow_label, 30)
|
|
207
|
+
flow_hbox.addWidget(self.cp_flow_le, 70)
|
|
208
|
+
self.cellpose_block.addLayout(flow_hbox)
|
|
209
|
+
|
|
210
|
+
self.cellpose_options = [
|
|
211
|
+
self.cp_diameter_label,
|
|
212
|
+
self.cp_diameter_le,
|
|
213
|
+
self.cp_cellprob_label,
|
|
214
|
+
self.cp_cellprob_le,
|
|
215
|
+
self.cp_flow_label,
|
|
216
|
+
self.cp_flow_le,
|
|
217
|
+
]
|
|
218
|
+
for c in self.cellpose_options:
|
|
219
|
+
c.hide()
|
|
220
|
+
|
|
221
|
+
def generate_threshold_options(self):
|
|
222
|
+
"""
|
|
223
|
+
Show the threshold config pipeline button.
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
self.threshold_config_button = QPushButton("Threshold Config Wizard")
|
|
227
|
+
self.threshold_config_button.setIcon(icon(MDI6.auto_fix, color="#1565c0"))
|
|
228
|
+
self.threshold_config_button.setIconSize(QSize(20, 20))
|
|
229
|
+
self.threshold_config_button.setVisible(False)
|
|
230
|
+
self.threshold_config_button.setStyleSheet(self.button_style_sheet_2)
|
|
231
|
+
self.threshold_config_button.clicked.connect(self.open_threshold_config_wizard)
|
|
232
|
+
self.layout.addWidget(self.threshold_config_button, 3, 0, 1, 2)
|
|
233
|
+
self.threshold_config_button.hide()
|
|
234
|
+
|
|
235
|
+
def showDialog(self):
|
|
236
|
+
"""
|
|
237
|
+
Import the model in the proper folder.
|
|
238
|
+
"""
|
|
239
|
+
|
|
240
|
+
# Set the file dialog according to the option chosen
|
|
241
|
+
if self.stardist_button.isChecked():
|
|
242
|
+
self.seg_mode = "stardist"
|
|
243
|
+
self.file_dialog.setFileMode(QFileDialog.Directory)
|
|
244
|
+
elif self.cellpose_button.isChecked():
|
|
245
|
+
self.seg_mode = "cellpose"
|
|
246
|
+
self.file_dialog.setFileMode(QFileDialog.ExistingFile)
|
|
247
|
+
elif self.threshold_button.isChecked():
|
|
248
|
+
self.seg_mode = "threshold"
|
|
249
|
+
self.file_dialog.setFileMode(QFileDialog.ExistingFile)
|
|
250
|
+
|
|
251
|
+
# If accepted check validity of data
|
|
252
|
+
if self.seg_mode != "threshold":
|
|
253
|
+
if self.file_dialog.exec_() == QFileDialog.Accepted:
|
|
254
|
+
self.filename = self.file_dialog.selectedFiles()[0]
|
|
255
|
+
if self.seg_mode == "stardist":
|
|
256
|
+
subfiles = glob(self.filename + "/*")
|
|
257
|
+
subfiles = [s.replace("\\", "/") for s in subfiles]
|
|
258
|
+
if self.filename + "/thresholds.json" in subfiles:
|
|
259
|
+
self.file_label.setText(self.filename.split("/")[-1])
|
|
260
|
+
self.modelname = self.filename.split("/")[-1]
|
|
261
|
+
self.destination = (
|
|
262
|
+
os.path.split(os.path.dirname(os.path.realpath(__file__)))[
|
|
263
|
+
0
|
|
264
|
+
]
|
|
265
|
+
+ f"/models/{self.target_folder}/"
|
|
266
|
+
+ self.modelname
|
|
267
|
+
)
|
|
268
|
+
self.folder_dest = self.destination
|
|
269
|
+
else:
|
|
270
|
+
generic_message(
|
|
271
|
+
"StarDist model not recognized... Please ensure that it contains a thresholds.json file or that it is a valid StarDist model..."
|
|
272
|
+
)
|
|
273
|
+
return None
|
|
274
|
+
|
|
275
|
+
if self.seg_mode == "cellpose":
|
|
276
|
+
self.file_label.setText(self.filename.split("/")[-1])
|
|
277
|
+
self.modelname = self.filename.split("/")[-1]
|
|
278
|
+
print(f"Transferring Cellpose model {self.filename}...")
|
|
279
|
+
self.folder_dest = (
|
|
280
|
+
os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
|
|
281
|
+
+ f"/models/{self.target_folder}/"
|
|
282
|
+
+ self.modelname
|
|
283
|
+
)
|
|
284
|
+
self.destination = self.folder_dest + f"/{self.modelname}"
|
|
285
|
+
|
|
286
|
+
else:
|
|
287
|
+
start_dir = self.parent_window.exp_dir
|
|
288
|
+
if os.path.isdir(os.path.join(start_dir, "configs")):
|
|
289
|
+
start_dir = os.path.join(start_dir, "configs")
|
|
290
|
+
|
|
291
|
+
self.filename, _ = QFileDialog.getOpenFileNames(
|
|
292
|
+
None,
|
|
293
|
+
"Load threshold configuration(s)...",
|
|
294
|
+
start_dir,
|
|
295
|
+
"Json Configs (*.json)",
|
|
296
|
+
)
|
|
297
|
+
if self.filename:
|
|
298
|
+
n_files = len(self.filename)
|
|
299
|
+
print(f"You loaded {n_files} threshold configuration files...")
|
|
300
|
+
for i, filename in enumerate(self.filename):
|
|
301
|
+
print(f"Config {i}: ", filename, "...")
|
|
302
|
+
|
|
303
|
+
if n_files == 1:
|
|
304
|
+
self.merge_cb.hide()
|
|
305
|
+
self.merge_lbl.hide()
|
|
306
|
+
self.file_label.setText(self.filename[0].split("/")[-1])
|
|
307
|
+
else:
|
|
308
|
+
generic_message(
|
|
309
|
+
"You selected more than one pipeline. Please set a merging procedure for the resulting masks..."
|
|
310
|
+
)
|
|
311
|
+
self.merge_cb.show()
|
|
312
|
+
self.merge_lbl.show()
|
|
313
|
+
self.file_label.setText(f"{n_files} configs loaded...")
|
|
314
|
+
|
|
315
|
+
def show_seg_options(self):
|
|
316
|
+
"""
|
|
317
|
+
Show the relevant widgets, mask the others.
|
|
318
|
+
"""
|
|
319
|
+
|
|
320
|
+
self.filename = None
|
|
321
|
+
self.file_label.setText("No file chosen")
|
|
322
|
+
self.base_block_options = [
|
|
323
|
+
self.calibration_label,
|
|
324
|
+
self.spatial_calib_le,
|
|
325
|
+
*self.channel_layout.channel_cbs,
|
|
326
|
+
*self.channel_layout.channel_labels,
|
|
327
|
+
*self.channel_layout.normalization_mode_btns,
|
|
328
|
+
*self.channel_layout.normalization_clip_btns,
|
|
329
|
+
*self.channel_layout.normalization_min_value_lbl,
|
|
330
|
+
*self.channel_layout.normalization_min_value_le,
|
|
331
|
+
*self.channel_layout.normalization_max_value_lbl,
|
|
332
|
+
*self.channel_layout.normalization_max_value_le,
|
|
333
|
+
self.channel_layout.add_col_btn,
|
|
334
|
+
]
|
|
335
|
+
|
|
336
|
+
if self.cellpose_button.isChecked():
|
|
337
|
+
self.spatial_calib_le.setToolTip(
|
|
338
|
+
"Cellpose rescales the images such that the cells are 30.0 pixels. You can compute the scale from the training data as\n(pixel calibration [µm] in training images)*(cell diameter [px] in training images)/(30 [px]).\nIf you pass images with a different calibration to the model, they will be rescaled automatically.\nThe rescaling is ignored if you pass a diameter different from 30 px below."
|
|
339
|
+
)
|
|
340
|
+
self.channel_layout.channel_labels[0].setText("cyto: ")
|
|
341
|
+
self.channel_layout.channel_labels[1].setText("nuclei: ")
|
|
342
|
+
for c in [self.threshold_config_button, self.merge_lbl, self.merge_cb]:
|
|
343
|
+
c.hide()
|
|
344
|
+
for c in self.cellpose_options + self.base_block_options:
|
|
345
|
+
c.show()
|
|
346
|
+
self.unlock_upload()
|
|
347
|
+
elif self.stardist_button.isChecked():
|
|
348
|
+
self.spatial_calib_le.setToolTip("")
|
|
349
|
+
self.channel_layout.channel_labels[0].setText("channel 1: ")
|
|
350
|
+
self.channel_layout.channel_labels[1].setText("channel 2: ")
|
|
351
|
+
for c in self.base_block_options:
|
|
352
|
+
c.show()
|
|
353
|
+
for c in self.cellpose_options + [
|
|
354
|
+
self.threshold_config_button,
|
|
355
|
+
self.merge_lbl,
|
|
356
|
+
self.merge_cb,
|
|
357
|
+
]:
|
|
358
|
+
c.hide()
|
|
359
|
+
self.unlock_upload()
|
|
360
|
+
else:
|
|
361
|
+
for c in self.base_block_options + self.cellpose_options:
|
|
362
|
+
c.hide()
|
|
363
|
+
self.threshold_config_button.show()
|
|
364
|
+
self.upload_button.setEnabled(True)
|
|
365
|
+
|
|
366
|
+
self.resize(self.sizeHint())
|
|
367
|
+
# self.adjustSize()
|
|
368
|
+
|
|
369
|
+
def upload_model(self):
|
|
370
|
+
"""
|
|
371
|
+
Upload the model.
|
|
372
|
+
"""
|
|
373
|
+
|
|
374
|
+
channels = []
|
|
375
|
+
for i in range(len(self.channel_layout.channel_cbs)):
|
|
376
|
+
channels.append(self.channel_layout.channel_cbs[i].currentText())
|
|
377
|
+
|
|
378
|
+
if self.file_label.text() == "No file chosen":
|
|
379
|
+
generic_message("Please select a model first...")
|
|
380
|
+
return None
|
|
381
|
+
|
|
382
|
+
if not self.threshold_button.isChecked():
|
|
383
|
+
|
|
384
|
+
if self.stardist_button.isChecked():
|
|
385
|
+
|
|
386
|
+
try:
|
|
387
|
+
shutil.copytree(self.filename, self.destination)
|
|
388
|
+
except FileExistsError:
|
|
389
|
+
generic_message(
|
|
390
|
+
"A model with the same name already exists in the models folder. Please rename it."
|
|
391
|
+
)
|
|
392
|
+
return None
|
|
393
|
+
|
|
394
|
+
elif self.cellpose_button.isChecked():
|
|
395
|
+
|
|
396
|
+
try:
|
|
397
|
+
if not os.path.exists(self.folder_dest):
|
|
398
|
+
os.mkdir(self.folder_dest)
|
|
399
|
+
shutil.copy(self.filename, self.destination)
|
|
400
|
+
except FileExistsError:
|
|
401
|
+
generic_message(
|
|
402
|
+
"A model with the same name already exists in the models folder. Please rename it."
|
|
403
|
+
)
|
|
404
|
+
return None
|
|
405
|
+
try:
|
|
406
|
+
from cellpose.models import CellposeModel
|
|
407
|
+
|
|
408
|
+
model = CellposeModel(
|
|
409
|
+
pretrained_model=self.destination,
|
|
410
|
+
model_type=None,
|
|
411
|
+
nchan=len(channels),
|
|
412
|
+
)
|
|
413
|
+
self.scale_model = model.diam_mean
|
|
414
|
+
print(f"{self.scale_model=}")
|
|
415
|
+
del model
|
|
416
|
+
gc.collect()
|
|
417
|
+
except Exception as e:
|
|
418
|
+
print(e)
|
|
419
|
+
msgBox = QMessageBox()
|
|
420
|
+
msgBox.setIcon(QMessageBox.Critical)
|
|
421
|
+
msgBox.setText(f"Cellpose model could not be loaded...")
|
|
422
|
+
msgBox.setWindowTitle("Error")
|
|
423
|
+
msgBox.setStandardButtons(QMessageBox.Ok)
|
|
424
|
+
returnValue = msgBox.exec()
|
|
425
|
+
if returnValue == QMessageBox.Ok:
|
|
426
|
+
return None
|
|
427
|
+
|
|
428
|
+
self.generate_input_config()
|
|
429
|
+
self.parent_window.init_seg_model_list()
|
|
430
|
+
self.close()
|
|
431
|
+
else:
|
|
432
|
+
if not isinstance(self.filename, list):
|
|
433
|
+
if not self.filename is None:
|
|
434
|
+
self.filename = [self.filename]
|
|
435
|
+
|
|
436
|
+
idx = self.parent_window.parent_window.populations.index(self.mode)
|
|
437
|
+
self.parent_window.threshold_configs[idx] = self.filename
|
|
438
|
+
self.parent_window.seg_model_list.setCurrentText("Threshold")
|
|
439
|
+
self.close()
|
|
440
|
+
|
|
441
|
+
def generate_input_config(self):
|
|
442
|
+
"""
|
|
443
|
+
Check the ticked options and input parameters to create
|
|
444
|
+
a configuration to use the uploaded model properly.
|
|
445
|
+
"""
|
|
446
|
+
|
|
447
|
+
if self.threshold_button.isChecked():
|
|
448
|
+
model_type = "threshold"
|
|
449
|
+
return None
|
|
450
|
+
|
|
451
|
+
channels = []
|
|
452
|
+
for i in range(len(self.channel_layout.channel_cbs)):
|
|
453
|
+
channels.append(self.channel_layout.channel_cbs[i].currentText())
|
|
454
|
+
|
|
455
|
+
slots_to_keep = np.where(np.array(channels) != "--")[0]
|
|
456
|
+
while "--" in channels:
|
|
457
|
+
channels.remove("--")
|
|
458
|
+
|
|
459
|
+
norm_values = np.array(
|
|
460
|
+
[
|
|
461
|
+
[float(a.replace(",", ".")), float(b.replace(",", "."))]
|
|
462
|
+
for a, b in zip(
|
|
463
|
+
[l.text() for l in self.channel_layout.normalization_min_value_le],
|
|
464
|
+
[l.text() for l in self.channel_layout.normalization_max_value_le],
|
|
465
|
+
)
|
|
466
|
+
]
|
|
467
|
+
)
|
|
468
|
+
norm_values = norm_values[slots_to_keep]
|
|
469
|
+
norm_values = [list(v) for v in norm_values]
|
|
470
|
+
|
|
471
|
+
clip_values = np.array(self.channel_layout.clip_option)
|
|
472
|
+
clip_values = list(clip_values[slots_to_keep])
|
|
473
|
+
clip_values = [bool(c) for c in clip_values]
|
|
474
|
+
|
|
475
|
+
normalization_mode = np.array(self.channel_layout.normalization_mode)
|
|
476
|
+
normalization_mode = list(normalization_mode[slots_to_keep])
|
|
477
|
+
normalization_mode = [bool(m) for m in normalization_mode]
|
|
478
|
+
|
|
479
|
+
dico = {}
|
|
480
|
+
|
|
481
|
+
# Check model option
|
|
482
|
+
if self.stardist_button.isChecked():
|
|
483
|
+
|
|
484
|
+
# Get channels
|
|
485
|
+
# channels = []
|
|
486
|
+
# for c in self.combos:
|
|
487
|
+
# if c.currentText()!="--":
|
|
488
|
+
# channels.append(c.currentText())
|
|
489
|
+
model_type = "stardist"
|
|
490
|
+
spatial_calib = float(self.spatial_calib_le.text().replace(",", "."))
|
|
491
|
+
# normalize = self.normalize_checkbox.isChecked()
|
|
492
|
+
dico.update(
|
|
493
|
+
{
|
|
494
|
+
"channels": channels,
|
|
495
|
+
# "normalize": normalize,
|
|
496
|
+
"spatial_calibration": spatial_calib,
|
|
497
|
+
"normalization_percentile": normalization_mode,
|
|
498
|
+
"normalization_clip": clip_values,
|
|
499
|
+
"normalization_values": norm_values,
|
|
500
|
+
}
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
elif self.cellpose_button.isChecked():
|
|
504
|
+
|
|
505
|
+
# Get channels (cyto and nucleus)
|
|
506
|
+
# channels = []
|
|
507
|
+
# for c in self.combos[:2]:
|
|
508
|
+
# if c.currentText()!="--":
|
|
509
|
+
# channels.append(c.currentText())
|
|
510
|
+
|
|
511
|
+
model_type = "cellpose"
|
|
512
|
+
# cellpose_utils requires at least two channels
|
|
513
|
+
if len(channels) == 1:
|
|
514
|
+
channels += ["None"]
|
|
515
|
+
normalization_mode += [True]
|
|
516
|
+
clip_values += [True]
|
|
517
|
+
norm_values += [[1, 99]]
|
|
518
|
+
|
|
519
|
+
diameter = float(self.cp_diameter_le.text().replace(",", "."))
|
|
520
|
+
cellprob_threshold = float(self.cp_cellprob_le.text().replace(",", "."))
|
|
521
|
+
flow_threshold = float(self.cp_flow_le.text().replace(",", "."))
|
|
522
|
+
# normalize = self.normalize_checkbox.isChecked()
|
|
523
|
+
spatial_calib = float(self.spatial_calib_le.text().replace(",", "."))
|
|
524
|
+
# assume 30 px diameter in cellpose_utils model
|
|
525
|
+
spatial_calib = spatial_calib * diameter / self.scale_model
|
|
526
|
+
diameter = 30.0
|
|
527
|
+
|
|
528
|
+
dico.update(
|
|
529
|
+
{
|
|
530
|
+
"channels": channels,
|
|
531
|
+
"diameter": diameter,
|
|
532
|
+
"cellprob_threshold": cellprob_threshold,
|
|
533
|
+
"flow_threshold": flow_threshold,
|
|
534
|
+
# "normalize": normalize,
|
|
535
|
+
"spatial_calibration": spatial_calib,
|
|
536
|
+
"normalization_percentile": normalization_mode,
|
|
537
|
+
"normalization_clip": clip_values,
|
|
538
|
+
"normalization_values": norm_values,
|
|
539
|
+
}
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
dico.update({"model_type": model_type})
|
|
543
|
+
print(f"{dico=}")
|
|
544
|
+
json_object = json.dumps(dico, indent=4)
|
|
545
|
+
|
|
546
|
+
# Writing to sample.json
|
|
547
|
+
# if os.path.exists(self.folder_dest):
|
|
548
|
+
|
|
549
|
+
# msgBox = QMessageBox()
|
|
550
|
+
# msgBox.setIcon(QMessageBox.Warning)
|
|
551
|
+
# msgBox.setText("A model with the same name already exists. Do you want to replace it?")
|
|
552
|
+
# msgBox.setWindowTitle("Confirm")
|
|
553
|
+
# msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
|
554
|
+
# returnValue = msgBox.exec()
|
|
555
|
+
# if returnValue == QMessageBox.No:
|
|
556
|
+
# return None
|
|
557
|
+
# elif returnValue == QMessageBox.Yes:
|
|
558
|
+
# shutil.rmtree(self.folder_dest)
|
|
559
|
+
# os.mkdir(self.folder_dest)
|
|
560
|
+
|
|
561
|
+
print(
|
|
562
|
+
"Configuration successfully written in ",
|
|
563
|
+
self.folder_dest + os.sep + "config_input.json",
|
|
564
|
+
)
|
|
565
|
+
with open(self.folder_dest + os.sep + "config_input.json", "w") as outfile:
|
|
566
|
+
outfile.write(json_object)
|
|
567
|
+
|
|
568
|
+
def open_threshold_config_wizard(self):
|
|
569
|
+
|
|
570
|
+
self.parent_window.parent_window.locate_image()
|
|
571
|
+
if self.parent_window.parent_window.current_stack is None:
|
|
572
|
+
return None
|
|
573
|
+
else:
|
|
574
|
+
from celldetective.gui.thresholds_gui import ThresholdConfigWizard
|
|
575
|
+
|
|
576
|
+
self.thresh_wizard = ThresholdConfigWizard(self)
|
|
577
|
+
self.thresh_wizard.show()
|
|
578
|
+
|
|
579
|
+
def safe_resize():
|
|
580
|
+
try:
|
|
581
|
+
self.thresh_wizard.resize(
|
|
582
|
+
self.thresh_wizard.width() + 1,
|
|
583
|
+
self.thresh_wizard.height() + 1,
|
|
584
|
+
)
|
|
585
|
+
except RuntimeError:
|
|
586
|
+
pass
|
|
587
|
+
|
|
588
|
+
try:
|
|
589
|
+
QTimer.singleShot(100, safe_resize)
|
|
590
|
+
center_window(self.thresh_wizard)
|
|
591
|
+
except:
|
|
592
|
+
pass
|