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,12 +1,23 @@
|
|
|
1
|
-
from PyQt5.QtWidgets import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
from PyQt5.QtWidgets import (
|
|
2
|
+
QMessageBox,
|
|
3
|
+
QGridLayout,
|
|
4
|
+
QButtonGroup,
|
|
5
|
+
QCheckBox,
|
|
6
|
+
QLineEdit,
|
|
7
|
+
QVBoxLayout,
|
|
8
|
+
QLabel,
|
|
9
|
+
QHBoxLayout,
|
|
10
|
+
QPushButton,
|
|
11
|
+
QRadioButton,
|
|
12
|
+
)
|
|
4
13
|
from PyQt5.QtCore import Qt, QSize
|
|
5
14
|
from PyQt5.QtGui import QDoubleValidator
|
|
6
15
|
|
|
7
|
-
from celldetective.gui.gui_utils import
|
|
16
|
+
from celldetective.gui.gui_utils import ExportPlotBtn, QuickSliderLayout
|
|
17
|
+
from celldetective.gui.base.figure_canvas import FigureCanvas
|
|
18
|
+
from celldetective.gui.base.utils import center_window
|
|
8
19
|
from celldetective.gui.tableUI import TableUI
|
|
9
|
-
from celldetective.
|
|
20
|
+
from celldetective.utils.experiment import collect_experiment_metadata
|
|
10
21
|
|
|
11
22
|
from superqt.fonticon import icon
|
|
12
23
|
from superqt import QLabeledSlider, QLabeledDoubleSlider
|
|
@@ -15,954 +26,1291 @@ import numpy as np
|
|
|
15
26
|
import json
|
|
16
27
|
import os
|
|
17
28
|
import matplotlib.pyplot as plt
|
|
18
|
-
|
|
29
|
+
|
|
30
|
+
plt.rcParams["svg.fonttype"] = "none"
|
|
19
31
|
from glob import glob
|
|
20
32
|
from matplotlib.cm import tab10
|
|
21
|
-
from celldetective.gui import CelldetectiveWidget
|
|
33
|
+
from celldetective.gui.base.components import CelldetectiveWidget
|
|
22
34
|
import matplotlib.cm as mcm
|
|
23
35
|
import pandas as pd
|
|
24
36
|
|
|
25
37
|
from lifelines.utils import qth_survival_times
|
|
26
38
|
|
|
39
|
+
|
|
27
40
|
class GenericSignalPlotWidget(CelldetectiveWidget):
|
|
28
41
|
|
|
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
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
df=None,
|
|
45
|
+
df_pos_info=None,
|
|
46
|
+
df_well_info=None,
|
|
47
|
+
feature_selected=None,
|
|
48
|
+
parent_window=None,
|
|
49
|
+
title="plot",
|
|
50
|
+
*args,
|
|
51
|
+
**kwargs,
|
|
52
|
+
):
|
|
53
|
+
|
|
54
|
+
super().__init__()
|
|
55
|
+
center_window(self)
|
|
56
|
+
|
|
57
|
+
self.parent_window = parent_window
|
|
58
|
+
self.setWindowTitle(title)
|
|
59
|
+
|
|
60
|
+
self.show_ci = False
|
|
61
|
+
self.legend_visible = True
|
|
62
|
+
self.show_cell_lines = False
|
|
63
|
+
self.alpha_setting = 0.5
|
|
64
|
+
self.scaling_factor = 1
|
|
65
|
+
self.target_class = [0]
|
|
66
|
+
self.float_validator = QDoubleValidator()
|
|
67
|
+
|
|
68
|
+
cmap_lbl = self.parent_window.cbs[-1].currentText()
|
|
69
|
+
self.cmap = getattr(mcm, cmap_lbl)
|
|
70
|
+
|
|
71
|
+
self.feature_selected = feature_selected
|
|
72
|
+
self.df = df
|
|
73
|
+
self.df_pos_info = df_pos_info
|
|
74
|
+
self.df_well_info = df_well_info
|
|
75
|
+
|
|
76
|
+
self.layout = QVBoxLayout()
|
|
77
|
+
self.layout.setSpacing(3)
|
|
78
|
+
self.populate_widget()
|
|
79
|
+
|
|
80
|
+
self.ci_btn.click()
|
|
81
|
+
# self.legend_btn.click()
|
|
82
|
+
|
|
83
|
+
self.fig.tight_layout()
|
|
84
|
+
self.setLayout(self.layout)
|
|
85
|
+
|
|
86
|
+
def populate_widget(self):
|
|
87
|
+
|
|
88
|
+
self.plot_options = [QRadioButton() for i in range(3)]
|
|
89
|
+
self.radio_labels = ["well", "position", "both"]
|
|
90
|
+
radio_hbox = QHBoxLayout()
|
|
91
|
+
radio_hbox.setContentsMargins(15, 15, 15, 0)
|
|
92
|
+
|
|
93
|
+
self.group_lbl = QLabel("grouping: ")
|
|
94
|
+
radio_hbox.addWidget(self.group_lbl, 25)
|
|
95
|
+
radio_subhbox = QHBoxLayout()
|
|
96
|
+
radio_hbox.addLayout(radio_subhbox, 75)
|
|
97
|
+
|
|
98
|
+
self.plot_btn_group = QButtonGroup()
|
|
99
|
+
for i in range(3):
|
|
100
|
+
self.plot_options[i].setText(self.radio_labels[i])
|
|
101
|
+
self.plot_btn_group.addButton(self.plot_options[i])
|
|
102
|
+
radio_subhbox.addWidget(self.plot_options[i], 33, alignment=Qt.AlignCenter)
|
|
103
|
+
|
|
104
|
+
if self.parent_window.position_indices is not None:
|
|
105
|
+
# at least a position is selected
|
|
106
|
+
if (
|
|
107
|
+
len(self.parent_window.well_indices) > 1
|
|
108
|
+
and len(self.parent_window.position_indices) == 1
|
|
109
|
+
):
|
|
110
|
+
# several wells but one position
|
|
111
|
+
self.plot_btn_group.buttons()[0].click()
|
|
112
|
+
# for i in [1,2]:
|
|
113
|
+
# self.plot_options[i].setEnabled(False)
|
|
114
|
+
elif len(self.parent_window.well_indices) > 1:
|
|
115
|
+
self.plot_btn_group.buttons()[0].click()
|
|
116
|
+
elif (
|
|
117
|
+
len(self.parent_window.well_indices) == 1
|
|
118
|
+
and len(self.parent_window.position_indices) == 1
|
|
119
|
+
):
|
|
120
|
+
self.plot_btn_group.buttons()[1].click()
|
|
121
|
+
for i in [0, 2]:
|
|
122
|
+
self.plot_options[i].setEnabled(False)
|
|
123
|
+
elif (
|
|
124
|
+
len(self.parent_window.well_indices) == 1
|
|
125
|
+
and len(self.parent_window.position_indices) > 1
|
|
126
|
+
):
|
|
127
|
+
# one well, several positions
|
|
128
|
+
self.plot_btn_group.buttons()[2].click()
|
|
129
|
+
else:
|
|
130
|
+
if len(self.parent_window.well_indices) > 1:
|
|
131
|
+
self.plot_btn_group.buttons()[0].click()
|
|
132
|
+
elif len(self.parent_window.well_indices) == 1:
|
|
133
|
+
self.plot_btn_group.buttons()[2].click()
|
|
134
|
+
|
|
135
|
+
self.layout.addLayout(radio_hbox)
|
|
136
|
+
|
|
137
|
+
plot_buttons_hbox = QHBoxLayout()
|
|
138
|
+
plot_buttons_hbox.setContentsMargins(10, 10, 5, 0)
|
|
139
|
+
plot_buttons_hbox.addWidget(QLabel(""), 80, alignment=Qt.AlignLeft)
|
|
140
|
+
|
|
141
|
+
self.legend_btn = QPushButton("")
|
|
142
|
+
self.legend_btn.setIcon(icon(MDI6.text_box, color=self.help_color))
|
|
143
|
+
self.legend_btn.setStyleSheet(self.button_select_all)
|
|
144
|
+
self.legend_btn.setToolTip("Show or hide the legend")
|
|
145
|
+
self.legend_btn.setIconSize(QSize(20, 20))
|
|
146
|
+
plot_buttons_hbox.addWidget(self.legend_btn, 5, alignment=Qt.AlignRight)
|
|
147
|
+
|
|
148
|
+
self.log_btn = QPushButton("")
|
|
149
|
+
self.log_btn.setIcon(icon(MDI6.math_log, color="black"))
|
|
150
|
+
self.log_btn.setStyleSheet(self.button_select_all)
|
|
151
|
+
self.log_btn.setIconSize(QSize(20, 20))
|
|
152
|
+
self.log_btn.setToolTip("Enable or disable log scale")
|
|
153
|
+
plot_buttons_hbox.addWidget(self.log_btn, 5, alignment=Qt.AlignRight)
|
|
154
|
+
|
|
155
|
+
self.ci_btn = QPushButton("")
|
|
156
|
+
self.ci_btn.setIcon(icon(MDI6.arrow_expand_horizontal, color="black"))
|
|
157
|
+
self.ci_btn.setStyleSheet(self.button_select_all)
|
|
158
|
+
self.ci_btn.setIconSize(QSize(20, 20))
|
|
159
|
+
self.ci_btn.setToolTip("Show or hide confidence intervals.")
|
|
160
|
+
plot_buttons_hbox.addWidget(self.ci_btn, 5, alignment=Qt.AlignRight)
|
|
161
|
+
|
|
162
|
+
self.cell_lines_btn = QPushButton("")
|
|
163
|
+
self.cell_lines_btn.setIcon(icon(MDI6.view_headline, color="black"))
|
|
164
|
+
self.cell_lines_btn.setStyleSheet(self.button_select_all)
|
|
165
|
+
self.cell_lines_btn.setToolTip("Show or hide individual cell signals.")
|
|
166
|
+
self.cell_lines_btn.setIconSize(QSize(20, 20))
|
|
167
|
+
plot_buttons_hbox.addWidget(self.cell_lines_btn, 5, alignment=Qt.AlignRight)
|
|
168
|
+
|
|
169
|
+
self.fig, self.ax = plt.subplots(1, 1, figsize=(4, 3))
|
|
170
|
+
self.plot_widget = FigureCanvas(self.fig, title="")
|
|
171
|
+
self.plot_widget.setContentsMargins(0, 0, 0, 0)
|
|
172
|
+
self.initialize_axis()
|
|
173
|
+
plt.tight_layout()
|
|
174
|
+
|
|
175
|
+
self.export_btn = ExportPlotBtn(self.fig, export_dir=self.parent_window.exp_dir)
|
|
176
|
+
plot_buttons_hbox.addWidget(self.export_btn, 5, alignment=Qt.AlignRight)
|
|
177
|
+
self.layout.addLayout(plot_buttons_hbox)
|
|
178
|
+
|
|
179
|
+
self.export_tabular_btn = QPushButton("")
|
|
180
|
+
self.export_tabular_btn.setIcon(icon(MDI6.table, color="black"))
|
|
181
|
+
self.export_tabular_btn.setStyleSheet(self.button_select_all)
|
|
182
|
+
self.export_tabular_btn.setToolTip("Tabulate survival values.")
|
|
183
|
+
self.export_tabular_btn.setIconSize(QSize(20, 20))
|
|
184
|
+
plot_buttons_hbox.addWidget(self.export_tabular_btn, 5, alignment=Qt.AlignRight)
|
|
185
|
+
self.export_tabular_btn.hide()
|
|
186
|
+
|
|
187
|
+
self.ax.set_prop_cycle(
|
|
188
|
+
"color",
|
|
189
|
+
[
|
|
190
|
+
self.cmap(i)
|
|
191
|
+
for i in np.linspace(0, 1, len(self.parent_window.well_indices))
|
|
192
|
+
],
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
self.fig.set_facecolor("none") # or 'None'
|
|
196
|
+
self.fig.canvas.setStyleSheet("background-color: transparent;")
|
|
197
|
+
self.plot_widget.canvas.draw()
|
|
198
|
+
|
|
199
|
+
self.layout.addWidget(self.plot_widget)
|
|
200
|
+
|
|
201
|
+
self.plot_btn_group.buttonClicked[int].connect(self.plot_signals)
|
|
202
|
+
self.legend_btn.clicked.connect(self.show_hide_legend)
|
|
203
|
+
self.log_btn.clicked.connect(self.switch_to_log)
|
|
204
|
+
self.ci_btn.clicked.connect(self.switch_ci)
|
|
205
|
+
self.cell_lines_btn.clicked.connect(self.switch_cell_lines)
|
|
206
|
+
|
|
207
|
+
self.class_selection_widget = CelldetectiveWidget()
|
|
208
|
+
|
|
209
|
+
self.class_selection_lbl = QLabel("class of interest:")
|
|
210
|
+
class_hbox = QHBoxLayout()
|
|
211
|
+
self.class_selection_widget.setLayout(class_hbox)
|
|
212
|
+
class_hbox.addWidget(self.class_selection_lbl, 25, alignment=Qt.AlignLeft)
|
|
213
|
+
|
|
214
|
+
class_subhbox = QHBoxLayout()
|
|
215
|
+
class_hbox.addLayout(class_subhbox, 75)
|
|
216
|
+
|
|
217
|
+
self.all_btn = QRadioButton("*")
|
|
218
|
+
self.event_btn = QRadioButton("event")
|
|
219
|
+
self.event_btn.setChecked(True)
|
|
220
|
+
self.no_event_btn = QRadioButton("no event")
|
|
221
|
+
self.class_btn_group = QButtonGroup()
|
|
222
|
+
for btn in [self.all_btn, self.event_btn, self.no_event_btn]:
|
|
223
|
+
self.class_btn_group.addButton(btn)
|
|
224
|
+
|
|
225
|
+
self.class_btn_group.buttonClicked[int].connect(self.set_class_to_plot)
|
|
226
|
+
|
|
227
|
+
class_subhbox.addWidget(self.all_btn, 33, alignment=Qt.AlignCenter)
|
|
228
|
+
class_subhbox.addWidget(self.event_btn, 33, alignment=Qt.AlignCenter)
|
|
229
|
+
class_subhbox.addWidget(self.no_event_btn, 33, alignment=Qt.AlignCenter)
|
|
230
|
+
|
|
231
|
+
self.layout.addWidget(self.class_selection_widget) # Layout(class_hbox)
|
|
232
|
+
|
|
233
|
+
# Rescale
|
|
234
|
+
self.rescale_widget = CelldetectiveWidget()
|
|
235
|
+
|
|
236
|
+
scale_hbox = QHBoxLayout()
|
|
237
|
+
self.rescale_widget.setLayout(scale_hbox)
|
|
238
|
+
|
|
239
|
+
scale_hbox.addWidget(QLabel("scaling factor: "), 25)
|
|
240
|
+
self.scaling_factor_le = QLineEdit("1")
|
|
241
|
+
self.scaling_factor_le.setValidator(self.float_validator)
|
|
242
|
+
scale_hbox.addWidget(self.scaling_factor_le, 65)
|
|
243
|
+
|
|
244
|
+
self.rescale_btn = QPushButton("rescale")
|
|
245
|
+
self.rescale_btn.setStyleSheet(self.button_style_sheet_2)
|
|
246
|
+
self.rescale_btn.clicked.connect(self.rescale_y_axis)
|
|
247
|
+
scale_hbox.addWidget(self.rescale_btn, 10)
|
|
248
|
+
# self.layout.addLayout(scale_hbox)
|
|
249
|
+
self.layout.addWidget(self.rescale_widget)
|
|
250
|
+
|
|
251
|
+
# Rescale
|
|
252
|
+
self.cell_lines_alpha_wdg = CelldetectiveWidget()
|
|
253
|
+
alpha_hbox = QHBoxLayout()
|
|
254
|
+
|
|
255
|
+
self.alpha_slider = QLabeledDoubleSlider()
|
|
256
|
+
alpha_hbox = QuickSliderLayout(
|
|
257
|
+
label="single-cell\nsignal alpha: ",
|
|
258
|
+
slider=self.alpha_slider,
|
|
259
|
+
slider_initial_value=self.alpha_setting,
|
|
260
|
+
slider_range=(0, 1),
|
|
261
|
+
decimal_option=True,
|
|
262
|
+
precision=5,
|
|
263
|
+
)
|
|
264
|
+
self.alpha_slider.valueChanged.connect(self.submit_alpha)
|
|
265
|
+
self.cell_lines_alpha_wdg.setLayout(alpha_hbox)
|
|
266
|
+
|
|
267
|
+
# self.submit_alpha_btn = QPushButton('submit')
|
|
268
|
+
# self.submit_alpha_btn.setStyleSheet(self.button_style_sheet_2)
|
|
269
|
+
# self.submit_alpha_btn.clicked.connect(self.submit_alpha)
|
|
270
|
+
# alpha_hbox.addWidget(self.submit_alpha_btn, 10)
|
|
271
|
+
self.layout.addWidget(self.cell_lines_alpha_wdg)
|
|
272
|
+
|
|
273
|
+
self.select_option = [QRadioButton() for i in range(2)]
|
|
274
|
+
self.select_label = ["by name", "spatially"]
|
|
275
|
+
|
|
276
|
+
select_hbox = QHBoxLayout()
|
|
277
|
+
select_hbox.addWidget(QLabel("select position: "), 25)
|
|
278
|
+
|
|
279
|
+
select_subhbox = QHBoxLayout()
|
|
280
|
+
select_hbox.addLayout(select_subhbox, 75)
|
|
281
|
+
|
|
282
|
+
self.select_btn_group = QButtonGroup()
|
|
283
|
+
for i in range(2):
|
|
284
|
+
self.select_option[i].setText(self.select_label[i])
|
|
285
|
+
self.select_btn_group.addButton(self.select_option[i])
|
|
286
|
+
select_subhbox.addWidget(
|
|
287
|
+
self.select_option[i], 33, alignment=Qt.AlignCenter
|
|
288
|
+
)
|
|
289
|
+
self.select_option[0].setChecked(True)
|
|
290
|
+
self.select_btn_group.buttonClicked[int].connect(self.switch_selection_mode)
|
|
291
|
+
self.layout.addLayout(select_hbox)
|
|
292
|
+
|
|
293
|
+
self.look_for_metadata()
|
|
294
|
+
if self.metadata_found:
|
|
295
|
+
self.fig_scatter, self.ax_scatter = plt.subplots(
|
|
296
|
+
1, 1, figsize=(4, 2)
|
|
297
|
+
) # ,figsize=(4,3)
|
|
298
|
+
self.position_scatter = FigureCanvas(self.fig_scatter)
|
|
299
|
+
self.load_coordinates()
|
|
300
|
+
self.plot_spatial_location()
|
|
301
|
+
self.ax_scatter.spines["top"].set_visible(False)
|
|
302
|
+
self.ax_scatter.spines["right"].set_visible(False)
|
|
303
|
+
self.ax_scatter.set_aspect("equal")
|
|
304
|
+
self.ax_scatter.set_xticks([])
|
|
305
|
+
self.ax_scatter.set_yticks([])
|
|
306
|
+
plt.tight_layout()
|
|
307
|
+
|
|
308
|
+
self.fig_scatter.set_facecolor("none") # or 'None'
|
|
309
|
+
self.fig_scatter.canvas.setStyleSheet("background-color: transparent;")
|
|
310
|
+
self.layout.addWidget(self.position_scatter)
|
|
311
|
+
|
|
312
|
+
self.generate_pos_selection_widget()
|
|
313
|
+
self.select_btn_group.buttons()[0].click()
|
|
314
|
+
|
|
315
|
+
def submit_alpha(self, value):
|
|
316
|
+
|
|
317
|
+
alpha = value
|
|
318
|
+
try:
|
|
319
|
+
alpha = float(alpha)
|
|
320
|
+
except:
|
|
321
|
+
return None
|
|
322
|
+
if alpha > 1.0:
|
|
323
|
+
alpha = 1.0
|
|
324
|
+
elif alpha < 0.0:
|
|
325
|
+
alpha = 0.0
|
|
326
|
+
self.alpha_setting = alpha
|
|
327
|
+
self.plot_signals(0)
|
|
328
|
+
|
|
329
|
+
def rescale_y_axis(self):
|
|
330
|
+
new_scale = self.scaling_factor_le.text().replace(",", ".")
|
|
331
|
+
if new_scale == "":
|
|
332
|
+
msgBox = QMessageBox()
|
|
333
|
+
msgBox.setIcon(QMessageBox.Warning)
|
|
334
|
+
msgBox.setText("Please set a valid scaling factor...")
|
|
335
|
+
msgBox.setWindowTitle("Warning")
|
|
336
|
+
msgBox.setStandardButtons(QMessageBox.Ok)
|
|
337
|
+
returnValue = msgBox.exec()
|
|
338
|
+
if returnValue == QMessageBox.Ok:
|
|
339
|
+
return None
|
|
340
|
+
else:
|
|
341
|
+
self.scaling_factor = float(new_scale)
|
|
342
|
+
self.plot_signals(0)
|
|
343
|
+
|
|
344
|
+
def switch_selection_mode(self, id):
|
|
345
|
+
|
|
346
|
+
for i in range(2):
|
|
347
|
+
if self.select_option[i].isChecked():
|
|
348
|
+
self.selection_mode = self.select_label[i]
|
|
349
|
+
if self.selection_mode == "by name":
|
|
350
|
+
if len(self.metafiles) > 0:
|
|
351
|
+
self.position_scatter.hide()
|
|
352
|
+
self.line_choice_widget.show()
|
|
353
|
+
else:
|
|
354
|
+
if len(self.metafiles) > 0:
|
|
355
|
+
self.position_scatter.show()
|
|
356
|
+
self.line_choice_widget.hide()
|
|
357
|
+
|
|
358
|
+
def set_class_to_plot(self):
|
|
359
|
+
|
|
360
|
+
if self.all_btn.isChecked():
|
|
361
|
+
self.target_class = [0, 1]
|
|
362
|
+
elif self.event_btn.isChecked():
|
|
363
|
+
self.target_class = [0]
|
|
364
|
+
else:
|
|
365
|
+
self.target_class = [1]
|
|
366
|
+
|
|
367
|
+
self.plot_signals(0)
|
|
368
|
+
|
|
369
|
+
def generate_pos_selection_widget(self):
|
|
370
|
+
|
|
371
|
+
self.well_names = self.df["well_name"].unique()
|
|
372
|
+
self.pos_names = self.df_pos_info[
|
|
373
|
+
"pos_name"
|
|
374
|
+
].unique() # pd.DataFrame(self.ks_estimators_per_position)['position_name'].unique()
|
|
375
|
+
|
|
376
|
+
self.usable_well_labels = []
|
|
377
|
+
for name in self.well_names:
|
|
378
|
+
for lbl in self.parent_window.well_labels:
|
|
379
|
+
if name + ":" in lbl:
|
|
380
|
+
self.usable_well_labels.append(lbl)
|
|
381
|
+
|
|
382
|
+
thresh = 20
|
|
383
|
+
self.well_name_truncated = [
|
|
384
|
+
w[: thresh - 3] + "..." if len(w) > thresh else w
|
|
385
|
+
for w in self.usable_well_labels
|
|
386
|
+
]
|
|
387
|
+
|
|
388
|
+
self.line_choice_widget = CelldetectiveWidget()
|
|
389
|
+
self.line_check_vbox = QGridLayout()
|
|
390
|
+
self.line_choice_widget.setLayout(self.line_check_vbox)
|
|
391
|
+
|
|
392
|
+
if len(self.parent_window.well_indices) > 1:
|
|
393
|
+
self.well_display_options = [
|
|
394
|
+
QCheckBox(self.well_name_truncated[i])
|
|
395
|
+
for i in range(len(self.well_name_truncated))
|
|
396
|
+
]
|
|
397
|
+
for i in range(len(self.well_names)):
|
|
398
|
+
self.line_check_vbox.addWidget(
|
|
399
|
+
self.well_display_options[i],
|
|
400
|
+
i % 4,
|
|
401
|
+
i // 4,
|
|
402
|
+
1,
|
|
403
|
+
1,
|
|
404
|
+
alignment=Qt.AlignCenter,
|
|
405
|
+
)
|
|
406
|
+
self.well_display_options[i].setChecked(True)
|
|
407
|
+
self.well_display_options[i].setStyleSheet("font-size: 12px;")
|
|
408
|
+
self.well_display_options[i].toggled.connect(self.select_lines)
|
|
409
|
+
self.well_display_options[i].setToolTip(self.usable_well_labels[i])
|
|
410
|
+
else:
|
|
411
|
+
self.pos_display_options = [
|
|
412
|
+
QCheckBox(self.pos_names[i]) for i in range(len(self.pos_names))
|
|
413
|
+
]
|
|
414
|
+
for i in range(len(self.pos_names)):
|
|
415
|
+
self.line_check_vbox.addWidget(
|
|
416
|
+
self.pos_display_options[i],
|
|
417
|
+
i % 4,
|
|
418
|
+
i // 4,
|
|
419
|
+
1,
|
|
420
|
+
1,
|
|
421
|
+
alignment=Qt.AlignCenter,
|
|
422
|
+
)
|
|
423
|
+
self.pos_display_options[i].setChecked(True)
|
|
424
|
+
self.pos_display_options[i].setStyleSheet("font-size: 12px;")
|
|
425
|
+
self.pos_display_options[i].toggled.connect(self.select_lines)
|
|
426
|
+
|
|
427
|
+
self.layout.addWidget(self.line_choice_widget)
|
|
428
|
+
# self.layout.addLayout(self.line_check_vbox)
|
|
429
|
+
|
|
430
|
+
def look_for_metadata(self):
|
|
431
|
+
self.metadata_found = False
|
|
432
|
+
self.metafiles = (
|
|
433
|
+
glob(
|
|
434
|
+
self.parent_window.exp_dir
|
|
435
|
+
+ os.sep.join([f"W*", "*", "movie", "*metadata.txt"])
|
|
436
|
+
)
|
|
437
|
+
+ glob(
|
|
438
|
+
self.parent_window.exp_dir + os.sep.join([f"W*", "*", "*metadata.txt"])
|
|
439
|
+
)
|
|
440
|
+
+ glob(self.parent_window.exp_dir + os.sep.join([f"W*", "*metadata.txt"]))
|
|
441
|
+
+ glob(self.parent_window.exp_dir + "*metadata.txt")
|
|
442
|
+
)
|
|
443
|
+
print(f"Found {len(self.metafiles)} metadata files...")
|
|
444
|
+
if len(self.metafiles) > 0:
|
|
445
|
+
self.metadata_found = True
|
|
446
|
+
|
|
447
|
+
def load_coordinates(self):
|
|
448
|
+
"""
|
|
449
|
+
Read metadata and try to extract position coordinates
|
|
450
|
+
"""
|
|
451
|
+
|
|
452
|
+
self.no_meta = False
|
|
453
|
+
try:
|
|
454
|
+
with open(self.metafiles[0], "r") as f:
|
|
455
|
+
data = json.load(f)
|
|
456
|
+
positions = data["Summary"]["InitialPositionList"]
|
|
457
|
+
except Exception as e:
|
|
458
|
+
print(f"Trouble loading metadata: error {e}...")
|
|
459
|
+
return None
|
|
460
|
+
|
|
461
|
+
for k in range(len(positions)):
|
|
462
|
+
pos_label = positions[k]["Label"]
|
|
463
|
+
try:
|
|
464
|
+
coords = positions[k]["DeviceCoordinatesUm"]["XYStage"]
|
|
465
|
+
except:
|
|
466
|
+
try:
|
|
467
|
+
coords = positions[k]["DeviceCoordinatesUm"]["PIXYStage"]
|
|
468
|
+
except:
|
|
469
|
+
self.no_meta = True
|
|
470
|
+
|
|
471
|
+
if not self.no_meta:
|
|
472
|
+
files = self.df_pos_info["stack_path"].values
|
|
473
|
+
pos_loc = [pos_label in f for f in files]
|
|
474
|
+
self.df_pos_info.loc[pos_loc, "x"] = coords[0]
|
|
475
|
+
self.df_pos_info.loc[pos_loc, "y"] = coords[1]
|
|
476
|
+
self.df_pos_info.loc[pos_loc, "metadata_tag"] = pos_label
|
|
477
|
+
|
|
478
|
+
def plot_spatial_location(self):
|
|
479
|
+
|
|
480
|
+
try:
|
|
481
|
+
self.sc = self.ax_scatter.scatter(
|
|
482
|
+
self.df_pos_info["x"].values,
|
|
483
|
+
self.df_pos_info["y"].values,
|
|
484
|
+
picker=True,
|
|
485
|
+
pickradius=1,
|
|
486
|
+
color=self.select_color(self.df_pos_info["select"].values),
|
|
487
|
+
)
|
|
488
|
+
self.scat_labels = self.df_pos_info["metadata_tag"].values
|
|
489
|
+
self.ax_scatter.invert_xaxis()
|
|
490
|
+
|
|
491
|
+
self.annot = self.ax_scatter.annotate(
|
|
492
|
+
"",
|
|
493
|
+
xy=(0, 0),
|
|
494
|
+
xytext=(10, 10),
|
|
495
|
+
textcoords="offset points",
|
|
496
|
+
bbox=dict(boxstyle="round", fc="w"),
|
|
497
|
+
arrowprops=dict(arrowstyle="->"),
|
|
498
|
+
)
|
|
499
|
+
self.annot.set_visible(False)
|
|
500
|
+
|
|
501
|
+
xmin, xmax = self.ax_scatter.get_xlim()
|
|
502
|
+
ymin, ymax = self.ax_scatter.get_ylim()
|
|
503
|
+
xdatarange = xmax - xmin
|
|
504
|
+
ydatarange = ymax - ymin
|
|
505
|
+
|
|
506
|
+
self.ax_scatter.set_xlim(xmin - 0.1 * xdatarange, xmax + 0.1 * xdatarange)
|
|
507
|
+
self.ax_scatter.set_ylim(ymin - 0.1 * ydatarange, ymax + 0.1 * ydatarange)
|
|
508
|
+
|
|
509
|
+
# xmin,xmax = self.ax_scatter.get_xlim()
|
|
510
|
+
# ymin,ymax = self.ax_scatter.get_ylim()
|
|
511
|
+
# desired_a = 4
|
|
512
|
+
# new_x_max = xmin + desired_a * (ymax - ymin)
|
|
513
|
+
# self.ax_scatter.set_xlim(xmin - (new_x_max - xmin)/2.0, new_x_max - (new_x_max - xmin)/2.0)
|
|
514
|
+
|
|
515
|
+
self.fig_scatter.tight_layout()
|
|
516
|
+
self.fig_scatter.canvas.mpl_connect("motion_notify_event", self.hover)
|
|
517
|
+
self.fig_scatter.canvas.mpl_connect("pick_event", self.unselect_position)
|
|
518
|
+
except Exception as e:
|
|
519
|
+
pass
|
|
520
|
+
|
|
521
|
+
def update_annot(self, ind):
|
|
522
|
+
|
|
523
|
+
pos = self.sc.get_offsets()[ind["ind"][0]]
|
|
524
|
+
self.annot.xy = pos
|
|
525
|
+
text = self.scat_labels[ind["ind"][0]]
|
|
526
|
+
self.annot.set_text(text)
|
|
527
|
+
self.annot.get_bbox_patch().set_facecolor("k")
|
|
528
|
+
self.annot.get_bbox_patch().set_alpha(0.4)
|
|
529
|
+
|
|
530
|
+
def hover(self, event):
|
|
531
|
+
vis = self.annot.get_visible()
|
|
532
|
+
if event.inaxes == self.ax_scatter:
|
|
533
|
+
cont, ind = self.sc.contains(event)
|
|
534
|
+
if cont:
|
|
535
|
+
self.update_annot(ind)
|
|
536
|
+
self.annot.set_visible(True)
|
|
537
|
+
self.fig_scatter.canvas.draw_idle()
|
|
538
|
+
else:
|
|
539
|
+
if vis:
|
|
540
|
+
self.annot.set_visible(False)
|
|
541
|
+
self.fig_scatter.canvas.draw_idle()
|
|
542
|
+
|
|
543
|
+
def unselect_position(self, event):
|
|
544
|
+
|
|
545
|
+
ind = event.ind # index of selected position
|
|
546
|
+
well_idx = self.df_pos_info.iloc[ind]["well_index"].values[0]
|
|
547
|
+
selectedPos = self.df_pos_info.iloc[ind]["pos_path"].values[0]
|
|
548
|
+
currentSelState = self.df_pos_info.iloc[ind]["select"].values[0]
|
|
549
|
+
if self.plot_options[0].isChecked() or self.plot_options[2].isChecked():
|
|
550
|
+
self.df_pos_info.loc[
|
|
551
|
+
self.df_pos_info["well_index"] == well_idx, "select"
|
|
552
|
+
] = not currentSelState
|
|
553
|
+
self.df_well_info.loc[
|
|
554
|
+
self.df_well_info["well_index"] == well_idx, "select"
|
|
555
|
+
] = not currentSelState
|
|
556
|
+
if len(self.parent_window.well_indices) > 1:
|
|
557
|
+
self.well_display_options[well_idx].setChecked(not currentSelState)
|
|
558
|
+
else:
|
|
559
|
+
for p in self.pos_display_options:
|
|
560
|
+
p.setChecked(not currentSelState)
|
|
561
|
+
else:
|
|
562
|
+
self.df_pos_info.loc[
|
|
563
|
+
self.df_pos_info["pos_path"] == selectedPos, "select"
|
|
564
|
+
] = not currentSelState
|
|
565
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
566
|
+
self.pos_display_options[ind[0]].setChecked(not currentSelState)
|
|
567
|
+
|
|
568
|
+
self.sc.set_color(self.select_color(self.df_pos_info["select"].values))
|
|
569
|
+
self.position_scatter.canvas.draw_idle()
|
|
570
|
+
self.plot_signals(0)
|
|
571
|
+
|
|
572
|
+
def select_color(self, selection):
|
|
573
|
+
colors = [tab10(0) if s else tab10(0.1) for s in selection]
|
|
574
|
+
return colors
|
|
575
|
+
|
|
576
|
+
def initialize_axis(self):
|
|
577
|
+
|
|
578
|
+
previous_ymin, previous_ymax = self.ax.get_ylim()
|
|
579
|
+
previous_legend = self.legend_visible
|
|
580
|
+
is_log = self.ax.get_yscale()
|
|
581
|
+
|
|
582
|
+
self.ax.clear()
|
|
583
|
+
self.ax.plot([], [])
|
|
584
|
+
|
|
585
|
+
# Labels
|
|
586
|
+
self.ax.set_xlabel("time [min]")
|
|
587
|
+
self.ax.set_ylabel(self.feature_selected)
|
|
588
|
+
|
|
589
|
+
# Spines
|
|
590
|
+
self.ax.spines["top"].set_visible(False)
|
|
591
|
+
self.ax.spines["right"].set_visible(False)
|
|
592
|
+
self.ax.grid(
|
|
593
|
+
which="major", color="black", linestyle="-", linewidth=0.8, alpha=0.2
|
|
594
|
+
)
|
|
595
|
+
self.ax.grid(
|
|
596
|
+
which="minor", color="lightgray", linestyle="--", linewidth=0.5, alpha=0.1
|
|
597
|
+
)
|
|
598
|
+
# Lims
|
|
599
|
+
safe_df = self.df.dropna(subset=self.feature_selected)
|
|
600
|
+
values = safe_df[self.feature_selected].values
|
|
601
|
+
if len(values) > 0:
|
|
602
|
+
self.ax.set_ylim(
|
|
603
|
+
np.percentile(values, 1) * self.scaling_factor,
|
|
604
|
+
np.percentile(values, 99) * self.scaling_factor,
|
|
605
|
+
)
|
|
606
|
+
self.ax.set_xlim(
|
|
607
|
+
-(self.df["FRAME"].max() + 2) * self.parent_window.FrameToMin,
|
|
608
|
+
(self.df["FRAME"].max() + 2) * self.parent_window.FrameToMin,
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
if is_log == "log":
|
|
612
|
+
self.ax.set_yscale("log")
|
|
613
|
+
if previous_legend:
|
|
614
|
+
leg = self.ax.get_legend()
|
|
615
|
+
if leg is not None:
|
|
616
|
+
leg.set_visible(True)
|
|
617
|
+
|
|
618
|
+
def show_hide_legend(self):
|
|
619
|
+
|
|
620
|
+
if self.legend_visible:
|
|
621
|
+
leg = self.ax.get_legend()
|
|
622
|
+
leg.set_visible(False)
|
|
623
|
+
self.legend_visible = False
|
|
624
|
+
self.legend_btn.setIcon(icon(MDI6.text_box, color="black"))
|
|
625
|
+
else:
|
|
626
|
+
leg = self.ax.get_legend()
|
|
627
|
+
leg.set_visible(True)
|
|
628
|
+
self.legend_visible = True
|
|
629
|
+
self.legend_btn.setIcon(icon(MDI6.text_box, color=self.help_color))
|
|
630
|
+
|
|
631
|
+
self.plot_widget.canvas.draw_idle()
|
|
632
|
+
|
|
633
|
+
def switch_to_log(self):
|
|
634
|
+
"""
|
|
635
|
+
Switch threshold histogram to log scale. Auto adjust.
|
|
636
|
+
"""
|
|
637
|
+
|
|
638
|
+
if self.ax.get_yscale() == "linear":
|
|
639
|
+
self.ax.set_yscale("log")
|
|
640
|
+
self.log_btn.setIcon(icon(MDI6.math_log, color=self.help_color))
|
|
641
|
+
# self.ax.set_ylim(0.01,1.05)
|
|
642
|
+
else:
|
|
643
|
+
self.ax.set_yscale("linear")
|
|
644
|
+
self.log_btn.setIcon(icon(MDI6.math_log, color="black"))
|
|
645
|
+
# self.ax.set_ylim(0.01,1.05)
|
|
646
|
+
|
|
647
|
+
# self.ax.autoscale()
|
|
648
|
+
self.plot_widget.canvas.draw_idle()
|
|
649
|
+
|
|
650
|
+
def plot_signals(self, id):
|
|
651
|
+
|
|
652
|
+
for i in range(3):
|
|
653
|
+
if self.plot_options[i].isChecked():
|
|
654
|
+
self.plot_mode = self.radio_labels[i]
|
|
655
|
+
|
|
656
|
+
if self.target_class == [0, 1]:
|
|
657
|
+
mean_signal_type = "mean_all"
|
|
658
|
+
std_signal = "std_all"
|
|
659
|
+
matrix = "matrix_all"
|
|
660
|
+
elif self.target_class == [0]:
|
|
661
|
+
mean_signal_type = "mean_event"
|
|
662
|
+
std_signal = "std_event"
|
|
663
|
+
matrix = "matrix_event"
|
|
664
|
+
else:
|
|
665
|
+
mean_signal_type = "mean_no_event"
|
|
666
|
+
std_signal = "std_no_event"
|
|
667
|
+
matrix = "matrix_no_event"
|
|
668
|
+
|
|
669
|
+
colors = np.array(
|
|
670
|
+
[self.cmap(i / len(self.df_pos_info)) for i in range(len(self.df_pos_info))]
|
|
671
|
+
)
|
|
672
|
+
well_color = [
|
|
673
|
+
self.cmap(i / len(self.df_well_info)) for i in range(len(self.df_well_info))
|
|
674
|
+
]
|
|
675
|
+
|
|
676
|
+
if self.plot_mode == "position":
|
|
677
|
+
self.initialize_axis()
|
|
678
|
+
lines = self.df_pos_info.loc[self.df_pos_info["select"], "signal"].values
|
|
679
|
+
pos_labels = self.df_pos_info.loc[
|
|
680
|
+
self.df_pos_info["select"], "pos_name"
|
|
681
|
+
].values
|
|
682
|
+
pos_indices = self.df_pos_info.loc[
|
|
683
|
+
self.df_pos_info["select"], "pos_index"
|
|
684
|
+
].values
|
|
685
|
+
well_index = self.df_pos_info.loc[
|
|
686
|
+
self.df_pos_info["select"], "well_index"
|
|
687
|
+
].values
|
|
688
|
+
for i in range(len(lines)):
|
|
689
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
690
|
+
self.plot_line(
|
|
691
|
+
lines[i],
|
|
692
|
+
colors[pos_indices[i]],
|
|
693
|
+
pos_labels[i],
|
|
694
|
+
mean_signal_type,
|
|
695
|
+
std_signal=std_signal,
|
|
696
|
+
ci_option=self.show_ci,
|
|
697
|
+
cell_lines_option=self.show_cell_lines,
|
|
698
|
+
matrix=matrix,
|
|
699
|
+
)
|
|
700
|
+
else:
|
|
701
|
+
self.plot_line(
|
|
702
|
+
lines[i],
|
|
703
|
+
well_color[well_index[i]],
|
|
704
|
+
pos_labels[i],
|
|
705
|
+
mean_signal_type,
|
|
706
|
+
std_signal=std_signal,
|
|
707
|
+
ci_option=self.show_ci,
|
|
708
|
+
cell_lines_option=self.show_cell_lines,
|
|
709
|
+
matrix=matrix,
|
|
710
|
+
)
|
|
711
|
+
if self.legend_visible:
|
|
712
|
+
self.ax.legend(ncols=3, fontsize="x-small")
|
|
713
|
+
|
|
714
|
+
elif self.plot_mode == "well":
|
|
715
|
+
self.initialize_axis()
|
|
716
|
+
lines = self.df_well_info.loc[self.df_well_info["select"], "signal"].values
|
|
717
|
+
well_index = self.df_well_info.loc[
|
|
718
|
+
self.df_well_info["select"], "well_index"
|
|
719
|
+
].values
|
|
720
|
+
well_labels = self.df_well_info.loc[
|
|
721
|
+
self.df_well_info["select"], "well_name"
|
|
722
|
+
].values
|
|
723
|
+
for i in range(len(lines)):
|
|
724
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
725
|
+
self.plot_line(
|
|
726
|
+
lines[i],
|
|
727
|
+
"k",
|
|
728
|
+
well_labels[i],
|
|
729
|
+
mean_signal_type,
|
|
730
|
+
std_signal=std_signal,
|
|
731
|
+
ci_option=self.show_ci,
|
|
732
|
+
cell_lines_option=self.show_cell_lines,
|
|
733
|
+
matrix=matrix,
|
|
734
|
+
)
|
|
735
|
+
else:
|
|
736
|
+
self.plot_line(
|
|
737
|
+
lines[i],
|
|
738
|
+
well_color[well_index[i]],
|
|
739
|
+
well_labels[i],
|
|
740
|
+
mean_signal_type,
|
|
741
|
+
std_signal=std_signal,
|
|
742
|
+
ci_option=self.show_ci,
|
|
743
|
+
cell_lines_option=self.show_cell_lines,
|
|
744
|
+
matrix=matrix,
|
|
745
|
+
)
|
|
746
|
+
if self.legend_visible:
|
|
747
|
+
self.ax.legend(ncols=2, fontsize="x-small")
|
|
748
|
+
|
|
749
|
+
elif self.plot_mode == "both":
|
|
750
|
+
|
|
751
|
+
self.initialize_axis()
|
|
752
|
+
lines_pos = self.df_pos_info.loc[
|
|
753
|
+
self.df_pos_info["select"], "signal"
|
|
754
|
+
].values
|
|
755
|
+
lines_well = self.df_well_info.loc[
|
|
756
|
+
self.df_well_info["select"], "signal"
|
|
757
|
+
].values
|
|
758
|
+
|
|
759
|
+
pos_indices = self.df_pos_info.loc[
|
|
760
|
+
self.df_pos_info["select"], "pos_index"
|
|
761
|
+
].values
|
|
762
|
+
well_index_pos = self.df_pos_info.loc[
|
|
763
|
+
self.df_pos_info["select"], "well_index"
|
|
764
|
+
].values
|
|
765
|
+
well_index = self.df_well_info.loc[
|
|
766
|
+
self.df_well_info["select"], "well_index"
|
|
767
|
+
].values
|
|
768
|
+
well_labels = self.df_well_info.loc[
|
|
769
|
+
self.df_well_info["select"], "well_name"
|
|
770
|
+
].values
|
|
771
|
+
pos_labels = self.df_pos_info.loc[
|
|
772
|
+
self.df_pos_info["select"], "pos_name"
|
|
773
|
+
].values
|
|
774
|
+
|
|
775
|
+
for i in range(len(lines_pos)):
|
|
776
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
777
|
+
self.plot_line(
|
|
778
|
+
lines_pos[i],
|
|
779
|
+
colors[pos_indices[i]],
|
|
780
|
+
pos_labels[i],
|
|
781
|
+
mean_signal_type,
|
|
782
|
+
std_signal=std_signal,
|
|
783
|
+
ci_option=self.show_ci,
|
|
784
|
+
cell_lines_option=self.show_cell_lines,
|
|
785
|
+
matrix=matrix,
|
|
786
|
+
)
|
|
787
|
+
else:
|
|
788
|
+
self.plot_line(
|
|
789
|
+
lines_pos[i],
|
|
790
|
+
well_color[well_index_pos[i]],
|
|
791
|
+
None,
|
|
792
|
+
mean_signal_type,
|
|
793
|
+
std_signal=std_signal,
|
|
794
|
+
ci_option=False,
|
|
795
|
+
)
|
|
796
|
+
|
|
797
|
+
for i in range(len(lines_well)):
|
|
798
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
799
|
+
self.plot_line(
|
|
800
|
+
lines_well[i],
|
|
801
|
+
"k",
|
|
802
|
+
"pool",
|
|
803
|
+
mean_signal_type,
|
|
804
|
+
std_signal=std_signal,
|
|
805
|
+
ci_option=False,
|
|
806
|
+
)
|
|
807
|
+
else:
|
|
808
|
+
self.plot_line(
|
|
809
|
+
lines_well[i],
|
|
810
|
+
well_color[well_index[i]],
|
|
811
|
+
well_labels[i],
|
|
812
|
+
mean_signal_type,
|
|
813
|
+
std_signal=std_signal,
|
|
814
|
+
ci_option=False,
|
|
815
|
+
)
|
|
816
|
+
if self.legend_visible:
|
|
817
|
+
self.ax.legend(ncols=3, fontsize="x-small")
|
|
818
|
+
|
|
819
|
+
self.plot_widget.canvas.draw()
|
|
820
|
+
|
|
821
|
+
def plot_line(
|
|
822
|
+
self,
|
|
823
|
+
line,
|
|
824
|
+
color,
|
|
825
|
+
label,
|
|
826
|
+
mean_signal_type,
|
|
827
|
+
ci_option=True,
|
|
828
|
+
cell_lines_option=False,
|
|
829
|
+
alpha_ci=0.5,
|
|
830
|
+
std_signal=None,
|
|
831
|
+
matrix=None,
|
|
832
|
+
):
|
|
833
|
+
|
|
834
|
+
# Plot a signal
|
|
835
|
+
if line == line:
|
|
836
|
+
self.ax.plot(
|
|
837
|
+
line["timeline"] * self.parent_window.FrameToMin,
|
|
838
|
+
line[mean_signal_type] * self.scaling_factor,
|
|
839
|
+
color=color,
|
|
840
|
+
label=label,
|
|
841
|
+
)
|
|
842
|
+
|
|
843
|
+
if ci_option and std_signal is not None:
|
|
844
|
+
|
|
845
|
+
self.ax.fill_between(
|
|
846
|
+
line["timeline"] * self.parent_window.FrameToMin,
|
|
847
|
+
[
|
|
848
|
+
a - b
|
|
849
|
+
for a, b in zip(
|
|
850
|
+
line[mean_signal_type] * self.scaling_factor,
|
|
851
|
+
line[std_signal] * self.scaling_factor,
|
|
852
|
+
)
|
|
853
|
+
],
|
|
854
|
+
[
|
|
855
|
+
a + b
|
|
856
|
+
for a, b in zip(
|
|
857
|
+
line[mean_signal_type] * self.scaling_factor,
|
|
858
|
+
line[std_signal] * self.scaling_factor,
|
|
859
|
+
)
|
|
860
|
+
],
|
|
861
|
+
color=color,
|
|
862
|
+
alpha=alpha_ci,
|
|
863
|
+
)
|
|
864
|
+
if cell_lines_option and matrix is not None:
|
|
865
|
+
# Show individual cell signals
|
|
866
|
+
mat = line[matrix]
|
|
867
|
+
for i in range(mat.shape[0]):
|
|
868
|
+
self.ax.plot(
|
|
869
|
+
line["timeline"] * self.parent_window.FrameToMin,
|
|
870
|
+
mat[i, :] * self.scaling_factor,
|
|
871
|
+
color=color,
|
|
872
|
+
alpha=self.alpha_setting,
|
|
873
|
+
)
|
|
874
|
+
|
|
875
|
+
def switch_ci(self):
|
|
876
|
+
|
|
877
|
+
# Show the confidence interval / STD
|
|
878
|
+
|
|
879
|
+
if self.show_ci:
|
|
880
|
+
self.ci_btn.setIcon(icon(MDI6.arrow_expand_horizontal, color="black"))
|
|
881
|
+
else:
|
|
882
|
+
self.ci_btn.setIcon(
|
|
883
|
+
icon(MDI6.arrow_expand_horizontal, color=self.help_color)
|
|
884
|
+
)
|
|
885
|
+
self.show_ci = not self.show_ci
|
|
886
|
+
try:
|
|
887
|
+
self.plot_signals(0)
|
|
888
|
+
except Exception as e:
|
|
889
|
+
print(f"{e=}")
|
|
890
|
+
|
|
891
|
+
def switch_cell_lines(self):
|
|
892
|
+
|
|
893
|
+
# Show individual cell signals
|
|
894
|
+
|
|
895
|
+
if self.show_cell_lines:
|
|
896
|
+
self.cell_lines_btn.setIcon(icon(MDI6.view_headline, color="black"))
|
|
897
|
+
else:
|
|
898
|
+
self.cell_lines_btn.setIcon(icon(MDI6.view_headline, color=self.help_color))
|
|
899
|
+
self.show_cell_lines = not self.show_cell_lines
|
|
900
|
+
self.plot_signals(0)
|
|
901
|
+
|
|
902
|
+
def select_lines(self):
|
|
903
|
+
|
|
904
|
+
if len(self.parent_window.well_indices) > 1:
|
|
905
|
+
for i in range(len(self.well_display_options)):
|
|
906
|
+
self.df_well_info.loc[
|
|
907
|
+
self.df_well_info["well_index"] == i, "select"
|
|
908
|
+
] = self.well_display_options[i].isChecked()
|
|
909
|
+
self.df_pos_info.loc[self.df_pos_info["well_index"] == i, "select"] = (
|
|
910
|
+
self.well_display_options[i].isChecked()
|
|
911
|
+
)
|
|
912
|
+
else:
|
|
913
|
+
for i in range(len(self.pos_display_options)):
|
|
914
|
+
self.df_pos_info.loc[self.df_pos_info["pos_index"] == i, "select"] = (
|
|
915
|
+
self.pos_display_options[i].isChecked()
|
|
916
|
+
)
|
|
917
|
+
|
|
918
|
+
if len(self.metafiles) > 0:
|
|
919
|
+
self.sc.set_color(self.select_color(self.df_pos_info["select"].values))
|
|
920
|
+
self.position_scatter.canvas.draw_idle()
|
|
921
|
+
self.plot_signals(0)
|
|
922
|
+
|
|
694
923
|
|
|
695
924
|
class SurvivalPlotWidget(GenericSignalPlotWidget):
|
|
696
925
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
926
|
+
def __init__(self, *args, **kwargs):
|
|
927
|
+
|
|
928
|
+
super(SurvivalPlotWidget, self).__init__(*args, **kwargs)
|
|
929
|
+
self.cell_lines_btn.hide()
|
|
930
|
+
self.class_selection_widget.hide()
|
|
931
|
+
self.rescale_widget.hide()
|
|
932
|
+
self.cell_lines_alpha_wdg.hide()
|
|
933
|
+
self.export_tabular_btn.show()
|
|
934
|
+
self.export_tabular_btn.clicked.connect(self.set_table_options)
|
|
935
|
+
|
|
936
|
+
def switch_to_log(self):
|
|
937
|
+
"""
|
|
938
|
+
Switch threshold histogram to log scale. Auto adjust.
|
|
939
|
+
"""
|
|
940
|
+
|
|
941
|
+
if self.ax.get_yscale() == "linear":
|
|
942
|
+
ymin, _ = self.ax.get_ylim()
|
|
943
|
+
self.ax.set_ylim(max(ymin, 0.01), 1.05)
|
|
944
|
+
self.ax.set_yscale("log")
|
|
945
|
+
self.log_btn.setIcon(icon(MDI6.math_log, color=self.help_color))
|
|
946
|
+
else:
|
|
947
|
+
self.ax.set_yscale("linear")
|
|
948
|
+
self.log_btn.setIcon(icon(MDI6.math_log, color="black"))
|
|
949
|
+
# self.ax.set_ylim(0.01,1.05)
|
|
950
|
+
|
|
951
|
+
# self.ax.autoscale()
|
|
952
|
+
self.plot_widget.canvas.draw_idle()
|
|
953
|
+
|
|
954
|
+
def initialize_axis(self):
|
|
955
|
+
|
|
956
|
+
previous_legend = self.legend_visible
|
|
957
|
+
is_log = self.ax.get_yscale()
|
|
958
|
+
|
|
959
|
+
self.ax.clear()
|
|
960
|
+
self.ax.plot([], [])
|
|
961
|
+
|
|
962
|
+
# Labels
|
|
963
|
+
self.ax.set_xlabel("time [min]")
|
|
964
|
+
self.ax.set_ylabel("survival")
|
|
965
|
+
|
|
966
|
+
# Spines
|
|
967
|
+
self.ax.spines["top"].set_visible(False)
|
|
968
|
+
self.ax.spines["right"].set_visible(False)
|
|
969
|
+
|
|
970
|
+
# Lims
|
|
971
|
+
self.ax.set_xlim(
|
|
972
|
+
0 * self.parent_window.FrameToMin,
|
|
973
|
+
(self.df["FRAME"].max() + 2) * self.parent_window.FrameToMin,
|
|
974
|
+
)
|
|
975
|
+
if is_log == "log":
|
|
976
|
+
ymin = 0.1
|
|
977
|
+
else:
|
|
978
|
+
ymin = 0.0
|
|
979
|
+
self.ax.set_ylim(ymin, 1.05)
|
|
980
|
+
|
|
981
|
+
if is_log == "log":
|
|
982
|
+
self.ax.set_yscale("log")
|
|
983
|
+
if previous_legend:
|
|
984
|
+
leg = self.ax.get_legend()
|
|
985
|
+
if leg is not None:
|
|
986
|
+
leg.set_visible(True)
|
|
987
|
+
|
|
988
|
+
def plot_signals(self, id):
|
|
989
|
+
|
|
990
|
+
for i in range(3):
|
|
991
|
+
if self.plot_options[i].isChecked():
|
|
992
|
+
self.plot_mode = self.radio_labels[i]
|
|
993
|
+
|
|
994
|
+
colors = np.array(
|
|
995
|
+
[self.cmap(i / len(self.df_pos_info)) for i in range(len(self.df_pos_info))]
|
|
996
|
+
)
|
|
997
|
+
well_color = [
|
|
998
|
+
self.cmap(i / len(self.df_well_info)) for i in range(len(self.df_well_info))
|
|
999
|
+
]
|
|
1000
|
+
|
|
1001
|
+
if self.plot_mode == "position":
|
|
1002
|
+
self.initialize_axis()
|
|
1003
|
+
lines = self.df_pos_info.loc[
|
|
1004
|
+
self.df_pos_info["select"], "survival_fit"
|
|
1005
|
+
].values
|
|
1006
|
+
pos_labels = self.df_pos_info.loc[
|
|
1007
|
+
self.df_pos_info["select"], "pos_name"
|
|
1008
|
+
].values
|
|
1009
|
+
pos_indices = self.df_pos_info.loc[
|
|
1010
|
+
self.df_pos_info["select"], "pos_index"
|
|
1011
|
+
].values
|
|
1012
|
+
well_index = self.df_pos_info.loc[
|
|
1013
|
+
self.df_pos_info["select"], "well_index"
|
|
1014
|
+
].values
|
|
1015
|
+
for i in range(len(lines)):
|
|
1016
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
1017
|
+
self.plot_line(
|
|
1018
|
+
lines[i],
|
|
1019
|
+
colors[pos_indices[i]],
|
|
1020
|
+
pos_labels[i],
|
|
1021
|
+
ci_option=self.show_ci,
|
|
1022
|
+
)
|
|
1023
|
+
else:
|
|
1024
|
+
self.plot_line(
|
|
1025
|
+
lines[i],
|
|
1026
|
+
well_color[well_index[i]],
|
|
1027
|
+
pos_labels[i],
|
|
1028
|
+
ci_option=self.show_ci,
|
|
1029
|
+
)
|
|
1030
|
+
if self.legend_visible:
|
|
1031
|
+
self.ax.legend(ncols=3, fontsize="x-small")
|
|
1032
|
+
|
|
1033
|
+
elif self.plot_mode == "well":
|
|
1034
|
+
self.initialize_axis()
|
|
1035
|
+
lines = self.df_well_info.loc[
|
|
1036
|
+
self.df_well_info["select"], "survival_fit"
|
|
1037
|
+
].values
|
|
1038
|
+
well_index = self.df_well_info.loc[
|
|
1039
|
+
self.df_well_info["select"], "well_index"
|
|
1040
|
+
].values
|
|
1041
|
+
well_labels = self.df_well_info.loc[
|
|
1042
|
+
self.df_well_info["select"], "well_name"
|
|
1043
|
+
].values
|
|
1044
|
+
for i in range(len(lines)):
|
|
1045
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
1046
|
+
self.plot_line(
|
|
1047
|
+
lines[i],
|
|
1048
|
+
"k",
|
|
1049
|
+
well_labels[i],
|
|
1050
|
+
ci_option=self.show_ci,
|
|
1051
|
+
legend=True,
|
|
1052
|
+
)
|
|
1053
|
+
else:
|
|
1054
|
+
self.plot_line(
|
|
1055
|
+
lines[i],
|
|
1056
|
+
well_color[well_index[i]],
|
|
1057
|
+
well_labels[i],
|
|
1058
|
+
ci_option=self.show_ci,
|
|
1059
|
+
legend=True,
|
|
1060
|
+
)
|
|
1061
|
+
if self.legend_visible:
|
|
1062
|
+
self.ax.legend(ncols=2, fontsize="x-small")
|
|
1063
|
+
|
|
1064
|
+
elif self.plot_mode == "both":
|
|
1065
|
+
|
|
1066
|
+
self.initialize_axis()
|
|
1067
|
+
lines_pos = self.df_pos_info.loc[
|
|
1068
|
+
self.df_pos_info["select"], "survival_fit"
|
|
1069
|
+
].values
|
|
1070
|
+
lines_well = self.df_well_info.loc[
|
|
1071
|
+
self.df_well_info["select"], "survival_fit"
|
|
1072
|
+
].values
|
|
1073
|
+
|
|
1074
|
+
pos_indices = self.df_pos_info.loc[
|
|
1075
|
+
self.df_pos_info["select"], "pos_index"
|
|
1076
|
+
].values
|
|
1077
|
+
well_index_pos = self.df_pos_info.loc[
|
|
1078
|
+
self.df_pos_info["select"], "well_index"
|
|
1079
|
+
].values
|
|
1080
|
+
well_index = self.df_well_info.loc[
|
|
1081
|
+
self.df_well_info["select"], "well_index"
|
|
1082
|
+
].values
|
|
1083
|
+
well_labels = self.df_well_info.loc[
|
|
1084
|
+
self.df_well_info["select"], "well_name"
|
|
1085
|
+
].values
|
|
1086
|
+
pos_labels = self.df_pos_info.loc[
|
|
1087
|
+
self.df_pos_info["select"], "pos_name"
|
|
1088
|
+
].values
|
|
1089
|
+
|
|
1090
|
+
for i in range(len(lines_pos)):
|
|
1091
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
1092
|
+
self.plot_line(
|
|
1093
|
+
lines_pos[i],
|
|
1094
|
+
colors[pos_indices[i]],
|
|
1095
|
+
pos_labels[i],
|
|
1096
|
+
ci_option=self.show_ci,
|
|
1097
|
+
legend=True,
|
|
1098
|
+
)
|
|
1099
|
+
else:
|
|
1100
|
+
self.plot_line(
|
|
1101
|
+
lines_pos[i],
|
|
1102
|
+
well_color[well_index_pos[i]],
|
|
1103
|
+
None,
|
|
1104
|
+
ci_option=False,
|
|
1105
|
+
)
|
|
1106
|
+
|
|
1107
|
+
for i in range(len(lines_well)):
|
|
1108
|
+
if len(self.parent_window.well_indices) <= 1:
|
|
1109
|
+
self.plot_line(
|
|
1110
|
+
lines_well[i], "k", "pool", ci_option=False, legend=True
|
|
1111
|
+
)
|
|
1112
|
+
else:
|
|
1113
|
+
self.plot_line(
|
|
1114
|
+
lines_well[i],
|
|
1115
|
+
well_color[well_index[i]],
|
|
1116
|
+
well_labels[i],
|
|
1117
|
+
ci_option=False,
|
|
1118
|
+
legend=True,
|
|
1119
|
+
)
|
|
1120
|
+
if self.legend_visible:
|
|
1121
|
+
self.ax.legend(ncols=3, fontsize="x-small")
|
|
1122
|
+
|
|
1123
|
+
self.plot_widget.canvas.draw()
|
|
1124
|
+
|
|
1125
|
+
def plot_line(self, line, color, label, ci_option=True, legend=None, alpha_ci=0.5):
|
|
1126
|
+
|
|
1127
|
+
# Plot a signal
|
|
1128
|
+
if line == line:
|
|
1129
|
+
line.plot_survival_function(
|
|
1130
|
+
ci_show=ci_option,
|
|
1131
|
+
ax=self.ax,
|
|
1132
|
+
legend=legend,
|
|
1133
|
+
color=color,
|
|
1134
|
+
label=label,
|
|
1135
|
+
xlabel="timeline [min]",
|
|
1136
|
+
)
|
|
1137
|
+
|
|
1138
|
+
def set_table_options(self):
|
|
1139
|
+
|
|
1140
|
+
self.config_table_wg = CelldetectiveWidget()
|
|
1141
|
+
self.config_table_wg.setMinimumWidth(480)
|
|
1142
|
+
self.config_table_wg.setWindowTitle("Survival data")
|
|
1143
|
+
|
|
1144
|
+
layout = QVBoxLayout()
|
|
1145
|
+
self.config_table_wg.setLayout(layout)
|
|
1146
|
+
|
|
1147
|
+
self.all_values_rb = QRadioButton("tabulate all values")
|
|
1148
|
+
self.single_timepoint_rb = QRadioButton("survival at single timepoint [min]: ")
|
|
1149
|
+
self.ec_rb = QRadioButton(r"EC N% survival: ")
|
|
1150
|
+
self.all_values_rb.toggled.connect(self.activate_sliders)
|
|
1151
|
+
self.single_timepoint_rb.toggled.connect(self.activate_sliders)
|
|
1152
|
+
|
|
1153
|
+
self.single_timepoint_slider = QLabeledSlider()
|
|
1154
|
+
self.single_timepoint_slider.setRange(
|
|
1155
|
+
0, int(self.df["FRAME"].max() * self.parent_window.FrameToMin)
|
|
1156
|
+
)
|
|
1157
|
+
self.single_timepoint_slider.setValue(
|
|
1158
|
+
int(self.df["FRAME"].max() * self.parent_window.FrameToMin)
|
|
1159
|
+
)
|
|
1160
|
+
|
|
1161
|
+
self.ec_slider = QLabeledSlider()
|
|
1162
|
+
self.ec_slider.setRange(0, 100)
|
|
1163
|
+
self.ec_slider.setValue(50)
|
|
1164
|
+
|
|
1165
|
+
self.ec_rb.toggled.connect(self.activate_sliders)
|
|
1166
|
+
self.all_values_rb.click()
|
|
1167
|
+
|
|
1168
|
+
self.set_btn = QPushButton("Set")
|
|
1169
|
+
self.set_btn.setStyleSheet(self.button_style_sheet)
|
|
1170
|
+
self.set_btn.clicked.connect(self.assemble_survival_data)
|
|
1171
|
+
|
|
1172
|
+
layout.addWidget(self.all_values_rb)
|
|
1173
|
+
|
|
1174
|
+
single_tp_layout = QHBoxLayout()
|
|
1175
|
+
single_tp_layout.addWidget(self.single_timepoint_rb, 33)
|
|
1176
|
+
single_tp_layout.addWidget(self.single_timepoint_slider, 66)
|
|
1177
|
+
layout.addLayout(single_tp_layout)
|
|
1178
|
+
|
|
1179
|
+
ec_layout = QHBoxLayout()
|
|
1180
|
+
ec_layout.addWidget(self.ec_rb, 33)
|
|
1181
|
+
ec_layout.addWidget(self.ec_slider, 66)
|
|
1182
|
+
layout.addLayout(ec_layout)
|
|
1183
|
+
|
|
1184
|
+
layout.addWidget(self.set_btn)
|
|
1185
|
+
center_window(self.config_table_wg)
|
|
1186
|
+
self.config_table_wg.show()
|
|
1187
|
+
|
|
1188
|
+
def activate_sliders(self):
|
|
1189
|
+
if self.all_values_rb.isChecked():
|
|
1190
|
+
self.single_timepoint_slider.setEnabled(False)
|
|
1191
|
+
self.ec_slider.setEnabled(False)
|
|
1192
|
+
elif self.single_timepoint_rb.isChecked():
|
|
1193
|
+
self.single_timepoint_slider.setEnabled(True)
|
|
1194
|
+
self.ec_slider.setEnabled(False)
|
|
1195
|
+
elif self.ec_rb.isChecked():
|
|
1196
|
+
self.ec_slider.setEnabled(True)
|
|
1197
|
+
self.single_timepoint_slider.setEnabled(False)
|
|
1198
|
+
|
|
1199
|
+
def assemble_survival_data(self):
|
|
1200
|
+
|
|
1201
|
+
if self.plot_options[0].isChecked():
|
|
1202
|
+
data = self.df_well_info
|
|
1203
|
+
groupby = ["well_path"]
|
|
1204
|
+
if self.plot_options[1].isChecked():
|
|
1205
|
+
data = self.df_pos_info
|
|
1206
|
+
groupby = ["pos_path"]
|
|
1207
|
+
if self.plot_options[2].isChecked():
|
|
1208
|
+
print(
|
|
1209
|
+
'Not implemented yet... Please select "well" or "position" as grouping...'
|
|
1210
|
+
)
|
|
1211
|
+
return None
|
|
1212
|
+
|
|
1213
|
+
if self.all_values_rb.isChecked():
|
|
1214
|
+
|
|
1215
|
+
survival_table = []
|
|
1216
|
+
tid = 0
|
|
1217
|
+
for name, group in data.groupby(groupby):
|
|
1218
|
+
print(name)
|
|
1219
|
+
if groupby[0] == "pos_path":
|
|
1220
|
+
metadata = collect_experiment_metadata(pos_path=name[0])
|
|
1221
|
+
elif groupby[0] == "well_path":
|
|
1222
|
+
metadata = collect_experiment_metadata(well_path=name[0])
|
|
1223
|
+
ks_estimator = group["survival_fit"].values[0]
|
|
1224
|
+
if ks_estimator != ks_estimator:
|
|
1225
|
+
continue
|
|
1226
|
+
timeline = list(ks_estimator.survival_function_.index)
|
|
1227
|
+
survival = ks_estimator.survival_function_["KM_estimate"].values
|
|
1228
|
+
lower_error = ks_estimator.confidence_interval_[
|
|
1229
|
+
"KM_estimate_lower_0.95"
|
|
1230
|
+
].values
|
|
1231
|
+
upper_error = ks_estimator.confidence_interval_[
|
|
1232
|
+
"KM_estimate_upper_0.95"
|
|
1233
|
+
].values
|
|
1234
|
+
for k in range(len(timeline)):
|
|
1235
|
+
dico = metadata.copy()
|
|
1236
|
+
dico.update(
|
|
1237
|
+
{
|
|
1238
|
+
"TRACK_ID": tid,
|
|
1239
|
+
"FRAME": int(timeline[k] / self.parent_window.FrameToMin),
|
|
1240
|
+
"timeline": timeline[k],
|
|
1241
|
+
"survival": survival[k],
|
|
1242
|
+
"event_fraction": 1 - survival[k],
|
|
1243
|
+
"KM_estimate_lower_0.95": lower_error[k],
|
|
1244
|
+
"KM_estimate_upper_0.95": upper_error[k],
|
|
1245
|
+
}
|
|
1246
|
+
)
|
|
1247
|
+
survival_table.append(dico)
|
|
1248
|
+
tid += 1
|
|
1249
|
+
|
|
1250
|
+
survival_table = pd.DataFrame(survival_table)
|
|
1251
|
+
self.table = TableUI(
|
|
1252
|
+
survival_table, f"Survival data", plot_mode="plot_track_signals"
|
|
1253
|
+
)
|
|
1254
|
+
self.table.show()
|
|
1255
|
+
|
|
1256
|
+
elif self.single_timepoint_rb.isChecked():
|
|
1257
|
+
|
|
1258
|
+
survival_table = []
|
|
1259
|
+
tid = 0
|
|
1260
|
+
for name, group in data.groupby(groupby):
|
|
1261
|
+
print(name)
|
|
1262
|
+
if groupby[0] == "pos_path":
|
|
1263
|
+
metadata = collect_experiment_metadata(pos_path=name[0])
|
|
1264
|
+
elif groupby[0] == "well_path":
|
|
1265
|
+
metadata = collect_experiment_metadata(well_path=name[0])
|
|
1266
|
+
ks_estimator = group["survival_fit"].values[0]
|
|
1267
|
+
if ks_estimator != ks_estimator:
|
|
1268
|
+
continue
|
|
1269
|
+
survival = ks_estimator.survival_function_at_times(
|
|
1270
|
+
self.single_timepoint_slider.value()
|
|
1271
|
+
).values[0]
|
|
1272
|
+
dico = metadata.copy()
|
|
1273
|
+
dico.update(
|
|
1274
|
+
{
|
|
1275
|
+
"timepoint": self.single_timepoint_slider.value(),
|
|
1276
|
+
"survival": survival,
|
|
1277
|
+
"event_fraction": 1 - survival,
|
|
1278
|
+
}
|
|
1279
|
+
)
|
|
1280
|
+
survival_table.append(dico)
|
|
1281
|
+
tid += 1
|
|
1282
|
+
|
|
1283
|
+
survival_table = pd.DataFrame(survival_table)
|
|
1284
|
+
self.table = TableUI(survival_table, f"Survival data", plot_mode="static")
|
|
1285
|
+
self.table.show()
|
|
1286
|
+
|
|
1287
|
+
elif self.ec_rb.isChecked():
|
|
1288
|
+
|
|
1289
|
+
survival_table = []
|
|
1290
|
+
tid = 0
|
|
1291
|
+
for name, group in data.groupby(groupby):
|
|
1292
|
+
print(name)
|
|
1293
|
+
if groupby[0] == "pos_path":
|
|
1294
|
+
metadata = collect_experiment_metadata(pos_path=name[0])
|
|
1295
|
+
elif groupby[0] == "well_path":
|
|
1296
|
+
metadata = collect_experiment_metadata(well_path=name[0])
|
|
1297
|
+
ks_estimator = group["survival_fit"].values[0]
|
|
1298
|
+
if ks_estimator != ks_estimator:
|
|
1299
|
+
continue
|
|
1300
|
+
survival = ks_estimator.survival_function_
|
|
1301
|
+
ecN = qth_survival_times(
|
|
1302
|
+
float(self.ec_slider.value()) / 100.0, survival
|
|
1303
|
+
)
|
|
1304
|
+
dico = metadata.copy()
|
|
1305
|
+
dico.update(
|
|
1306
|
+
{
|
|
1307
|
+
"qth": int(self.ec_slider.value()),
|
|
1308
|
+
f"EC{int(self.ec_slider.value())}% [min]": ecN,
|
|
1309
|
+
}
|
|
1310
|
+
)
|
|
1311
|
+
survival_table.append(dico)
|
|
1312
|
+
tid += 1
|
|
1313
|
+
|
|
1314
|
+
survival_table = pd.DataFrame(survival_table)
|
|
1315
|
+
self.table = TableUI(survival_table, f"Survival data", plot_mode="static")
|
|
1316
|
+
self.table.show()
|