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
celldetective/gui/survival_ui.py
CHANGED
|
@@ -1,329 +1,439 @@
|
|
|
1
|
-
from PyQt5.QtWidgets import
|
|
1
|
+
from PyQt5.QtWidgets import (
|
|
2
|
+
QComboBox,
|
|
3
|
+
QLineEdit,
|
|
4
|
+
QVBoxLayout,
|
|
5
|
+
QLabel,
|
|
6
|
+
QHBoxLayout,
|
|
7
|
+
QPushButton,
|
|
8
|
+
)
|
|
2
9
|
from PyQt5.QtCore import Qt
|
|
3
10
|
from PyQt5.QtGui import QDoubleValidator
|
|
4
|
-
from celldetective.gui.
|
|
11
|
+
from celldetective.gui.base.components import generic_message
|
|
12
|
+
from celldetective.gui.base.utils import center_window
|
|
5
13
|
from superqt import QColormapComboBox
|
|
6
14
|
from celldetective.gui.generic_signal_plot import SurvivalPlotWidget
|
|
7
|
-
from celldetective
|
|
8
|
-
|
|
15
|
+
from celldetective import (
|
|
16
|
+
get_software_location,
|
|
17
|
+
)
|
|
18
|
+
from celldetective.utils.data_cleaning import extract_cols_from_table_list
|
|
19
|
+
from celldetective.utils.parsing import _extract_labels_from_config
|
|
20
|
+
from celldetective.utils.data_loaders import load_experiment_tables
|
|
9
21
|
import numpy as np
|
|
10
22
|
import os
|
|
11
23
|
import matplotlib.pyplot as plt
|
|
12
|
-
|
|
24
|
+
|
|
25
|
+
plt.rcParams["svg.fonttype"] = "none"
|
|
13
26
|
from glob import glob
|
|
14
|
-
from celldetective.gui import Styles
|
|
27
|
+
from celldetective.gui.base.styles import Styles
|
|
28
|
+
from celldetective.gui.base.components import CelldetectiveWidget
|
|
15
29
|
from matplotlib import colormaps
|
|
16
30
|
from celldetective.events import compute_survival
|
|
17
31
|
from celldetective.relative_measurements import expand_pair_table
|
|
18
32
|
import matplotlib.cm
|
|
19
33
|
from celldetective.neighborhood import extract_neighborhood_in_pair_table
|
|
20
34
|
|
|
35
|
+
|
|
21
36
|
class ConfigSurvival(CelldetectiveWidget):
|
|
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
|
-
|
|
37
|
+
"""
|
|
38
|
+
UI to set survival instructions.
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, parent_window=None):
|
|
43
|
+
|
|
44
|
+
super().__init__()
|
|
45
|
+
self.parent_window = parent_window
|
|
46
|
+
self.setWindowTitle("Configure survival")
|
|
47
|
+
|
|
48
|
+
self.exp_dir = self.parent_window.exp_dir
|
|
49
|
+
self.soft_path = get_software_location()
|
|
50
|
+
self.exp_config = self.exp_dir + "config.ini"
|
|
51
|
+
self.wells = np.array(self.parent_window.parent_window.wells, dtype=str)
|
|
52
|
+
self.well_labels = _extract_labels_from_config(self.exp_config, len(self.wells))
|
|
53
|
+
self.FrameToMin = self.parent_window.parent_window.FrameToMin
|
|
54
|
+
self.float_validator = QDoubleValidator()
|
|
55
|
+
self.auto_close = False
|
|
56
|
+
|
|
57
|
+
self.well_option = (
|
|
58
|
+
self.parent_window.parent_window.well_list.getSelectedIndices()
|
|
59
|
+
)
|
|
60
|
+
self.position_option = (
|
|
61
|
+
self.parent_window.parent_window.position_list.getSelectedIndices()
|
|
62
|
+
)
|
|
63
|
+
self.interpret_pos_location()
|
|
64
|
+
# self.config_path = self.exp_dir + self.config_name
|
|
65
|
+
|
|
66
|
+
self.screen_height = (
|
|
67
|
+
self.parent_window.parent_window.parent_window.screen_height
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
self.setMinimumWidth(350)
|
|
71
|
+
self.populate_widget()
|
|
72
|
+
if self.auto_close:
|
|
73
|
+
self.close()
|
|
74
|
+
|
|
75
|
+
def interpret_pos_location(self):
|
|
76
|
+
"""
|
|
77
|
+
Read the well/position selection from the control panel to decide which data to load
|
|
78
|
+
Set position_indices to None if all positions must be taken
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
self.well_indices = (
|
|
83
|
+
self.parent_window.parent_window.well_list.getSelectedIndices()
|
|
84
|
+
)
|
|
85
|
+
self.position_indices = (
|
|
86
|
+
self.parent_window.parent_window.position_list.getSelectedIndices()
|
|
87
|
+
)
|
|
88
|
+
if self.position_indices == []:
|
|
89
|
+
self.position_indices = None
|
|
90
|
+
|
|
91
|
+
def populate_widget(self):
|
|
92
|
+
"""
|
|
93
|
+
Create the multibox design.
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
# Create button widget and layout
|
|
98
|
+
main_layout = QVBoxLayout()
|
|
99
|
+
self.setLayout(main_layout)
|
|
100
|
+
main_layout.setContentsMargins(30, 30, 30, 30)
|
|
101
|
+
|
|
102
|
+
panel_title = QLabel("Options")
|
|
103
|
+
panel_title.setStyleSheet(
|
|
104
|
+
"""
|
|
84
105
|
font-weight: bold;
|
|
85
106
|
padding: 0px;
|
|
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
|
-
|
|
107
|
+
"""
|
|
108
|
+
)
|
|
109
|
+
main_layout.addWidget(panel_title, alignment=Qt.AlignCenter)
|
|
110
|
+
|
|
111
|
+
pops = []
|
|
112
|
+
self.cols_per_pop = {}
|
|
113
|
+
for population in self.parent_window.parent_window.populations:
|
|
114
|
+
tables = glob(
|
|
115
|
+
self.exp_dir
|
|
116
|
+
+ os.sep.join(
|
|
117
|
+
["W*", "*", "output", "tables", f"trajectories_{population}.csv"]
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
if len(tables) > 0:
|
|
121
|
+
pops.append(population)
|
|
122
|
+
cols = extract_cols_from_table_list(tables)
|
|
123
|
+
|
|
124
|
+
# check for neighbor pairs
|
|
125
|
+
neigh_cols = [
|
|
126
|
+
c for c in cols if c.startswith("inclusive_count_neighborhood")
|
|
127
|
+
]
|
|
128
|
+
neigh_pairs = [
|
|
129
|
+
c.split("_(")[-1].split(")_")[0].split("-") for c in neigh_cols
|
|
130
|
+
]
|
|
131
|
+
neigh_pairs = ["-".join(c) for c in neigh_pairs]
|
|
132
|
+
for k in range(len(neigh_pairs)):
|
|
133
|
+
if "_self_" in neigh_pairs[k]:
|
|
134
|
+
neigh_pairs[k] = "-".join([population, population])
|
|
135
|
+
pops.extend(neigh_pairs)
|
|
136
|
+
|
|
137
|
+
self.cols_per_pop.update({population: cols})
|
|
138
|
+
|
|
139
|
+
labels = [
|
|
140
|
+
QLabel("population: "),
|
|
141
|
+
QLabel("time of\nreference: "),
|
|
142
|
+
QLabel("time of\ninterest: "),
|
|
143
|
+
QLabel("cmap: "),
|
|
144
|
+
] # QLabel('class: '),
|
|
145
|
+
self.cb_options = [pops, ["0"], [], []] # ['class'],
|
|
146
|
+
self.cbs = [QComboBox() for _ in range(len(labels))]
|
|
147
|
+
|
|
148
|
+
self.cbs[-1] = QColormapComboBox()
|
|
149
|
+
self.cbs[0].currentIndexChanged.connect(self.set_classes_and_times)
|
|
150
|
+
|
|
151
|
+
choice_layout = QVBoxLayout()
|
|
152
|
+
choice_layout.setContentsMargins(20, 20, 20, 20)
|
|
153
|
+
for i in range(len(labels)):
|
|
154
|
+
hbox = QHBoxLayout()
|
|
155
|
+
hbox.addWidget(labels[i], 33)
|
|
156
|
+
hbox.addWidget(self.cbs[i], 66)
|
|
157
|
+
if i < len(labels) - 1:
|
|
158
|
+
self.cbs[i].addItems(self.cb_options[i])
|
|
159
|
+
choice_layout.addLayout(hbox)
|
|
160
|
+
|
|
161
|
+
all_cms = list(colormaps)
|
|
162
|
+
for cm in all_cms:
|
|
163
|
+
if hasattr(matplotlib.cm, str(cm).lower()):
|
|
164
|
+
try:
|
|
165
|
+
self.cbs[-1].addColormap(cm.lower())
|
|
166
|
+
except Exception as _:
|
|
167
|
+
pass
|
|
168
|
+
|
|
169
|
+
main_layout.addLayout(choice_layout)
|
|
170
|
+
|
|
171
|
+
select_layout = QHBoxLayout()
|
|
172
|
+
select_layout.addWidget(QLabel("select cells\nwith query: "), 33)
|
|
173
|
+
self.query_le = QLineEdit()
|
|
174
|
+
select_layout.addWidget(self.query_le, 66)
|
|
175
|
+
main_layout.addLayout(select_layout)
|
|
176
|
+
|
|
177
|
+
time_cut_layout = QHBoxLayout()
|
|
178
|
+
cut_time_lbl = QLabel("cut obs.\ntime [min]: ")
|
|
179
|
+
cut_time_lbl.setToolTip(
|
|
180
|
+
"Filter out later events from\nthe analysis (in absolute time)."
|
|
181
|
+
)
|
|
182
|
+
time_cut_layout.addWidget(cut_time_lbl, 33)
|
|
183
|
+
self.query_time_cut = QLineEdit()
|
|
184
|
+
self.query_time_cut.setValidator(self.float_validator)
|
|
185
|
+
time_cut_layout.addWidget(self.query_time_cut, 66)
|
|
186
|
+
main_layout.addLayout(time_cut_layout)
|
|
187
|
+
|
|
188
|
+
self.set_classes_and_times()
|
|
189
|
+
self.cbs[1].setCurrentText("t_firstdetection")
|
|
190
|
+
|
|
191
|
+
time_calib_layout = QHBoxLayout()
|
|
192
|
+
time_calib_layout.setContentsMargins(20, 20, 20, 20)
|
|
193
|
+
time_calib_layout.addWidget(QLabel("time calibration\n(frame to min)"), 33)
|
|
194
|
+
self.time_calibration_le = QLineEdit(str(self.FrameToMin).replace(".", ","))
|
|
195
|
+
self.time_calibration_le.setValidator(self.float_validator)
|
|
196
|
+
time_calib_layout.addWidget(self.time_calibration_le, 66)
|
|
197
|
+
# time_calib_layout.addWidget(QLabel(' min'))
|
|
198
|
+
main_layout.addLayout(time_calib_layout)
|
|
199
|
+
|
|
200
|
+
self.submit_btn = QPushButton("Submit")
|
|
201
|
+
self.submit_btn.setStyleSheet(self.button_style_sheet)
|
|
202
|
+
self.submit_btn.clicked.connect(self.process_survival)
|
|
203
|
+
main_layout.addWidget(self.submit_btn)
|
|
204
|
+
|
|
205
|
+
# self.populate_left_panel()
|
|
206
|
+
# grid.addLayout(self.left_side, 0, 0, 1, 1)
|
|
207
|
+
|
|
208
|
+
# self.setCentralWidget(self.scroll_area)
|
|
209
|
+
# self.show()
|
|
210
|
+
|
|
211
|
+
def set_classes_and_times(self):
|
|
212
|
+
|
|
213
|
+
# Look for all classes and times
|
|
214
|
+
self.neighborhood_keys = None
|
|
215
|
+
self.population = self.cbs[0].currentText()
|
|
216
|
+
pop_split = self.population.split("-")
|
|
217
|
+
|
|
218
|
+
if len(pop_split) == 2:
|
|
219
|
+
|
|
220
|
+
self.population = "pairs"
|
|
221
|
+
tables_pairs = glob(
|
|
222
|
+
self.exp_dir
|
|
223
|
+
+ os.sep.join(
|
|
224
|
+
["W*", "*", "output", "tables", f"trajectories_pairs.csv"]
|
|
225
|
+
)
|
|
226
|
+
)
|
|
227
|
+
if not tables_pairs:
|
|
228
|
+
print("No pair table found... please compute the pair measurements...")
|
|
229
|
+
return None
|
|
230
|
+
self.cols_pairs = extract_cols_from_table_list(tables_pairs)
|
|
231
|
+
|
|
232
|
+
self.population_reference = pop_split[0]
|
|
233
|
+
self.population_neigh = pop_split[1]
|
|
234
|
+
|
|
235
|
+
cols_ref = self.cols_per_pop[self.population_reference]
|
|
236
|
+
cols_neigh = self.cols_per_pop[self.population_neigh]
|
|
237
|
+
|
|
238
|
+
time_cols_ref = np.array(
|
|
239
|
+
[s.startswith("t_") or s == "t0" for s in cols_ref]
|
|
240
|
+
)
|
|
241
|
+
if len(time_cols_ref) > 0:
|
|
242
|
+
time_cols_ref = list(cols_ref[time_cols_ref])
|
|
243
|
+
time_cols_ref = ["reference_" + t for t in time_cols_ref]
|
|
244
|
+
|
|
245
|
+
time_cols_neigh = np.array(
|
|
246
|
+
[s.startswith("t_") or s == "t0" for s in cols_neigh]
|
|
247
|
+
)
|
|
248
|
+
if len(time_cols_neigh) > 0:
|
|
249
|
+
time_cols_neigh = list(cols_neigh[time_cols_neigh])
|
|
250
|
+
time_cols_neigh = ["neighbor_" + t for t in time_cols_neigh]
|
|
251
|
+
|
|
252
|
+
if self.population_reference != self.population_neigh:
|
|
253
|
+
self.neighborhood_keys = [
|
|
254
|
+
c[16:]
|
|
255
|
+
for c in cols_ref
|
|
256
|
+
if c.startswith("inclusive_count_neighborhood")
|
|
257
|
+
and str(self.population_neigh) in c
|
|
258
|
+
]
|
|
259
|
+
else:
|
|
260
|
+
self.neighborhood_keys = [
|
|
261
|
+
c[16:]
|
|
262
|
+
for c in cols_ref
|
|
263
|
+
if c.startswith("inclusive_count_neighborhood")
|
|
264
|
+
and str(self.population_neigh) not in c
|
|
265
|
+
]
|
|
266
|
+
|
|
267
|
+
print(f"{self.neighborhood_keys=}")
|
|
268
|
+
|
|
269
|
+
time_idx = np.array(
|
|
270
|
+
[s.startswith("t_") or s.startswith("t0") for s in self.cols_pairs]
|
|
271
|
+
)
|
|
272
|
+
time_cols_pairs = list(self.cols_pairs[time_idx])
|
|
273
|
+
|
|
274
|
+
time_columns = time_cols_ref + time_cols_neigh + time_cols_pairs
|
|
275
|
+
|
|
276
|
+
else:
|
|
277
|
+
self.all_columns = self.cols_per_pop[self.population]
|
|
278
|
+
time_idx = np.array(
|
|
279
|
+
[s.startswith("t_") or s == "t0" for s in self.all_columns]
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
try:
|
|
283
|
+
time_columns = list(self.all_columns[time_idx])
|
|
284
|
+
except:
|
|
285
|
+
print("no column starts with t")
|
|
286
|
+
self.auto_close = True
|
|
287
|
+
return None
|
|
288
|
+
|
|
289
|
+
self.cbs[1].clear()
|
|
290
|
+
self.cbs[1].addItems(np.unique(self.cb_options[1] + time_columns))
|
|
291
|
+
self.cbs[1].setCurrentText("t_firstdetection")
|
|
292
|
+
|
|
293
|
+
self.cbs[2].clear()
|
|
294
|
+
self.cbs[2].addItems(np.unique(self.cb_options[2] + time_columns))
|
|
295
|
+
|
|
296
|
+
def process_survival(self):
|
|
297
|
+
|
|
298
|
+
self.FrameToMin = float(self.time_calibration_le.text().replace(",", "."))
|
|
299
|
+
self.time_of_interest = self.cbs[2].currentText()
|
|
300
|
+
if self.time_of_interest == "t0":
|
|
301
|
+
self.class_of_interest = "class"
|
|
302
|
+
elif self.time_of_interest.startswith("t0"):
|
|
303
|
+
self.class_of_interest = self.time_of_interest.replace("t0_", "class_")
|
|
304
|
+
else:
|
|
305
|
+
self.class_of_interest = self.time_of_interest.replace("t_", "class_")
|
|
306
|
+
|
|
307
|
+
# read instructions from combobox options
|
|
308
|
+
self.load_available_tables_local()
|
|
309
|
+
if self.df is not None:
|
|
310
|
+
|
|
311
|
+
try:
|
|
312
|
+
query_text = self.query_le.text()
|
|
313
|
+
if query_text != "":
|
|
314
|
+
self.df = self.df.query(query_text)
|
|
315
|
+
except Exception as e:
|
|
316
|
+
print(e, " The query is misunderstood and will not be applied...")
|
|
317
|
+
|
|
318
|
+
self.interpret_pos_location()
|
|
319
|
+
|
|
320
|
+
if self.class_of_interest in list(self.df.columns) and self.cbs[
|
|
321
|
+
2
|
|
322
|
+
].currentText() in list(self.df.columns):
|
|
323
|
+
self.compute_survival_functions()
|
|
324
|
+
else:
|
|
325
|
+
generic_message(
|
|
326
|
+
"The class and/or event time of interest is not found in the dataframe..."
|
|
327
|
+
)
|
|
328
|
+
return None
|
|
329
|
+
|
|
330
|
+
if "survival_fit" in list(self.df_pos_info.columns):
|
|
331
|
+
self.plot_window = SurvivalPlotWidget(
|
|
332
|
+
parent_window=self,
|
|
333
|
+
df=self.df,
|
|
334
|
+
df_pos_info=self.df_pos_info,
|
|
335
|
+
df_well_info=self.df_well_info,
|
|
336
|
+
title="plot survivals",
|
|
337
|
+
)
|
|
338
|
+
self.plot_window.show()
|
|
339
|
+
else:
|
|
340
|
+
generic_message(
|
|
341
|
+
"No survival function was successfully computed...\nCheck your parameter choice."
|
|
342
|
+
)
|
|
343
|
+
return None
|
|
344
|
+
|
|
345
|
+
def load_available_tables_local(self):
|
|
346
|
+
"""
|
|
347
|
+
Load the tables of the selected wells/positions from the control Panel for the population of interest
|
|
348
|
+
|
|
349
|
+
"""
|
|
350
|
+
|
|
351
|
+
self.well_option = (
|
|
352
|
+
self.parent_window.parent_window.well_list.getSelectedIndices()
|
|
353
|
+
)
|
|
354
|
+
self.position_option = (
|
|
355
|
+
self.parent_window.parent_window.position_list.getSelectedIndices()
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
self.df, self.df_pos_info = load_experiment_tables(
|
|
359
|
+
self.exp_dir,
|
|
360
|
+
well_option=self.well_option,
|
|
361
|
+
position_option=self.position_option,
|
|
362
|
+
population=self.population,
|
|
363
|
+
return_pos_info=True,
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
if self.df is None:
|
|
367
|
+
generic_message("No table could be found.. Abort.")
|
|
368
|
+
return None
|
|
369
|
+
else:
|
|
370
|
+
self.df_well_info = self.df_pos_info.loc[
|
|
371
|
+
:, ["well_path", "well_index", "well_name", "well_number", "well_alias"]
|
|
372
|
+
].drop_duplicates()
|
|
373
|
+
|
|
374
|
+
if self.population == "pairs":
|
|
375
|
+
self.df = expand_pair_table(self.df)
|
|
376
|
+
self.df = extract_neighborhood_in_pair_table(
|
|
377
|
+
self.df,
|
|
378
|
+
reference_population=self.population_reference,
|
|
379
|
+
neighbor_population=self.population_neigh,
|
|
380
|
+
neighborhood_key=self.neighborhood_keys[0],
|
|
381
|
+
contact_only=True,
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
def compute_survival_functions(self):
|
|
385
|
+
|
|
386
|
+
cut_observation_time = None
|
|
387
|
+
try:
|
|
388
|
+
if self.query_time_cut.text() != "":
|
|
389
|
+
cut_observation_time = (
|
|
390
|
+
float(self.query_time_cut.text().replace(",", "."))
|
|
391
|
+
/ self.FrameToMin
|
|
392
|
+
)
|
|
393
|
+
if not 0 < cut_observation_time <= (self.df["FRAME"].max()):
|
|
394
|
+
print("Invalid cut time (larger than movie length)... Not applied.")
|
|
395
|
+
cut_observation_time = None
|
|
396
|
+
except Exception as e:
|
|
397
|
+
print(f"{e=}")
|
|
398
|
+
pass
|
|
399
|
+
|
|
400
|
+
pairs = False
|
|
401
|
+
if self.neighborhood_keys is not None:
|
|
402
|
+
pairs = True
|
|
403
|
+
|
|
404
|
+
# Per position survival
|
|
405
|
+
for block, movie_group in self.df.groupby(["well", "position"]):
|
|
406
|
+
print(f"{block=}")
|
|
407
|
+
ks = compute_survival(
|
|
408
|
+
movie_group,
|
|
409
|
+
self.class_of_interest,
|
|
410
|
+
self.cbs[2].currentText(),
|
|
411
|
+
t_reference=self.cbs[1].currentText(),
|
|
412
|
+
FrameToMin=self.FrameToMin,
|
|
413
|
+
cut_observation_time=cut_observation_time,
|
|
414
|
+
pairs=pairs,
|
|
415
|
+
)
|
|
416
|
+
print(f"{ks=}")
|
|
417
|
+
if ks is not None:
|
|
418
|
+
self.df_pos_info.loc[
|
|
419
|
+
self.df_pos_info["pos_path"] == block[1], "survival_fit"
|
|
420
|
+
] = ks
|
|
421
|
+
|
|
422
|
+
# Per well survival
|
|
423
|
+
for well, well_group in self.df.groupby("well"):
|
|
424
|
+
ks = compute_survival(
|
|
425
|
+
well_group,
|
|
426
|
+
self.class_of_interest,
|
|
427
|
+
self.cbs[2].currentText(),
|
|
428
|
+
t_reference=self.cbs[1].currentText(),
|
|
429
|
+
FrameToMin=self.FrameToMin,
|
|
430
|
+
cut_observation_time=cut_observation_time,
|
|
431
|
+
pairs=pairs,
|
|
432
|
+
)
|
|
433
|
+
if ks is not None:
|
|
434
|
+
self.df_well_info.loc[
|
|
435
|
+
self.df_well_info["well_path"] == well, "survival_fit"
|
|
436
|
+
] = ks
|
|
437
|
+
|
|
438
|
+
self.df_pos_info.loc[:, "select"] = True
|
|
439
|
+
self.df_well_info.loc[:, "select"] = True
|