spacr 1.0.6__py3-none-any.whl → 1.0.9__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.
spacr/gui_utils.py CHANGED
@@ -9,7 +9,7 @@ import psutil
9
9
  from PIL import Image, ImageTk
10
10
  from screeninfo import get_monitors
11
11
 
12
- from .gui_elements import AnnotateApp, spacrEntry, spacrCheck, spacrCombo
12
+ from .gui_elements import spacrEntry, spacrCheck, spacrCombo
13
13
 
14
14
  try:
15
15
  ctypes.windll.shcore.SetProcessDpiAwareness(True)
@@ -208,114 +208,6 @@ def cancel_after_tasks(frame):
208
208
  frame.after_cancel(task)
209
209
  frame.after_tasks.clear()
210
210
 
211
- def annotate(settings):
212
- from .settings import set_annotate_default_settings
213
- settings = set_annotate_default_settings(settings)
214
- src = settings['src']
215
-
216
- db = os.path.join(src, 'measurements/measurements.db')
217
- conn = sqlite3.connect(db)
218
- c = conn.cursor()
219
- c.execute('PRAGMA table_info(png_list)')
220
- cols = c.fetchall()
221
- if settings['annotation_column'] not in [col[1] for col in cols]:
222
- c.execute(f"ALTER TABLE png_list ADD COLUMN {settings['annotation_column']} integer")
223
- conn.commit()
224
- conn.close()
225
-
226
- root = tk.Tk()
227
-
228
- root.geometry(f"{root.winfo_screenwidth()}x{root.winfo_screenheight()}")
229
-
230
- db_path = os.path.join(settings['src'], 'measurements/measurements.db')
231
-
232
- app = AnnotateApp(root,
233
- db_path=db_path,
234
- src=settings['src'],
235
- image_type=settings['image_type'],
236
- channels=settings['channels'],
237
- image_size=settings['img_size'],
238
- annotation_column=settings['annotation_column'],
239
- normalize=settings['normalize'],
240
- percentiles=settings['percentiles'],
241
- measurement=settings['measurement'],
242
- threshold=settings['threshold'],
243
- normalize_channels=settings['normalize_channels'])
244
-
245
- app.load_images()
246
- root.mainloop()
247
-
248
- def generate_annotate_fields(frame):
249
- from .settings import set_annotate_default_settings
250
- from .gui_elements import set_dark_style
251
-
252
- style_out = set_dark_style(ttk.Style())
253
- font_loader = style_out['font_loader']
254
- font_size = style_out['font_size'] - 2
255
-
256
- vars_dict = {}
257
- settings = set_annotate_default_settings(settings={})
258
-
259
- for setting in settings:
260
- vars_dict[setting] = {
261
- 'entry': ttk.Entry(frame),
262
- 'value': settings[setting]
263
- }
264
-
265
- # Arrange input fields and labels
266
- for row, (name, data) in enumerate(vars_dict.items()):
267
- tk.Label(
268
- frame,
269
- text=f"{name.replace('_', ' ').capitalize()}:",
270
- bg=style_out['bg_color'],
271
- fg=style_out['fg_color'],
272
- font=font_loader.get_font(size=font_size)
273
- ).grid(row=row, column=0)
274
-
275
- value = data['value']
276
- if isinstance(value, list):
277
- string_value = ','.join(map(str, value))
278
- elif isinstance(value, (int, float, bool)):
279
- string_value = str(value)
280
- elif value is None:
281
- string_value = ''
282
- else:
283
- string_value = value
284
-
285
- data['entry'].insert(0, string_value)
286
- data['entry'].grid(row=row, column=1)
287
-
288
- return vars_dict
289
-
290
- def run_annotate_app(vars_dict, parent_frame):
291
- settings = {key: data['entry'].get() for key, data in vars_dict.items()}
292
- settings['channels'] = settings['channels'].split(',')
293
- settings['img_size'] = list(map(int, settings['img_size'].split(','))) # Convert string to list of integers
294
- settings['percentiles'] = list(map(int, settings['percentiles'].split(','))) # Convert string to list of integers
295
- settings['normalize'] = settings['normalize'].lower() == 'true'
296
- settings['normalize_channels'] = settings['channels'].split(',')
297
- settings['rows'] = int(settings['rows'])
298
- settings['columns'] = int(settings['columns'])
299
- settings['measurement'] = settings['measurement'].split(',')
300
- settings['threshold'] = None if settings['threshold'].lower() == 'none' else int(settings['threshold'])
301
-
302
- # Clear previous content instead of destroying the root
303
- if hasattr(parent_frame, 'winfo_children'):
304
- for widget in parent_frame.winfo_children():
305
- widget.destroy()
306
-
307
- # Start the annotate application in the same root window
308
- annotate_app(parent_frame, settings)
309
-
310
- # Global list to keep references to PhotoImage objects
311
- global_image_refs = []
312
-
313
- def annotate_app(parent_frame, settings):
314
- global global_image_refs
315
- global_image_refs.clear()
316
- root = parent_frame.winfo_toplevel()
317
- annotate_with_image_refs(settings, root, lambda: load_next_app(root))
318
-
319
211
  def load_next_app(root):
