mosamatic2 2.0.24__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.
- models.py +259 -0
- mosamatic2/__init__.py +0 -0
- mosamatic2/app.py +32 -0
- mosamatic2/cli.py +50 -0
- mosamatic2/commands/__init__.py +0 -0
- mosamatic2/commands/boadockerpipeline.py +48 -0
- mosamatic2/commands/calculatemaskstatistics.py +59 -0
- mosamatic2/commands/calculatescores.py +73 -0
- mosamatic2/commands/createdicomsummary.py +61 -0
- mosamatic2/commands/createpngsfromsegmentations.py +65 -0
- mosamatic2/commands/defaultdockerpipeline.py +84 -0
- mosamatic2/commands/defaultpipeline.py +70 -0
- mosamatic2/commands/dicom2nifti.py +55 -0
- mosamatic2/commands/liveranalysispipeline.py +61 -0
- mosamatic2/commands/rescaledicomimages.py +54 -0
- mosamatic2/commands/segmentmusclefatl3tensorflow.py +55 -0
- mosamatic2/commands/selectslicefromscans.py +66 -0
- mosamatic2/commands/totalsegmentator.py +77 -0
- mosamatic2/constants.py +27 -0
- mosamatic2/core/__init__.py +0 -0
- mosamatic2/core/data/__init__.py +5 -0
- mosamatic2/core/data/dicomimage.py +27 -0
- mosamatic2/core/data/dicomimageseries.py +26 -0
- mosamatic2/core/data/dixonseries.py +22 -0
- mosamatic2/core/data/filedata.py +26 -0
- mosamatic2/core/data/multidicomimage.py +30 -0
- mosamatic2/core/data/multiniftiimage.py +26 -0
- mosamatic2/core/data/multinumpyimage.py +26 -0
- mosamatic2/core/data/niftiimage.py +13 -0
- mosamatic2/core/data/numpyimage.py +13 -0
- mosamatic2/core/managers/__init__.py +0 -0
- mosamatic2/core/managers/logmanager.py +45 -0
- mosamatic2/core/managers/logmanagerlistener.py +3 -0
- mosamatic2/core/pipelines/__init__.py +4 -0
- mosamatic2/core/pipelines/boadockerpipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/boadockerpipeline/boadockerpipeline.py +70 -0
- mosamatic2/core/pipelines/defaultdockerpipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/defaultdockerpipeline/defaultdockerpipeline.py +28 -0
- mosamatic2/core/pipelines/defaultpipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/defaultpipeline/defaultpipeline.py +90 -0
- mosamatic2/core/pipelines/liveranalysispipeline/__init__.py +0 -0
- mosamatic2/core/pipelines/liveranalysispipeline/liveranalysispipeline.py +48 -0
- mosamatic2/core/pipelines/pipeline.py +14 -0
- mosamatic2/core/singleton.py +9 -0
- mosamatic2/core/tasks/__init__.py +13 -0
- mosamatic2/core/tasks/applythresholdtosegmentationstask/__init__.py +0 -0
- mosamatic2/core/tasks/applythresholdtosegmentationstask/applythresholdtosegmentationstask.py +117 -0
- mosamatic2/core/tasks/calculatemaskstatisticstask/__init__.py +0 -0
- mosamatic2/core/tasks/calculatemaskstatisticstask/calculatemaskstatisticstask.py +104 -0
- mosamatic2/core/tasks/calculatescorestask/__init__.py +0 -0
- mosamatic2/core/tasks/calculatescorestask/calculatescorestask.py +152 -0
- mosamatic2/core/tasks/createdicomsummarytask/__init__.py +0 -0
- mosamatic2/core/tasks/createdicomsummarytask/createdicomsummarytask.py +88 -0
- mosamatic2/core/tasks/createpngsfromsegmentationstask/__init__.py +0 -0
- mosamatic2/core/tasks/createpngsfromsegmentationstask/createpngsfromsegmentationstask.py +101 -0
- mosamatic2/core/tasks/dicom2niftitask/__init__.py +0 -0
- mosamatic2/core/tasks/dicom2niftitask/dicom2niftitask.py +45 -0
- mosamatic2/core/tasks/rescaledicomimagestask/__init__.py +0 -0
- mosamatic2/core/tasks/rescaledicomimagestask/rescaledicomimagestask.py +64 -0
- mosamatic2/core/tasks/segmentationnifti2numpytask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentationnifti2numpytask/segmentationnifti2numpytask.py +57 -0
- mosamatic2/core/tasks/segmentationnumpy2niftitask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentationnumpy2niftitask/segmentationnumpy2niftitask.py +86 -0
- mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/paramloader.py +39 -0
- mosamatic2/core/tasks/segmentmusclefatl3tensorflowtask/segmentmusclefatl3tensorflowtask.py +122 -0
- mosamatic2/core/tasks/segmentmusclefatt4pytorchtask/__init__.py +0 -0
- mosamatic2/core/tasks/segmentmusclefatt4pytorchtask/paramloader.py +39 -0
- mosamatic2/core/tasks/segmentmusclefatt4pytorchtask/segmentmusclefatt4pytorchtask.py +128 -0
- mosamatic2/core/tasks/selectslicefromscanstask/__init__.py +0 -0
- mosamatic2/core/tasks/selectslicefromscanstask/selectslicefromscanstask.py +249 -0
- mosamatic2/core/tasks/task.py +50 -0
- mosamatic2/core/tasks/totalsegmentatortask/__init__.py +0 -0
- mosamatic2/core/tasks/totalsegmentatortask/totalsegmentatortask.py +75 -0
- mosamatic2/core/utils.py +405 -0
- mosamatic2/server.py +146 -0
- mosamatic2/ui/__init__.py +0 -0
- mosamatic2/ui/mainwindow.py +426 -0
- mosamatic2/ui/resources/VERSION +1 -0
- mosamatic2/ui/resources/icons/mosamatic2.icns +0 -0
- mosamatic2/ui/resources/icons/mosamatic2.ico +0 -0
- mosamatic2/ui/resources/icons/spinner.gif +0 -0
- mosamatic2/ui/resources/images/body-composition.jpg +0 -0
- mosamatic2/ui/settings.py +62 -0
- mosamatic2/ui/utils.py +36 -0
- mosamatic2/ui/widgets/__init__.py +0 -0
- mosamatic2/ui/widgets/dialogs/__init__.py +0 -0
- mosamatic2/ui/widgets/dialogs/dialog.py +16 -0
- mosamatic2/ui/widgets/dialogs/helpdialog.py +9 -0
- mosamatic2/ui/widgets/panels/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/defaultpanel.py +31 -0
- mosamatic2/ui/widgets/panels/logpanel.py +65 -0
- mosamatic2/ui/widgets/panels/mainpanel.py +82 -0
- mosamatic2/ui/widgets/panels/pipelines/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/pipelines/boadockerpipelinepanel.py +195 -0
- mosamatic2/ui/widgets/panels/pipelines/defaultdockerpipelinepanel.py +314 -0
- mosamatic2/ui/widgets/panels/pipelines/defaultpipelinepanel.py +302 -0
- mosamatic2/ui/widgets/panels/pipelines/liveranalysispipelinepanel.py +187 -0
- mosamatic2/ui/widgets/panels/pipelines/pipelinepanel.py +6 -0
- mosamatic2/ui/widgets/panels/settingspanel.py +16 -0
- mosamatic2/ui/widgets/panels/stackedpanel.py +22 -0
- mosamatic2/ui/widgets/panels/tasks/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/tasks/applythresholdtosegmentationstaskpanel.py +271 -0
- mosamatic2/ui/widgets/panels/tasks/calculatemaskstatisticstaskpanel.py +215 -0
- mosamatic2/ui/widgets/panels/tasks/calculatescorestaskpanel.py +238 -0
- mosamatic2/ui/widgets/panels/tasks/createdicomsummarytaskpanel.py +206 -0
- mosamatic2/ui/widgets/panels/tasks/createpngsfromsegmentationstaskpanel.py +247 -0
- mosamatic2/ui/widgets/panels/tasks/dicom2niftitaskpanel.py +183 -0
- mosamatic2/ui/widgets/panels/tasks/rescaledicomimagestaskpanel.py +184 -0
- mosamatic2/ui/widgets/panels/tasks/segmentationnifti2numpytaskpanel.py +192 -0
- mosamatic2/ui/widgets/panels/tasks/segmentationnumpy2niftitaskpanel.py +213 -0
- mosamatic2/ui/widgets/panels/tasks/segmentmusclefatl3tensorflowtaskpanel.py +216 -0
- mosamatic2/ui/widgets/panels/tasks/segmentmusclefatt4pytorchtaskpanel.py +217 -0
- mosamatic2/ui/widgets/panels/tasks/selectslicefromscanstaskpanel.py +193 -0
- mosamatic2/ui/widgets/panels/tasks/taskpanel.py +6 -0
- mosamatic2/ui/widgets/panels/tasks/totalsegmentatortaskpanel.py +195 -0
- mosamatic2/ui/widgets/panels/visualizations/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/liversegmentpicker.py +96 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/liversegmentviewer.py +130 -0
- mosamatic2/ui/widgets/panels/visualizations/liversegmentvisualization/liversegmentvisualization.py +120 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/sliceselectionviewer.py +61 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/sliceselectionvisualization.py +133 -0
- mosamatic2/ui/widgets/panels/visualizations/sliceselectionvisualization/slicetile.py +63 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/__init__.py +0 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/custominteractorstyle.py +80 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/sliceviewer.py +116 -0
- mosamatic2/ui/widgets/panels/visualizations/slicevisualization/slicevisualization.py +141 -0
- mosamatic2/ui/widgets/panels/visualizations/visualization.py +6 -0
- mosamatic2/ui/widgets/splashscreen.py +101 -0
- mosamatic2/ui/worker.py +29 -0
- mosamatic2-2.0.24.dist-info/METADATA +43 -0
- mosamatic2-2.0.24.dist-info/RECORD +136 -0
- mosamatic2-2.0.24.dist-info/WHEEL +4 -0
- mosamatic2-2.0.24.dist-info/entry_points.txt +5 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import pathlib
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from PySide6.QtWidgets import (
|
|
7
|
+
QLineEdit,
|
|
8
|
+
QCheckBox,
|
|
9
|
+
QComboBox,
|
|
10
|
+
QDoubleSpinBox,
|
|
11
|
+
QHBoxLayout,
|
|
12
|
+
QVBoxLayout,
|
|
13
|
+
QFormLayout,
|
|
14
|
+
QPushButton,
|
|
15
|
+
QFileDialog,
|
|
16
|
+
QMessageBox,
|
|
17
|
+
)
|
|
18
|
+
from PySide6.QtCore import (
|
|
19
|
+
QThread,
|
|
20
|
+
Slot,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from mosamatic2.core.managers.logmanager import LogManager
|
|
24
|
+
from mosamatic2.ui.widgets.panels.tasks.taskpanel import TaskPanel
|
|
25
|
+
from mosamatic2.ui.settings import Settings
|
|
26
|
+
from mosamatic2.ui.utils import is_macos
|
|
27
|
+
from mosamatic2.ui.worker import Worker
|
|
28
|
+
from mosamatic2.core.tasks import ApplyThresholdToSegmentationsTask
|
|
29
|
+
|
|
30
|
+
LOG = LogManager()
|
|
31
|
+
|
|
32
|
+
PANEL_TITLE = 'ApplyThresholdToSegmentationsTask'
|
|
33
|
+
PANEL_NAME = 'applythresholdtosegmentationstaskpanel'
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ApplyThresholdToSegmentationsTaskPanel(TaskPanel):
|
|
37
|
+
def __init__(self):
|
|
38
|
+
super(ApplyThresholdToSegmentationsTaskPanel, self).__init__()
|
|
39
|
+
self.set_title(PANEL_TITLE)
|
|
40
|
+
self._images_dir_line_edit = None
|
|
41
|
+
self._images_dir_select_button = None
|
|
42
|
+
self._segmentations_dir_line_edit = None
|
|
43
|
+
self._segmentations_dir_select_button = None
|
|
44
|
+
self._output_dir_line_edit = None
|
|
45
|
+
self._output_dir_select_button = None
|
|
46
|
+
self._threshold_low_spinbox = None
|
|
47
|
+
self._threshold_high_spinbox = None
|
|
48
|
+
self._label_combobox = None
|
|
49
|
+
self._overwrite_checkbox = None
|
|
50
|
+
self._form_layout = None
|
|
51
|
+
self._run_task_button = None
|
|
52
|
+
self._open_excel_button = None
|
|
53
|
+
self._settings = None
|
|
54
|
+
self._task = None
|
|
55
|
+
self._worker = None
|
|
56
|
+
self._thread = None
|
|
57
|
+
self.init_layout()
|
|
58
|
+
|
|
59
|
+
def images_dir_line_edit(self):
|
|
60
|
+
if not self._images_dir_line_edit:
|
|
61
|
+
self._images_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/images_dir'))
|
|
62
|
+
return self._images_dir_line_edit
|
|
63
|
+
|
|
64
|
+
def images_dir_select_button(self):
|
|
65
|
+
if not self._images_dir_select_button:
|
|
66
|
+
self._images_dir_select_button = QPushButton('Select')
|
|
67
|
+
self._images_dir_select_button.clicked.connect(self.handle_images_dir_select_button)
|
|
68
|
+
return self._images_dir_select_button
|
|
69
|
+
|
|
70
|
+
def segmentations_dir_line_edit(self):
|
|
71
|
+
if not self._segmentations_dir_line_edit:
|
|
72
|
+
self._segmentations_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/segmentations_dir'))
|
|
73
|
+
return self._segmentations_dir_line_edit
|
|
74
|
+
|
|
75
|
+
def segmentations_dir_select_button(self):
|
|
76
|
+
if not self._segmentations_dir_select_button:
|
|
77
|
+
self._segmentations_dir_select_button = QPushButton('Select')
|
|
78
|
+
self._segmentations_dir_select_button.clicked.connect(self.handle_segmentations_dir_select_button)
|
|
79
|
+
return self._segmentations_dir_select_button
|
|
80
|
+
|
|
81
|
+
def output_dir_line_edit(self):
|
|
82
|
+
if not self._output_dir_line_edit:
|
|
83
|
+
self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
|
|
84
|
+
return self._output_dir_line_edit
|
|
85
|
+
|
|
86
|
+
def output_dir_select_button(self):
|
|
87
|
+
if not self._output_dir_select_button:
|
|
88
|
+
self._output_dir_select_button = QPushButton('Select')
|
|
89
|
+
self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
|
|
90
|
+
return self._output_dir_select_button
|
|
91
|
+
|
|
92
|
+
def threshold_low_spinbox(self):
|
|
93
|
+
if not self._threshold_low_spinbox:
|
|
94
|
+
self._threshold_low_spinbox = QDoubleSpinBox(minimum=-200, maximum=150, value=5)
|
|
95
|
+
self._threshold_low_spinbox.setValue(self.settings().get_int(f'{PANEL_NAME}/threshold_low', 5))
|
|
96
|
+
return self._threshold_low_spinbox
|
|
97
|
+
|
|
98
|
+
def threshold_high_spinbox(self):
|
|
99
|
+
if not self._threshold_high_spinbox:
|
|
100
|
+
self._threshold_high_spinbox = QDoubleSpinBox(minimum=-200, maximum=150, value=150)
|
|
101
|
+
self._threshold_high_spinbox.setValue(self.settings().get_int(f'{PANEL_NAME}/threshold_high', 150))
|
|
102
|
+
return self._threshold_high_spinbox
|
|
103
|
+
|
|
104
|
+
def label_combobox(self):
|
|
105
|
+
if not self._label_combobox:
|
|
106
|
+
self._label_combobox = QComboBox()
|
|
107
|
+
self._label_combobox.addItems(['1', '5', '7'])
|
|
108
|
+
self._label_combobox.setCurrentText(self.settings().get(f'{PANEL_NAME}/label', '1'))
|
|
109
|
+
return self._label_combobox
|
|
110
|
+
|
|
111
|
+
def overwrite_checkbox(self):
|
|
112
|
+
if not self._overwrite_checkbox:
|
|
113
|
+
self._overwrite_checkbox = QCheckBox('')
|
|
114
|
+
self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
|
|
115
|
+
return self._overwrite_checkbox
|
|
116
|
+
|
|
117
|
+
def form_layout(self):
|
|
118
|
+
if not self._form_layout:
|
|
119
|
+
self._form_layout = QFormLayout()
|
|
120
|
+
if is_macos():
|
|
121
|
+
self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
|
122
|
+
return self._form_layout
|
|
123
|
+
|
|
124
|
+
def run_task_button(self):
|
|
125
|
+
if not self._run_task_button:
|
|
126
|
+
self._run_task_button = QPushButton('Run task')
|
|
127
|
+
self._run_task_button.clicked.connect(self.handle_run_task_button)
|
|
128
|
+
return self._run_task_button
|
|
129
|
+
|
|
130
|
+
def open_excel_button(self):
|
|
131
|
+
if not self._open_excel_button:
|
|
132
|
+
self._open_excel_button = QPushButton('Open output in Excel')
|
|
133
|
+
self._open_excel_button.clicked.connect(self.handle_open_excel_button)
|
|
134
|
+
return self._open_excel_button
|
|
135
|
+
|
|
136
|
+
def settings(self):
|
|
137
|
+
if not self._settings:
|
|
138
|
+
self._settings = Settings()
|
|
139
|
+
return self._settings
|
|
140
|
+
|
|
141
|
+
def init_layout(self):
|
|
142
|
+
images_dir_layout = QHBoxLayout()
|
|
143
|
+
images_dir_layout.addWidget(self.images_dir_line_edit())
|
|
144
|
+
images_dir_layout.addWidget(self.images_dir_select_button())
|
|
145
|
+
segmentations_dir_layout = QHBoxLayout()
|
|
146
|
+
segmentations_dir_layout.addWidget(self.segmentations_dir_line_edit())
|
|
147
|
+
segmentations_dir_layout.addWidget(self.segmentations_dir_select_button())
|
|
148
|
+
output_dir_layout = QHBoxLayout()
|
|
149
|
+
output_dir_layout.addWidget(self.output_dir_line_edit())
|
|
150
|
+
output_dir_layout.addWidget(self.output_dir_select_button())
|
|
151
|
+
self.form_layout().addRow('Images directory', images_dir_layout)
|
|
152
|
+
self.form_layout().addRow('Segmentations directory', segmentations_dir_layout)
|
|
153
|
+
self.form_layout().addRow('Output directory', output_dir_layout)
|
|
154
|
+
self.form_layout().addRow('Threshold low', self.threshold_low_spinbox())
|
|
155
|
+
self.form_layout().addRow('Threshold high', self.threshold_high_spinbox())
|
|
156
|
+
self.form_layout().addRow('Label', self.label_combobox())
|
|
157
|
+
self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
|
|
158
|
+
layout = QVBoxLayout()
|
|
159
|
+
layout.addLayout(self.form_layout())
|
|
160
|
+
layout.addWidget(self.run_task_button())
|
|
161
|
+
layout.addWidget(self.open_excel_button())
|
|
162
|
+
self.setLayout(layout)
|
|
163
|
+
self.setObjectName(PANEL_NAME)
|
|
164
|
+
|
|
165
|
+
def handle_images_dir_select_button(self):
|
|
166
|
+
last_directory = self.settings().get('last_directory')
|
|
167
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
168
|
+
if directory:
|
|
169
|
+
self.images_dir_line_edit().setText(directory)
|
|
170
|
+
self.settings().set('last_directory', directory)
|
|
171
|
+
|
|
172
|
+
def handle_segmentations_dir_select_button(self):
|
|
173
|
+
last_directory = self.settings().get('last_directory')
|
|
174
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
175
|
+
if directory:
|
|
176
|
+
self.segmentations_dir_line_edit().setText(directory)
|
|
177
|
+
self.settings().set('last_directory', directory)
|
|
178
|
+
|
|
179
|
+
def handle_output_dir_select_button(self):
|
|
180
|
+
last_directory = self.settings().get('last_directory')
|
|
181
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
182
|
+
if directory:
|
|
183
|
+
self.output_dir_line_edit().setText(directory)
|
|
184
|
+
self.settings().set('last_directory', directory)
|
|
185
|
+
|
|
186
|
+
def handle_run_task_button(self):
|
|
187
|
+
errors = self.check_inputs_and_parameters()
|
|
188
|
+
if len(errors) > 0:
|
|
189
|
+
error_message = 'Following errors were encountered:\n'
|
|
190
|
+
for error in errors:
|
|
191
|
+
error_message += f' - {error}\n'
|
|
192
|
+
QMessageBox.information(self, 'Error', error_message)
|
|
193
|
+
else:
|
|
194
|
+
LOG.info('Running task...')
|
|
195
|
+
self.run_task_button().setEnabled(False)
|
|
196
|
+
self.save_inputs_and_parameters()
|
|
197
|
+
self._task = ApplyThresholdToSegmentationsTask(
|
|
198
|
+
inputs={
|
|
199
|
+
'images': self.images_dir_line_edit().text(),
|
|
200
|
+
'segmentations': self.segmentations_dir_line_edit().text(),
|
|
201
|
+
},
|
|
202
|
+
params={
|
|
203
|
+
'label': int(self.label_combobox().currentText()),
|
|
204
|
+
'threshold_low': self.threshold_low_spinbox().value(),
|
|
205
|
+
'threshold_high': self.threshold_high_spinbox().value(),
|
|
206
|
+
},
|
|
207
|
+
output=self.output_dir_line_edit().text(),
|
|
208
|
+
overwrite=self.overwrite_checkbox().isChecked(),
|
|
209
|
+
)
|
|
210
|
+
self._worker = Worker(self._task)
|
|
211
|
+
self._thread = QThread()
|
|
212
|
+
self._worker.moveToThread(self._thread)
|
|
213
|
+
self._thread.started.connect(self._worker.run)
|
|
214
|
+
self._worker.progress.connect(self.handle_progress)
|
|
215
|
+
self._worker.status.connect(self.handle_status)
|
|
216
|
+
self._worker.finished.connect(self.handle_finished)
|
|
217
|
+
self._worker.finished.connect(self._thread.quit)
|
|
218
|
+
self._worker.finished.connect(self._worker.deleteLater)
|
|
219
|
+
self._thread.finished.connect(self._thread.deleteLater)
|
|
220
|
+
self._thread.start()
|
|
221
|
+
|
|
222
|
+
def handle_open_excel_button(self):
|
|
223
|
+
file_path = os.path.join(self.output_dir_line_edit().text(), 'calculatescorestask', 'bc_scores.xlsx')
|
|
224
|
+
file_path = pathlib.Path(file_path).expanduser().resolve()
|
|
225
|
+
if not file_path.exists():
|
|
226
|
+
raise FileNotFoundError(file_path)
|
|
227
|
+
if sys.platform.startswith('win'):
|
|
228
|
+
os.startfile(str(file_path))
|
|
229
|
+
elif sys.platform == 'darwin':
|
|
230
|
+
subprocess.run(['open', str(file_path)], check=True)
|
|
231
|
+
else:
|
|
232
|
+
subprocess.run(["xdg-open", str(file_path)], check=True)
|
|
233
|
+
|
|
234
|
+
@Slot(int)
|
|
235
|
+
def handle_progress(self, progress):
|
|
236
|
+
LOG.info(f'Progress: {progress} / 100%')
|
|
237
|
+
|
|
238
|
+
@Slot(str)
|
|
239
|
+
def handle_status(self, status):
|
|
240
|
+
LOG.info(f'Status: {status}')
|
|
241
|
+
|
|
242
|
+
@Slot()
|
|
243
|
+
def handle_finished(self):
|
|
244
|
+
self.run_task_button().setEnabled(True)
|
|
245
|
+
|
|
246
|
+
# HELPERS
|
|
247
|
+
|
|
248
|
+
def check_inputs_and_parameters(self):
|
|
249
|
+
errors = []
|
|
250
|
+
if self.images_dir_line_edit().text() == '':
|
|
251
|
+
errors.append('Empty images directory path')
|
|
252
|
+
if not os.path.isdir(self.images_dir_line_edit().text()):
|
|
253
|
+
errors.append('Images directory does not exist')
|
|
254
|
+
if self.segmentations_dir_line_edit().text() == '':
|
|
255
|
+
errors.append('Empty segmentations directory path')
|
|
256
|
+
if not os.path.isdir(self.segmentations_dir_line_edit().text()):
|
|
257
|
+
errors.append('Segmentations directory does not exist')
|
|
258
|
+
if self.output_dir_line_edit().text() == '':
|
|
259
|
+
errors.append('Empty output directory path')
|
|
260
|
+
if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
|
|
261
|
+
errors.append('Output directory exists but overwrite=False. Please remove output directory first')
|
|
262
|
+
return errors
|
|
263
|
+
|
|
264
|
+
def save_inputs_and_parameters(self):
|
|
265
|
+
self.settings().set(f'{PANEL_NAME}/images_dir', self.images_dir_line_edit().text())
|
|
266
|
+
self.settings().set(f'{PANEL_NAME}/segmentations_dir', self.segmentations_dir_line_edit().text())
|
|
267
|
+
self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
|
|
268
|
+
self.settings().set(f'{PANEL_NAME}/label', self.label_combobox().currentText())
|
|
269
|
+
self.settings().set(f'{PANEL_NAME}/threshold_low', self.threshold_low_spinbox().value())
|
|
270
|
+
self.settings().set(f'{PANEL_NAME}/threshold_high', self.threshold_high_spinbox().value())
|
|
271
|
+
self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from PySide6.QtWidgets import (
|
|
4
|
+
QLineEdit,
|
|
5
|
+
QCheckBox,
|
|
6
|
+
QSpinBox,
|
|
7
|
+
QHBoxLayout,
|
|
8
|
+
QVBoxLayout,
|
|
9
|
+
QFormLayout,
|
|
10
|
+
QPushButton,
|
|
11
|
+
QFileDialog,
|
|
12
|
+
QMessageBox,
|
|
13
|
+
)
|
|
14
|
+
from PySide6.QtCore import (
|
|
15
|
+
QThread,
|
|
16
|
+
Slot,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from mosamatic2.core.managers.logmanager import LogManager
|
|
20
|
+
from mosamatic2.ui.widgets.panels.tasks.taskpanel import TaskPanel
|
|
21
|
+
from mosamatic2.ui.settings import Settings
|
|
22
|
+
from mosamatic2.ui.utils import is_macos
|
|
23
|
+
from mosamatic2.ui.worker import Worker
|
|
24
|
+
from mosamatic2.core.tasks import CalculateMaskStatisticsTask
|
|
25
|
+
|
|
26
|
+
LOG = LogManager()
|
|
27
|
+
|
|
28
|
+
PANEL_TITLE = 'CalculateMaskStatisticsTask'
|
|
29
|
+
PANEL_NAME = 'calculatemaskstatisticstaskpanel'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class CalculateMaskStatisticsTaskPanel(TaskPanel):
|
|
33
|
+
def __init__(self):
|
|
34
|
+
super(CalculateMaskStatisticsTaskPanel, self).__init__()
|
|
35
|
+
self.set_title(PANEL_TITLE)
|
|
36
|
+
self._scans_dir_line_edit = None
|
|
37
|
+
self._scans_dir_select_button = None
|
|
38
|
+
self._masks_dir_line_edit = None
|
|
39
|
+
self._masks_dir_select_button = None
|
|
40
|
+
self._output_dir_line_edit = None
|
|
41
|
+
self._output_dir_select_button = None
|
|
42
|
+
self._overwrite_checkbox = None
|
|
43
|
+
self._form_layout = None
|
|
44
|
+
self._run_task_button = None
|
|
45
|
+
self._settings = None
|
|
46
|
+
self._task = None
|
|
47
|
+
self._worker = None
|
|
48
|
+
self._thread = None
|
|
49
|
+
self.init_layout()
|
|
50
|
+
|
|
51
|
+
def scans_dir_line_edit(self):
|
|
52
|
+
if not self._scans_dir_line_edit:
|
|
53
|
+
self._scans_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/scans_dir'))
|
|
54
|
+
return self._scans_dir_line_edit
|
|
55
|
+
|
|
56
|
+
def scans_dir_select_button(self):
|
|
57
|
+
if not self._scans_dir_select_button:
|
|
58
|
+
self._scans_dir_select_button = QPushButton('Select')
|
|
59
|
+
self._scans_dir_select_button.clicked.connect(self.handle_scans_dir_select_button)
|
|
60
|
+
return self._scans_dir_select_button
|
|
61
|
+
|
|
62
|
+
def masks_dir_line_edit(self):
|
|
63
|
+
if not self._masks_dir_line_edit:
|
|
64
|
+
self._masks_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/masks_dir'))
|
|
65
|
+
return self._masks_dir_line_edit
|
|
66
|
+
|
|
67
|
+
def masks_dir_select_button(self):
|
|
68
|
+
if not self._masks_dir_select_button:
|
|
69
|
+
self._masks_dir_select_button = QPushButton('Select')
|
|
70
|
+
self._masks_dir_select_button.clicked.connect(self.handle_masks_dir_select_button)
|
|
71
|
+
return self._masks_dir_select_button
|
|
72
|
+
|
|
73
|
+
def output_dir_line_edit(self):
|
|
74
|
+
if not self._output_dir_line_edit:
|
|
75
|
+
self._output_dir_line_edit = QLineEdit(self.settings().get(f'{PANEL_NAME}/output_dir'))
|
|
76
|
+
return self._output_dir_line_edit
|
|
77
|
+
|
|
78
|
+
def output_dir_select_button(self):
|
|
79
|
+
if not self._output_dir_select_button:
|
|
80
|
+
self._output_dir_select_button = QPushButton('Select')
|
|
81
|
+
self._output_dir_select_button.clicked.connect(self.handle_output_dir_select_button)
|
|
82
|
+
return self._output_dir_select_button
|
|
83
|
+
|
|
84
|
+
def overwrite_checkbox(self):
|
|
85
|
+
if not self._overwrite_checkbox:
|
|
86
|
+
self._overwrite_checkbox = QCheckBox('')
|
|
87
|
+
self._overwrite_checkbox.setChecked(self.settings().get_bool(f'{PANEL_NAME}/overwrite', True))
|
|
88
|
+
return self._overwrite_checkbox
|
|
89
|
+
|
|
90
|
+
def form_layout(self):
|
|
91
|
+
if not self._form_layout:
|
|
92
|
+
self._form_layout = QFormLayout()
|
|
93
|
+
if is_macos():
|
|
94
|
+
self._form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
|
|
95
|
+
return self._form_layout
|
|
96
|
+
|
|
97
|
+
def run_task_button(self):
|
|
98
|
+
if not self._run_task_button:
|
|
99
|
+
self._run_task_button = QPushButton('Run task')
|
|
100
|
+
self._run_task_button.clicked.connect(self.handle_run_task_button)
|
|
101
|
+
return self._run_task_button
|
|
102
|
+
|
|
103
|
+
def settings(self):
|
|
104
|
+
if not self._settings:
|
|
105
|
+
self._settings = Settings()
|
|
106
|
+
return self._settings
|
|
107
|
+
|
|
108
|
+
def init_layout(self):
|
|
109
|
+
scans_dir_layout = QHBoxLayout()
|
|
110
|
+
scans_dir_layout.addWidget(self.scans_dir_line_edit())
|
|
111
|
+
scans_dir_layout.addWidget(self.scans_dir_select_button())
|
|
112
|
+
masks_dir_layout = QHBoxLayout()
|
|
113
|
+
masks_dir_layout.addWidget(self.masks_dir_line_edit())
|
|
114
|
+
masks_dir_layout.addWidget(self.masks_dir_select_button())
|
|
115
|
+
output_dir_layout = QHBoxLayout()
|
|
116
|
+
output_dir_layout.addWidget(self.output_dir_line_edit())
|
|
117
|
+
output_dir_layout.addWidget(self.output_dir_select_button())
|
|
118
|
+
self.form_layout().addRow('Scans directory', scans_dir_layout)
|
|
119
|
+
self.form_layout().addRow('Masks directory', masks_dir_layout)
|
|
120
|
+
self.form_layout().addRow('Output directory', output_dir_layout)
|
|
121
|
+
self.form_layout().addRow('Overwrite', self.overwrite_checkbox())
|
|
122
|
+
layout = QVBoxLayout()
|
|
123
|
+
layout.addLayout(self.form_layout())
|
|
124
|
+
layout.addWidget(self.run_task_button())
|
|
125
|
+
self.setLayout(layout)
|
|
126
|
+
self.setObjectName(PANEL_NAME)
|
|
127
|
+
|
|
128
|
+
def handle_scans_dir_select_button(self):
|
|
129
|
+
last_directory = self.settings().get('last_directory')
|
|
130
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
131
|
+
if directory:
|
|
132
|
+
self.scans_dir_line_edit().setText(directory)
|
|
133
|
+
self.settings().set('last_directory', directory)
|
|
134
|
+
|
|
135
|
+
def handle_masks_dir_select_button(self):
|
|
136
|
+
last_directory = self.settings().get('last_directory')
|
|
137
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
138
|
+
if directory:
|
|
139
|
+
self.masks_dir_line_edit().setText(directory)
|
|
140
|
+
self.settings().set('last_directory', directory)
|
|
141
|
+
|
|
142
|
+
def handle_output_dir_select_button(self):
|
|
143
|
+
last_directory = self.settings().get('last_directory')
|
|
144
|
+
directory = QFileDialog.getExistingDirectory(dir=last_directory)
|
|
145
|
+
if directory:
|
|
146
|
+
self.output_dir_line_edit().setText(directory)
|
|
147
|
+
self.settings().set('last_directory', directory)
|
|
148
|
+
|
|
149
|
+
def handle_run_task_button(self):
|
|
150
|
+
errors = self.check_inputs_and_parameters()
|
|
151
|
+
if len(errors) > 0:
|
|
152
|
+
error_message = 'Following errors were encountered:\n'
|
|
153
|
+
for error in errors:
|
|
154
|
+
error_message += f' - {error}\n'
|
|
155
|
+
QMessageBox.information(self, 'Error', error_message)
|
|
156
|
+
else:
|
|
157
|
+
LOG.info('Running task...')
|
|
158
|
+
self.run_task_button().setEnabled(False)
|
|
159
|
+
self.save_inputs_and_parameters()
|
|
160
|
+
self._task = CalculateMaskStatisticsTask(
|
|
161
|
+
inputs={
|
|
162
|
+
'scans': self.scans_dir_line_edit().text(),
|
|
163
|
+
'masks': self.masks_dir_line_edit().text(),
|
|
164
|
+
},
|
|
165
|
+
params=None,
|
|
166
|
+
output=self.output_dir_line_edit().text(),
|
|
167
|
+
overwrite=self.overwrite_checkbox().isChecked(),
|
|
168
|
+
)
|
|
169
|
+
self._worker = Worker(self._task)
|
|
170
|
+
self._thread = QThread()
|
|
171
|
+
self._worker.moveToThread(self._thread)
|
|
172
|
+
self._thread.started.connect(self._worker.run)
|
|
173
|
+
self._worker.progress.connect(self.handle_progress)
|
|
174
|
+
self._worker.status.connect(self.handle_status)
|
|
175
|
+
self._worker.finished.connect(self.handle_finished)
|
|
176
|
+
self._worker.finished.connect(self._thread.quit)
|
|
177
|
+
self._worker.finished.connect(self._worker.deleteLater)
|
|
178
|
+
self._thread.finished.connect(self._thread.deleteLater)
|
|
179
|
+
self._thread.start()
|
|
180
|
+
|
|
181
|
+
@Slot(int)
|
|
182
|
+
def handle_progress(self, progress):
|
|
183
|
+
LOG.info(f'Progress: {progress} / 100%')
|
|
184
|
+
|
|
185
|
+
@Slot(str)
|
|
186
|
+
def handle_status(self, status):
|
|
187
|
+
LOG.info(f'Status: {status}')
|
|
188
|
+
|
|
189
|
+
@Slot()
|
|
190
|
+
def handle_finished(self):
|
|
191
|
+
self.run_task_button().setEnabled(True)
|
|
192
|
+
|
|
193
|
+
# HELPERS
|
|
194
|
+
|
|
195
|
+
def check_inputs_and_parameters(self):
|
|
196
|
+
errors = []
|
|
197
|
+
if self.scans_dir_line_edit().text() == '':
|
|
198
|
+
errors.append('Empty scans directory path')
|
|
199
|
+
if not os.path.isdir(self.scans_dir_line_edit().text()):
|
|
200
|
+
errors.append('Scans directory does not exist')
|
|
201
|
+
if self.masks_dir_line_edit().text() == '':
|
|
202
|
+
errors.append('Empty masks directory path')
|
|
203
|
+
if not os.path.isdir(self.masks_dir_line_edit().text()):
|
|
204
|
+
errors.append('Masks directory does not exist')
|
|
205
|
+
if self.output_dir_line_edit().text() == '':
|
|
206
|
+
errors.append('Empty output directory path')
|
|
207
|
+
if os.path.isdir(self.output_dir_line_edit().text()) and not self.overwrite_checkbox().isChecked():
|
|
208
|
+
errors.append('Output directory exists but overwrite=False. Please remove output directory first')
|
|
209
|
+
return errors
|
|
210
|
+
|
|
211
|
+
def save_inputs_and_parameters(self):
|
|
212
|
+
self.settings().set(f'{PANEL_NAME}/scans_dir', self.scans_dir_line_edit().text())
|
|
213
|
+
self.settings().set(f'{PANEL_NAME}/masks_dir', self.masks_dir_line_edit().text())
|
|
214
|
+
self.settings().set(f'{PANEL_NAME}/output_dir', self.output_dir_line_edit().text())
|
|
215
|
+
self.settings().set(f'{PANEL_NAME}/overwrite', self.overwrite_checkbox().isChecked())
|