small-fish-gui 1.3.5__py3-none-any.whl → 1.4.0__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.
@@ -1,312 +0,0 @@
1
- import os
2
- import numpy as np
3
- import PySimpleGUI as sg
4
- import bigfish.stack as stack
5
- import czifile as czi
6
-
7
- from .layout import _segmentation_layout, _detection_layout, _input_parameters_layout, _ask_channel_map_layout
8
-
9
-
10
- from time import sleep
11
-
12
- def get_images(filename:str) :
13
- """returns filename if is image else return None"""
14
-
15
- supported_types = ('.tiff', '.tif', '.png', '.czi')
16
- if filename.endswith(supported_types) :
17
- return [filename]
18
- else :
19
- return None
20
-
21
-
22
- def get_files(path) :
23
-
24
- filelist = os.listdir(path)
25
- filelist = list(map(get_images,filelist))
26
-
27
- while None in filelist : filelist.remove(None)
28
-
29
- return filelist
30
-
31
- def extract_files(filenames: list) :
32
- return sum(filenames,[])
33
-
34
- def check_file(filename:str) :
35
-
36
- if filename.endswith('.czi') :
37
- image = czi.imread(filename)
38
- else :
39
- image = stack.read_image(filename)
40
-
41
- image = np.squeeze(image)
42
-
43
- return image.shape
44
-
45
- def sanity_check(
46
- filename_list: list,
47
- batch_folder : str,
48
- window : sg.Window,
49
- progress_bar: sg.ProgressBar,
50
- ) :
51
-
52
- filenumber = len(filename_list)
53
- if filenumber == 0 :
54
- print("No file to check")
55
- progress_bar.update(current_count= 0, bar_color=('gray','gray'))
56
- return None
57
- else :
58
- print("{0} files to check".format(filenumber))
59
- progress_bar.update(current_count=0, max= filenumber)
60
- ref_shape = check_file(batch_folder + '/' + filename_list[0])
61
-
62
- print("Starting sanity check. This could take some time...")
63
- for i, file in enumerate(filename_list) :
64
- progress_bar.update(current_count= i+1, bar_color=('green','gray'))
65
- shape = check_file(batch_folder + '/' + file)
66
-
67
- if len(shape) != len(ref_shape) : #then dimension missmatch
68
- print("Different number of dimensions found : {0}, {1}".format(len(ref_shape), len(shape)))
69
- progress_bar.update(current_count=filenumber, bar_color=('red','black'))
70
- window= window.refresh()
71
- break
72
-
73
- window= window.refresh()
74
-
75
- print("Sanity check completed.")
76
- return None if len(shape) != len(ref_shape) else shape
77
-
78
-
79
- def get_elmt_from_key(Tab_elmt:sg.Tab, key) -> sg.Element:
80
- elmt_list = sum(Tab_elmt.Rows,[])
81
- for elmt in elmt_list :
82
- if elmt.Key == key : return elmt
83
- raise KeyError("{0} key not found amongst {1}.".format(key, [elmt.Key for elmt in elmt_list]))
84
-
85
- def update_detection_tab(
86
- tab_elmt:sg.Tab,
87
- is_multichannel,
88
- is_3D,
89
- do_dense_region_deconvolution,
90
- do_clustering
91
- ) :
92
-
93
- #Acess elements
94
- ##Detection
95
- channel_to_compute = get_elmt_from_key(tab_elmt, key= 'channel to compute')
96
- voxel_size_z = get_elmt_from_key(tab_elmt, key= 'voxel_size_z')
97
- spot_size_z = get_elmt_from_key(tab_elmt, key= 'spot_size_z')
98
- log_kernel_size_z = get_elmt_from_key(tab_elmt, key= 'log_kernel_size_z')
99
- minimum_distance_z = get_elmt_from_key(tab_elmt, key= 'minimum_distance_z')
100
-
101
- ##Dense regions deconvolution
102
- alpha = get_elmt_from_key(tab_elmt, key= 'alpha')
103
- beta = get_elmt_from_key(tab_elmt, key= 'beta')
104
- gamma = get_elmt_from_key(tab_elmt, key= 'gamma')
105
- deconvolution_kernel_z = get_elmt_from_key(tab_elmt, key= 'deconvolution_kernel_z')
106
- cluster_size = get_elmt_from_key(tab_elmt, key= 'cluster size')
107
- min_number_of_spot = get_elmt_from_key(tab_elmt, key= 'min number of spots')
108
- nucleus_channel_signal = get_elmt_from_key(tab_elmt, key= 'nucleus channel signal')
109
- interactive_threshold_selector = get_elmt_from_key(tab_elmt, key= 'Interactive threshold selector')
110
-
111
- update_dict={
112
- 'is_3D' : is_3D,
113
- 'is_multichannel' : is_multichannel,
114
- 'do_dense_region_deconvolution' : do_dense_region_deconvolution,
115
- 'do_clustering' : do_clustering,
116
- 'always_hidden' : False
117
- }
118
-
119
- list_dict={
120
- 'is_3D' : [voxel_size_z, spot_size_z, log_kernel_size_z, minimum_distance_z, deconvolution_kernel_z],
121
- 'is_multichannel' : [channel_to_compute, nucleus_channel_signal],
122
- 'do_dense_region_deconvolution' : [alpha,beta,gamma],
123
- 'do_clustering' : [cluster_size, min_number_of_spot],
124
- 'always_hidden' : [interactive_threshold_selector]
125
-
126
- }
127
-
128
- for key, enabled in update_dict.items() :
129
- for elmt in list_dict.get(key) :
130
- elmt.update(disabled=not enabled)
131
-
132
-
133
-
134
- def update_segmentation_tab(tab_elmt : sg.Tab, do_segmentation, is_multichannel) : #TODO
135
-
136
- #Access elements
137
- cytoplasm_channel_elmt = get_elmt_from_key(tab_elmt, key= 'cytoplasm channel')
138
- nucleus_channel_elmt = get_elmt_from_key(tab_elmt, key= 'nucleus channel')
139
-
140
- #Update values
141
- tab_elmt.update(visible=do_segmentation)
142
- cytoplasm_channel_elmt.update(disabled = not is_multichannel)
143
- nucleus_channel_elmt.update(disabled = not is_multichannel)
144
-
145
- def update_map_tab() :
146
- #TODO
147
- pass
148
-
149
- def batch_promp() :
150
-
151
- files_values = [[]]
152
-
153
-
154
- #LOAD FILES
155
- files_table = sg.Table(values=files_values, headings=['Filenames'], col_widths=100, max_col_width= 200, def_col_width=100, num_rows= 10, auto_size_columns=False)
156
-
157
- #Start&Stop
158
- start_button =sg.Button('Start', button_color= 'green', disabled= True)
159
- stop_button = sg.Button('Cancel', button_color= 'red')
160
-
161
- #DIMENSION SANITY
162
- sanity_progress = sg.ProgressBar(10, size_px=(500,10))
163
- sanity_check_button = sg.Button(
164
- 'Check',
165
- tooltip= "Will check that all files loaded have the same dimension number and that small fish is able to open them.",
166
- pad=(10,0))
167
- sanity_header = sg.Text("Dimension sanity", font=('bold',15), pad=(0,10))
168
- dimension_number_text = sg.Text("Dimension number : unknown")
169
-
170
- #Input tab
171
- input_layout = _input_parameters_layout(
172
- ask_for_segmentation=True,
173
- is_3D_stack_preset=False,
174
- time_stack_preset=False,
175
- multichannel_preset=False,
176
- do_dense_regions_deconvolution_preset=False,
177
- do_clustering_preset=False,
178
- do_Napari_correction=False,
179
- do_segmentation_preset=False,
180
- )
181
- input_layout += [[sg.Button('Ok')]]
182
- input_tab = sg.Tab("Input", input_layout)
183
-
184
- #Maptab
185
- map_layout = _ask_channel_map_layout(
186
- shape=(0,1,2,3,4),
187
- is_3D_stack=True,
188
- is_time_stack=True,
189
- multichannel=True,
190
- )
191
- last_shape_read = sg.Text("Last shape read : None")
192
- auto_map = sg.Button("auto-map", disabled=True, pad=(10,0))
193
- map_layout += [[last_shape_read, auto_map]]
194
- map_tab = sg.Tab("Map", map_layout)
195
-
196
- #Segmentation tab
197
- segmentation_layout = _segmentation_layout(multichannel=True, cytoplasm_model_preset='cyto3')
198
- segmentation_tab = sg.Tab("Segmentation", segmentation_layout, visible=False)
199
-
200
- #Detection tab
201
- detection_layout = _detection_layout(
202
- is_3D_stack=True,
203
- is_multichannel=True,
204
- do_clustering=True,
205
- do_dense_region_deconvolution=True,
206
- do_segmentation=True,
207
- )
208
-
209
-
210
- detection_tab = sg.Tab("Detection", detection_layout)
211
-
212
-
213
-
214
- #TABS
215
- _tab_group = sg.TabGroup([[input_tab, map_tab, segmentation_tab, detection_tab]], enable_events=True)
216
- tab_group = sg.Column( #Allow the tab to be scrollable
217
- [[_tab_group]],
218
- scrollable=True,
219
- vertical_scroll_only=True,
220
- pad=(150,5)
221
- )
222
- tab_dict= {
223
- "Input" : input_tab,
224
- "Segmentation" : segmentation_tab,
225
- "Detection" : detection_tab,
226
- "Map" : map_tab,
227
- }
228
-
229
- layout = [
230
- [sg.Text("Batch Processing", font=('bold',20), pad=((300,0),(0,2)))],
231
- [sg.Text("Select a folder : "), sg.FolderBrowse(initial_folder=os.getcwd(), key='Batch_folder'), sg.Button('Load')],
232
- [files_table],
233
- [sanity_header, sanity_check_button, sanity_progress],
234
- [dimension_number_text],
235
- [tab_group],
236
- [sg.Output(size=(100,10), pad=(30,10))],
237
- [start_button, stop_button],
238
- ]
239
-
240
- window = sg.Window("small fish", layout=layout, size= (800,800), auto_size_buttons=True, auto_size_text=True)
241
- loop = 0
242
- timeout = 1
243
- while True :
244
- loop +=1
245
- window = window.refresh()
246
- event, values = window.read(timeout=timeout)
247
-
248
- #Welcome message
249
- if loop == 1 :
250
- timeout = None
251
- print("Welcome to small fish batch analysis. Please start by loading some files and setting parameters.")
252
-
253
- batch_folder = values.get('Batch_folder')
254
- is_multichanel = values.get('multichannel')
255
- is_3D = values.get('3D stack')
256
- do_segmentation = values.get('Segmentation')
257
- do_dense_regions_deconvolution = values.get('Dense regions deconvolution')
258
- do_clustering = values.get('Cluster computation')
259
-
260
- if type(batch_folder) != type(None) and event == 'Load':
261
- if not os.path.isdir(batch_folder) :
262
- print("Can't open {0}".format(batch_folder))
263
- else :
264
- files_values = get_files(batch_folder)
265
- files_table.update(values=files_values)
266
-
267
- elif event == 'Check' :
268
- filename_list = extract_files(files_values)
269
- last_shape = sanity_check(
270
- filename_list=filename_list,
271
- batch_folder=batch_folder,
272
- window=window,
273
- progress_bar=sanity_progress
274
- )
275
- if isinstance(last_shape,(tuple,list)) :
276
- dim_number = len(last_shape)
277
- dimension_number_text.update("Dimension number : {0}".format(dim_number))
278
- auto_map.update(disabled=False)
279
- else :
280
- dimension_number_text.update("Dimension number : unknown")
281
- auto_map.update(disabled=True)
282
-
283
- last_shape_read.update("Last shape read : {0}".format(last_shape))
284
-
285
-
286
- elif event == _tab_group.key or event == 'Ok': #Tab switch in parameters
287
- update_segmentation_tab(
288
- tab_elmt=tab_dict.get("Segmentation"),
289
- do_segmentation=do_segmentation,
290
- is_multichannel=is_multichanel,
291
- )
292
-
293
- update_detection_tab(
294
- tab_elmt=tab_dict.get("Detection"),
295
- is_multichannel=is_multichanel,
296
- is_3D=is_3D,
297
- do_dense_region_deconvolution=do_dense_regions_deconvolution,
298
- do_clustering=do_clustering,
299
- )
300
-
301
- elif event == 'auto-map' :
302
- #TODO
303
- pass
304
-
305
- # elif event == 'apply' (map) #TODO
306
-
307
- # elif event == 'check parameters' -> un/lock start #TODO
308
-
309
- elif event == "Cancel" :
310
- print(values)
311
- elif event == None :
312
- quit()
@@ -1,5 +0,0 @@
1
- import PySimpleGUI as sg
2
- import small_fish_gui.gui.batch as prompt
3
-
4
- prompt.batch_promp()
5
- print('end')