320
212
  # Get the next app function and arguments
321
213
  next_app_func = root.next_app_func
@@ -335,37 +227,6 @@ def load_next_app(root):
335
227
  new_root.title("SpaCr Application")
336
228
  next_app_func(new_root, *next_app_args)
337
229
 
338
- def annotate_with_image_refs(settings, root, shutdown_callback):
339
- from .settings import set_annotate_default_settings
340
-
341
- settings = set_annotate_default_settings(settings)
342
- src = settings['src']
343
-
344
- db = os.path.join(src, 'measurements/measurements.db')
345
- conn = sqlite3.connect(db)
346
- c = conn.cursor()
347
- c.execute('PRAGMA table_info(png_list)')
348
- cols = c.fetchall()
349
- if settings['annotation_column'] not in [col[1] for col in cols]:
350
- c.execute(f"ALTER TABLE png_list ADD COLUMN {settings['annotation_column']} integer")
351
- conn.commit()
352
- conn.close()
353
-
354
- screen_width = root.winfo_screenwidth()
355
- screen_height = root.winfo_screenheight()
356
- root.geometry(f"{screen_width}x{screen_height}")
357
-
358
- app = AnnotateApp(root, db, src, image_type=settings['image_type'], channels=settings['channels'], image_size=settings['img_size'], annotation_column=settings['annotation_column'], normalize=settings['normalize'], percentiles=settings['percentiles'], measurement=settings['measurement'], threshold=settings['threshold'], normalize_channels=settings['normalize_channels'], outline=settings['outline'], outline_threshold_factor=settings['outline_threshold_factor'], outline_sigma=settings['outline_sigma'])
359
-
360
- # Set the canvas background to black
361
- root.configure(bg='black')
362
-
363
- # Store the shutdown function and next app details in the root
364
- root.current_app_exit_func = lambda: [app.shutdown(), shutdown_callback()]
365
-
366
- # Call load_images after setting up the root window
367
- app.load_images()
368
-
369
230
  def convert_settings_dict_for_gui(settings):
370
231
  from torchvision import models as torch_models
371
232
  torchvision_models = [name for name, obj in torch_models.__dict__.items() if callable(obj)]
@@ -462,15 +323,14 @@ def function_gui_wrapper(function=None, settings={}, q=None, fig_queue=None, imp
462
323
 
463
324
  def run_function_gui(settings_type, settings, q, fig_queue, stop_requested):
464
325
 
465
- from .core import generate_image_umap, preprocess_generate_masks
466
- from .spacr_cellpose import identify_masks_finetune, check_cellpose_models, compare_cellpose_masks
326
+ from .core import preprocess_generate_masks
327
+ from .spacr_cellpose import identify_masks_finetune, check_cellpose_models
467
328
  from .submodules import analyze_recruitment
468
329
  from .ml import generate_ml_scores, perform_regression
469
330
  from .submodules import train_cellpose, analyze_plaques
470
- from .io import process_non_tif_non_2D_images, generate_cellpose_train_test, generate_dataset
331
+ from .io import process_non_tif_non_2D_images
471
332
  from .measure import measure_crop
472
- from .sim import run_multiple_simulations
473
- from .deep_spacr import deep_spacr, apply_model_to_tar
333
+ from .deep_spacr import deep_spacr
474
334
  from .sequencing import generate_barecode_mapping
475
335
 
476
336
  process_stdout_stderr(q)
@@ -483,9 +343,6 @@ def run_function_gui(settings_type, settings, q, fig_queue, stop_requested):
483
343
  elif settings_type == 'measure':
484
344
  function = measure_crop
485
345
  imports = 1
486
- elif settings_type == 'simulation':
487
- function = run_multiple_simulations
488
- imports = 1
489
346
  elif settings_type == 'classify':
490
347
  function = deep_spacr
491
348
  imports = 1
@@ -510,9 +367,6 @@ def run_function_gui(settings_type, settings, q, fig_queue, stop_requested):
510
367
  elif settings_type == 'recruitment':
511
368
  function = analyze_recruitment
512
369
  imports = 1
513
- elif settings_type == 'umap':
514
- function = generate_image_umap
515
- imports = 1
516
370
  elif settings_type == 'analyze_plaques':
517
371
  function = analyze_plaques
518
372
  imports = 1