-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel_simulation_module_smlm.py
62 lines (47 loc) · 1.71 KB
/
model_simulation_module_smlm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Title : Model for module 1b
# Objective : Model setup of module 1b
# Written by: Saskia Kutz
from os import path, mkdir
from PyQt5 import QtCore as qtc
from pythonr.Python_to_R import PythonToR
class ModelSMLM(qtc.QObject):
"""Data check for R backbone"""
error = qtc.pyqtSignal(str)
finished = qtc.pyqtSignal()
def __init__(self):
super().__init__()
self.inputs = None
@qtc.pyqtSlot(object)
def set_data(self, inputs):
self.inputs = inputs
@qtc.pyqtSlot()
def print_income(self):
"""check for correct directory and connection to R"""
print("save_called")
error = ''
dir_ = self.inputs.get('directory')
if dir_ == "select directory":
error = f'You need to choose a directory'
elif not path.isdir(dir_.rsplit('/', 1)[0]):
error = f'You need to choose a valid directory'
elif not path.isdir(dir_):
try:
mkdir(dir_)
except Exception as e:
error = f'Directory creation failed'
else:
try:
dir_file = dir_ + '/' + 'sim_smlm_parameters.txt'
list_dir = [f'{key}={self.inputs[key]}' for key in self.inputs]
with open(dir_file, 'w') as fh:
[fh.write(f'{st}\n') for st in list_dir]
except Exception as e:
error = f'Cannot store parameters: {e}'
try:
simulation = PythonToR()
simulation.r_smlm_simulation(self.inputs)
except Exception as e:
error = f'Cannot do the simulations: {e}'
self.finished.emit()
if error:
self.error.emit(error)