spacr 0.4.15__py3-none-any.whl → 0.5.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.
Files changed (54) hide show
  1. spacr/__init__.py +2 -2
  2. spacr/core.py +52 -10
  3. spacr/deep_spacr.py +2 -3
  4. spacr/gui.py +0 -1
  5. spacr/gui_core.py +247 -41
  6. spacr/gui_elements.py +133 -2
  7. spacr/gui_utils.py +22 -17
  8. spacr/io.py +624 -149
  9. spacr/ml.py +141 -258
  10. spacr/plot.py +76 -34
  11. spacr/resources/MEDIAR/__pycache__/SetupDict.cpython-39.pyc +0 -0
  12. spacr/resources/MEDIAR/__pycache__/evaluate.cpython-39.pyc +0 -0
  13. spacr/resources/MEDIAR/__pycache__/generate_mapping.cpython-39.pyc +0 -0
  14. spacr/resources/MEDIAR/__pycache__/main.cpython-39.pyc +0 -0
  15. spacr/resources/MEDIAR/core/Baseline/__pycache__/Predictor.cpython-39.pyc +0 -0
  16. spacr/resources/MEDIAR/core/Baseline/__pycache__/Trainer.cpython-39.pyc +0 -0
  17. spacr/resources/MEDIAR/core/Baseline/__pycache__/__init__.cpython-39.pyc +0 -0
  18. spacr/resources/MEDIAR/core/Baseline/__pycache__/utils.cpython-39.pyc +0 -0
  19. spacr/resources/MEDIAR/core/MEDIAR/__pycache__/EnsemblePredictor.cpython-39.pyc +0 -0
  20. spacr/resources/MEDIAR/core/MEDIAR/__pycache__/Predictor.cpython-39.pyc +0 -0
  21. spacr/resources/MEDIAR/core/MEDIAR/__pycache__/Trainer.cpython-39.pyc +0 -0
  22. spacr/resources/MEDIAR/core/MEDIAR/__pycache__/__init__.cpython-39.pyc +0 -0
  23. spacr/resources/MEDIAR/core/MEDIAR/__pycache__/utils.cpython-39.pyc +0 -0
  24. spacr/resources/MEDIAR/core/__pycache__/BasePredictor.cpython-39.pyc +0 -0
  25. spacr/resources/MEDIAR/core/__pycache__/BaseTrainer.cpython-39.pyc +0 -0
  26. spacr/resources/MEDIAR/core/__pycache__/__init__.cpython-39.pyc +0 -0
  27. spacr/resources/MEDIAR/core/__pycache__/utils.cpython-39.pyc +0 -0
  28. spacr/resources/MEDIAR/train_tools/__pycache__/__init__.cpython-39.pyc +0 -0
  29. spacr/resources/MEDIAR/train_tools/__pycache__/measures.cpython-39.pyc +0 -0
  30. spacr/resources/MEDIAR/train_tools/__pycache__/utils.cpython-39.pyc +0 -0
  31. spacr/resources/MEDIAR/train_tools/data_utils/__pycache__/__init__.cpython-39.pyc +0 -0
  32. spacr/resources/MEDIAR/train_tools/data_utils/__pycache__/datasetter.cpython-39.pyc +0 -0
  33. spacr/resources/MEDIAR/train_tools/data_utils/__pycache__/transforms.cpython-39.pyc +0 -0
  34. spacr/resources/MEDIAR/train_tools/data_utils/__pycache__/utils.cpython-39.pyc +0 -0
  35. spacr/resources/MEDIAR/train_tools/data_utils/custom/__pycache__/CellAware.cpython-39.pyc +0 -0
  36. spacr/resources/MEDIAR/train_tools/data_utils/custom/__pycache__/LoadImage.cpython-39.pyc +0 -0
  37. spacr/resources/MEDIAR/train_tools/data_utils/custom/__pycache__/NormalizeImage.cpython-39.pyc +0 -0
  38. spacr/resources/MEDIAR/train_tools/data_utils/custom/__pycache__/__init__.cpython-39.pyc +0 -0
  39. spacr/resources/MEDIAR/train_tools/models/__pycache__/MEDIARFormer.cpython-39.pyc +0 -0
  40. spacr/resources/MEDIAR/train_tools/models/__pycache__/__init__.cpython-39.pyc +0 -0
  41. spacr/sequencing.py +73 -38
  42. spacr/settings.py +161 -135
  43. spacr/submodules.py +618 -215
  44. spacr/timelapse.py +197 -29
  45. spacr/toxo.py +23 -23
  46. spacr/utils.py +186 -128
  47. {spacr-0.4.15.dist-info → spacr-0.5.0.dist-info}/METADATA +5 -2
  48. {spacr-0.4.15.dist-info → spacr-0.5.0.dist-info}/RECORD +53 -24
  49. spacr/stats.py +0 -221
  50. /spacr/{cellpose.py → spacr_cellpose.py} +0 -0
  51. {spacr-0.4.15.dist-info → spacr-0.5.0.dist-info}/LICENSE +0 -0
  52. {spacr-0.4.15.dist-info → spacr-0.5.0.dist-info}/WHEEL +0 -0
  53. {spacr-0.4.15.dist-info → spacr-0.5.0.dist-info}/entry_points.txt +0 -0
  54. {spacr-0.4.15.dist-info → spacr-0.5.0.dist-info}/top_level.txt +0 -0
spacr/settings.py CHANGED
@@ -26,12 +26,14 @@ def set_default_plot_merge_settings():
26
26
 
27
27
  def set_default_settings_preprocess_generate_masks(settings={}):
28
28
 
29
+ settings.setdefault('denoise', False)
29
30
  settings.setdefault('src', 'path')
30
31
  settings.setdefault('delete_intermediate', False)
31
32
  settings.setdefault('segmentation_mode', 'cellpose')
32
33
  settings.setdefault('preprocess', True)
33
34
  settings.setdefault('masks', True)
34
35
  settings.setdefault('save', True)
36
+ settings.setdefault('consolidate', False)
35
37
  settings.setdefault('batch_size', 50)
36
38
  settings.setdefault('test_mode', False)
37
39
  settings.setdefault('test_images', 10)
@@ -86,21 +88,19 @@ def set_default_settings_preprocess_generate_masks(settings={}):
86
88
  settings.setdefault('fps', 2)
87
89
  settings.setdefault('timelapse_displacement', None)
88
90
  settings.setdefault('timelapse_memory', 3)
89
- settings.setdefault('timelapse_frame_limits', [5,60])
91
+ settings.setdefault('timelapse_frame_limits', [5,])
90
92
  settings.setdefault('timelapse_remove_transient', False)
91
93
  settings.setdefault('timelapse_mode', 'trackpy')
92
94
  settings.setdefault('timelapse_objects', None)
93
95
 
94
96
  # Misc settings
95
97
  settings.setdefault('all_to_mip', False)
96
- settings.setdefault('pick_slice', False)
97
- settings.setdefault('skip_mode', '01')
98
98
  settings.setdefault('upscale', False)
99
99
  settings.setdefault('upscale_factor', 2.0)
100
100
  settings.setdefault('adjust_cells', False)
101
101
  return settings
102
102
 
103
- def set_default_settings_preprocess_img_data(settings):
103
+ def set_default_settings_preprocess_img_data_v1(settings):
104
104
 
105
105
  metadata_type = settings.setdefault('metadata_type', 'cellvoyager')
106
106
  custom_regex = settings.setdefault('custom_regex', None)
@@ -125,6 +125,27 @@ def set_default_settings_preprocess_img_data(settings):
125
125
 
126
126
  return settings, metadata_type, custom_regex, nr, plot, batch_size, timelapse, lower_percentile, randomize, all_to_mip, pick_slice, skip_mode, cmap, figuresize, normalize, save_dtype, test_mode, test_images, random_test
127
127
 
128
+ def set_default_settings_preprocess_img_data(settings):
129
+
130
+ settings.setdefault('metadata_type', 'cellvoyager')
131
+ settings.setdefault('custom_regex', None)
132
+ settings.setdefault('nr', 1)
133
+ settings.setdefault('plot', True)
134
+ settings.setdefault('batch_size', 50)
135
+ settings.setdefault('timelapse', False)
136
+ settings.setdefault('lower_percentile', 2)
137
+ settings.setdefault('randomize', True)
138
+ settings.setdefault('all_to_mip', False)
139
+ settings.setdefault('cmap', 'inferno')
140
+ settings.setdefault('figuresize', 10)
141
+ settings.setdefault('normalize', True)
142
+ settings.setdefault('save_dtype', 'uint16')
143
+ settings.setdefault('test_mode', False)
144
+ settings.setdefault('test_images', 10)
145
+ settings.setdefault('random_test', True)
146
+ settings.setdefault('fps', 2)
147
+ return settings
148
+
128
149
  def _get_object_settings(object_type, settings):
129
150
 
130
151
  from .utils import _get_diam
@@ -219,7 +240,7 @@ def set_default_umap_image_settings(settings={}):
219
240
  settings.setdefault('smooth_lines', True)
220
241
  settings.setdefault('clustering', 'dbscan')
221
242
  settings.setdefault('exclude', None)
222
- settings.setdefault('col_to_compare', 'column_name')
243
+ settings.setdefault('col_to_compare', 'columnID')
223
244
  settings.setdefault('pos', 'c1')
224
245
  settings.setdefault('neg', 'c2')
225
246
  settings.setdefault('mix', 'c3')
@@ -276,77 +297,7 @@ def get_measure_crop_settings(settings={}):
276
297
 
277
298
  # Timelapsed settings
278
299
  settings.setdefault('timelapse', False)
279
- settings.setdefault('timelapse_objects', 'cell')
280
-
281
- # Operational settings
282
- settings.setdefault('plot',False)
283
- settings.setdefault('n_jobs', os.cpu_count()-2)
284
-
285
- # Object settings
286
- settings.setdefault('cell_mask_dim',4)
287
- settings.setdefault('nucleus_mask_dim',5)
288
- settings.setdefault('pathogen_mask_dim',6)
289
- settings.setdefault('cytoplasm',False)
290
- settings.setdefault('uninfected',True)
291
- settings.setdefault('cell_min_size',0)
292
- settings.setdefault('nucleus_min_size',0)
293
- settings.setdefault('pathogen_min_size',0)
294
- settings.setdefault('cytoplasm_min_size',0)
295
- settings.setdefault('merge_edge_pathogen_cells', True)
296
-
297
- if settings['test_mode']:
298
- settings['verbose'] = True
299
- settings['plot'] = True
300
- test_imgs = settings['test_nr']
301
- print(f'Test mode enabled with {test_imgs} images, plotting set to True')
302
-
303
- return settings
304
- settings.setdefault('normalize_by','png')
305
- settings.setdefault('crop_mode',['cell'])
306
- settings.setdefault('dialate_pngs', False)
307
- settings.setdefault('dialate_png_ratios', [0.2])
308
-
309
- # Timelapsed settings
310
- settings.setdefault('timelapse', False)
311
- settings.setdefault('timelapse_objects', 'cell')
312
-
313
- # Operational settings
314
- settings.setdefault('plot',False)
315
- settings.setdefault('n_jobs', os.cpu_count()-2)
316
-
317
- # Object settings
318
- settings.setdefault('cell_mask_dim',4)
319
- settings.setdefault('nucleus_mask_dim',5)
320
- settings.setdefault('pathogen_mask_dim',6)
321
- settings.setdefault('cytoplasm',False)
322
- settings.setdefault('uninfected',True)
323
- settings.setdefault('cell_min_size',0)
324
- settings.setdefault('nucleus_min_size',0)
325
- settings.setdefault('pathogen_min_size',0)
326
- settings.setdefault('cytoplasm_min_size',0)
327
- settings.setdefault('merge_edge_pathogen_cells', True)
328
-
329
- if settings['test_mode']:
330
- settings['verbose'] = True
331
- settings['plot'] = True
332
- test_imgs = settings['test_nr']
333
- print(f'Test mode enabled with {test_imgs} images, plotting set to True')
334
-
335
- return settings
336
- settings.setdefault('save_arrays', False)
337
- settings.setdefault('save_png',True)
338
- settings.setdefault('use_bounding_box',False)
339
- settings.setdefault('png_size',[224,224])
340
- settings.setdefault('png_dims',[0,1,2])
341
- settings.setdefault('normalize',False)
342
- settings.setdefault('normalize_by','png')
343
- settings.setdefault('crop_mode',['cell'])
344
- settings.setdefault('dialate_pngs', False)
345
- settings.setdefault('dialate_png_ratios', [0.2])
346
-
347
- # Timelapsed settings
348
- settings.setdefault('timelapse', False)
349
- settings.setdefault('timelapse_objects', 'cell')
300
+ settings.setdefault('timelapse_objects', ['cell'])
350
301
 
351
302
  # Operational settings
352
303
  settings.setdefault('plot',False)
@@ -388,7 +339,7 @@ def set_default_analyze_screen(settings):
388
339
  settings.setdefault('learning_rate',0.001)
389
340
  settings.setdefault('n_estimators',1000)
390
341
  settings.setdefault('test_size',0.2)
391
- settings.setdefault('location_column','column_name')
342
+ settings.setdefault('location_column','columnID')
392
343
  settings.setdefault('positive_control','c2')
393
344
  settings.setdefault('negative_control','c1')
394
345
  settings.setdefault('exclude',None)
@@ -451,7 +402,7 @@ def set_generate_training_dataset_defaults(settings):
451
402
  settings.setdefault('size',224)
452
403
  settings.setdefault('test_split',0.1)
453
404
  settings.setdefault('class_metadata',[['c1'],['c2']])
454
- settings.setdefault('metadata_type_by','column_name')
405
+ settings.setdefault('metadata_type_by','columnID')
455
406
  settings.setdefault('channel_of_interest',3)
456
407
  settings.setdefault('custom_measurement',None)
457
408
  settings.setdefault('tables',None)
@@ -473,7 +424,7 @@ def deep_spacr_defaults(settings):
473
424
  settings.setdefault('size',224)
474
425
  settings.setdefault('test_split',0.1)
475
426
  settings.setdefault('class_metadata',[['c1'],['c2']])
476
- settings.setdefault('metadata_type_by','column_name')
427
+ settings.setdefault('metadata_type_by','columnID')
477
428
  settings.setdefault('channel_of_interest',3)
478
429
  settings.setdefault('custom_measurement',None)
479
430
  settings.setdefault('tables',None)
@@ -557,7 +508,7 @@ def get_analyze_recruitment_default_settings(settings):
557
508
  settings.setdefault('pathogen_plate_metadata',[['c1', 'c2', 'c3'],['c4','c5', 'c6']])
558
509
  settings.setdefault('treatments',['cm', 'lovastatin'])
559
510
  settings.setdefault('treatment_plate_metadata',[['r1', 'r2','r3'], ['r4', 'r5','r6']])
560
- #settings.setdefault('metadata_types',['column_name', 'column_name', 'row_name'])
511
+ #settings.setdefault('metadata_types',['columnID', 'columnID', 'rowID'])
561
512
  settings.setdefault('channel_dims',[0,1,2,3])
562
513
  settings.setdefault('cell_chann_dim',3)
563
514
  settings.setdefault('cell_mask_dim',4)
@@ -579,7 +530,40 @@ def get_analyze_recruitment_default_settings(settings):
579
530
  settings.setdefault('pathogen_intensity_range',[0,100000])
580
531
  settings.setdefault('nucleus_intensity_range',[0,100000])
581
532
  settings.setdefault('cell_intensity_range',[0,100000])
582
- settings.setdefault('target_intensity_min',0)
533
+ settings.setdefault('target_intensity_min',1)
534
+ return settings
535
+
536
+ def get_default_test_cellpose_model_settings(settings):
537
+ settings.setdefault('src','path')
538
+ settings.setdefault('model_path','path')
539
+ settings.setdefault('save',True)
540
+ settings.setdefault('normalize',True)
541
+ settings.setdefault('percentiles',(2,98))
542
+ settings.setdefault('batch_size',50)
543
+ settings.setdefault('CP_probability',0)
544
+ settings.setdefault('FT',100)
545
+ settings.setdefault('target_size',1000)
546
+ return settings
547
+
548
+ def get_default_apply_cellpose_model_settings(settings):
549
+ settings.setdefault('src','path')
550
+ settings.setdefault('model_path','path')
551
+ settings.setdefault('save',True)
552
+ settings.setdefault('normalize',True)
553
+ settings.setdefault('percentiles',(2,98))
554
+ settings.setdefault('batch_size',50)
555
+ settings.setdefault('CP_probability',0)
556
+ settings.setdefault('FT',100)
557
+ settings.setdefault('circularize',False)
558
+ settings.setdefault('target_size',1000)
559
+ return settings
560
+
561
+ def default_settings_analyze_percent_positive(settings):
562
+ settings.setdefault('src','path')
563
+ settings.setdefault('tables',['cell'])
564
+ settings.setdefault('filter_1',['cell_area',1000])
565
+ settings.setdefault('value_col','cell_channel_2_mean_intensity')
566
+ settings.setdefault('threshold',2000)
583
567
  return settings
584
568
 
585
569
  def get_analyze_reads_default_settings(settings):
@@ -654,9 +638,8 @@ def get_perform_regression_default_settings(settings):
654
638
  settings.setdefault('cov_type',None)
655
639
  settings.setdefault('alpha',1)
656
640
  settings.setdefault('filter_value',['c1', 'c2', 'c3'])
657
- settings.setdefault('filter_column','column')
658
- settings.setdefault('plate','plate1')
659
- settings.setdefault('class_1_threshold',None)
641
+ settings.setdefault('filter_column','columnID')
642
+ settings.setdefault('plateID','plate1')
660
643
  settings.setdefault('metadata_files',['/home/carruthers/Documents/TGGT1_Summary.csv','/home/carruthers/Documents/TGME49_Summary.csv'])
661
644
  settings.setdefault('volcano','gene')
662
645
  settings.setdefault('toxo', True)
@@ -751,7 +734,7 @@ expected_types = {
751
734
  #"timelapse_frame_limits": (list, type(None)), # This can be a list of lists
752
735
  "timelapse_remove_transient": bool,
753
736
  "timelapse_mode": str,
754
- "timelapse_objects": list,
737
+ "timelapse_objects": (list, type(None)),
755
738
  "fps": int,
756
739
  "remove_background": bool,
757
740
  "lower_percentile": (int, float),
@@ -925,6 +908,7 @@ expected_types = {
925
908
  "agg_type": str,
926
909
  "min_cell_count": int,
927
910
  "resize": bool,
911
+ "denoise":bool,
928
912
  "target_height": (int, type(None)),
929
913
  "target_width": (int, type(None)),
930
914
  "rescale": bool,
@@ -1017,12 +1001,13 @@ expected_types = {
1017
1001
  "flow_threshold":float,
1018
1002
  "cell_diamiter":int,
1019
1003
  "nucleus_diamiter":int,
1020
- "pathogen_diamiter":int
1004
+ "pathogen_diamiter":int,
1005
+ "consolidate":bool
1021
1006
  }
1022
1007
 
1023
1008
  categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset","model_path","grna_csv","row_csv","column_csv", "metadata_files", "score_data","count_data"],
1024
1009
  "General": ["cell_mask_dim", "cytoplasm", "cell_chann_dim", "cell_channel", "nucleus_chann_dim", "nucleus_channel", "nucleus_mask_dim", "pathogen_mask_dim", "pathogen_chann_dim", "pathogen_channel", "test_mode", "plot", "metadata_type", "custom_regex", "experiment", "channels", "magnification", "channel_dims", "apply_model_to_dataset", "generate_training_dataset", "train_DL_model", "segmentation_mode", "delete_intermediate", "uninfected", ],
1025
- "Cellpose":["fill_in","from_scratch", "n_epochs", "width_height", "model_name", "custom_model", "resample", "rescale", "CP_prob", "flow_threshold", "percentiles", "invert", "diameter", "grayscale", "Signal_to_noise", "resize", "target_height", "target_width"],
1010
+ "Cellpose":["denoise","fill_in","from_scratch", "n_epochs", "width_height", "model_name", "custom_model", "resample", "rescale", "CP_prob", "flow_threshold", "percentiles", "invert", "diameter", "grayscale", "Signal_to_noise", "resize", "target_height", "target_width"],
1026
1011
  "Cell": ["cell_diamiter","cell_intensity_range", "cell_size_range", "cell_background", "cell_Signal_to_noise", "cell_CP_prob", "cell_FT", "remove_background_cell", "cell_min_size", "cytoplasm_min_size", "adjust_cells", "cells", "cell_loc"],
1027
1012
  "Nucleus": ["nucleus_diamiter","nucleus_intensity_range", "nucleus_size_range", "nucleus_background", "nucleus_Signal_to_noise", "nucleus_CP_prob", "nucleus_FT", "remove_background_nucleus", "nucleus_min_size", "nucleus_loc"],
1028
1013
  "Pathogen": ["pathogen_diamiter","pathogen_intensity_range", "pathogen_size_range", "pathogen_background", "pathogen_Signal_to_noise", "pathogen_CP_prob", "pathogen_FT", "pathogen_model", "remove_background_pathogen", "pathogen_min_size", "pathogens", "pathogen_loc", "pathogen_types", "pathogen_plate_metadata", ],
@@ -1033,13 +1018,13 @@ categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset
1033
1018
  "Hyperparamiters (Training)": ["png_type", "score_threshold","file_type", "train_channels", "epochs", "loss_type", "optimizer_type","image_size","val_split","learning_rate","weight_decay","dropout_rate", "init_weights", "train", "classes", "augment", "amsgrad","use_checkpoint","gradient_accumulation","gradient_accumulation_steps","intermedeate_save","pin_memory"],
1034
1019
  "Hyperparamiters (Embedding)": ["visualize","n_neighbors","min_dist","metric","resnet_features","reduction_method","embedding_by_controls","col_to_compare","log_data"],
1035
1020
  "Hyperparamiters (Clustering)": ["eps","min_samples","analyze_clusters","clustering","remove_cluster_noise"],
1036
- "Hyperparamiters (Regression)":["cross_validation","prune_features","reg_lambda","reg_alpha","cov_type", "class_1_threshold", "plate", "other", "fraction_threshold", "alpha", "random_row_column_effects", "regression_type", "min_cell_count", "agg_type", "transform", "dependent_variable"],
1021
+ "Hyperparamiters (Regression)":["cross_validation","prune_features","reg_lambda","reg_alpha","cov_type", "plate", "other", "fraction_threshold", "alpha", "random_row_column_effects", "regression_type", "min_cell_count", "agg_type", "transform", "dependent_variable"],
1037
1022
  "Hyperparamiters (Activation)":["cam_type", "overlay", "correlation", "target_layer", "normalize_input"],
1038
1023
  "Annotation": ["filter_column", "filter_value","volcano", "toxo", "controls", "nc_loc", "pc_loc", "nc", "pc", "cell_plate_metadata","treatment_plate_metadata", "metadata_types", "cell_types", "target","positive_control","negative_control", "location_column", "treatment_loc", "channel_of_interest", "measurement", "treatments", "um_per_pixel", "nr_imgs", "exclude", "exclude_conditions", "mix", "pos", "neg"],
1039
1024
  "Plot": ["split_axis_lims", "x_lim","log_x","log_y", "plot_control", "plot_nr", "examples_to_plot", "normalize_plots", "cmap", "figuresize", "plot_cluster_grids", "img_zoom", "row_limit", "color_by", "plot_images", "smooth_lines", "plot_points", "plot_outlines", "black_background", "plot_by_cluster", "heatmap_feature","grouping","min_max","cmap","save_figure"],
1040
1025
  "Timelapse": ["timelapse", "fps", "timelapse_displacement", "timelapse_memory", "timelapse_frame_limits", "timelapse_remove_transient", "timelapse_mode", "timelapse_objects", "compartments"],
1041
1026
  "Advanced": ["merge_edge_pathogen_cells", "test_images", "random_test", "test_nr", "test", "test_split", "normalize", "target_unique_count","threshold_multiplier", "threshold_method", "min_n","shuffle", "target_intensity_min", "cells_per_well", "nuclei_limit", "pathogen_limit", "background", "backgrounds", "schedule", "test_size","exclude","n_repeats","top_features", "model_type_ml", "model_type","minimum_cell_count","n_estimators","preprocess", "remove_background", "normalize", "lower_percentile", "merge_pathogens", "batch_size", "filter", "save", "masks", "verbose", "randomize", "n_jobs"],
1042
- "Beta": ["all_to_mip", "pick_slice", "skip_mode", "upscale", "upscale_factor"]
1027
+ "Beta": ["all_to_mip", "upscale", "upscale_factor", "consolidate"]
1043
1028
  }
1044
1029
 
1045
1030
 
@@ -1053,38 +1038,38 @@ def check_settings(vars_dict, expected_types, q=None):
1053
1038
  q = Queue()
1054
1039
 
1055
1040
  settings = {}
1041
+ errors = [] # Collect errors instead of stopping at the first one
1056
1042
 
1057
1043
  for key, (label, widget, var, _) in vars_dict.items():
1058
- if key not in expected_types:
1059
- if key not in category_keys:
1060
- q.put(f"Key {key} not found in expected types.")
1061
- continue
1044
+ if key not in expected_types and key not in category_keys:
1045
+ errors.append(f"Warning: Key '{key}' not found in expected types.")
1046
+ continue
1062
1047
 
1063
- value = var.get()
1048
+ value = var.get()
1064
1049
  if value in ['None', '']:
1065
1050
  value = None
1066
1051
 
1067
1052
  expected_type = expected_types.get(key, str)
1068
1053
 
1069
1054
  try:
1070
- #if key in ["cell_plate_metadata", "timelapse_frame_limits", "png_size", "pathogen_loc", "treatment_loc", "pathogen_plate_metadata", "treatment_plate_metadata", "barcode_coordinates", "class_metadata"]:
1071
- if key in ["cell_plate_metadata", "timelapse_frame_limits", "png_size", "png_dims", "pathogen_plate_metadata", "treatment_plate_metadata", "class_metadata", "crop_mode"]:
1072
-
1055
+ if key in ["cell_plate_metadata", "timelapse_frame_limits", "png_size", "png_dims", "pathogen_plate_metadata", "treatment_plate_metadata", "timelapse_objects", "class_metadata", "crop_mode"]:
1073
1056
  if value is None:
1074
- parsed_value = None
1057
+ parsed_value = None
1075
1058
  else:
1076
- parsed_value = ast.literal_eval(value) if isinstance(value, str) and value.strip() else None
1077
-
1078
- #parsed_value = ast.literal_eval(value) if value else None
1079
-
1059
+ try:
1060
+ parsed_value = ast.literal_eval(value)
1061
+ except (ValueError, SyntaxError):
1062
+ raise ValueError(f"Expected a list or list of lists but got an invalid format: {value}")
1063
+
1080
1064
  if isinstance(parsed_value, list):
1081
1065
  if all(isinstance(i, list) for i in parsed_value) or all(not isinstance(i, list) for i in parsed_value):
1082
1066
  settings[key] = parsed_value
1083
1067
  else:
1084
- raise ValueError("Invalid format: Mixed list and list of lists")
1068
+ raise ValueError(f"Invalid format: '{key}' contains mixed types (single values and lists).")
1069
+
1085
1070
  else:
1086
- raise ValueError("Invalid format for list or list of lists")
1087
-
1071
+ raise ValueError(f"Expected a list for '{key}', but got {type(parsed_value).__name__}.")
1072
+
1088
1073
  elif expected_type == list:
1089
1074
  settings[key] = parse_list(value) if value else None
1090
1075
 
@@ -1092,37 +1077,52 @@ def check_settings(vars_dict, expected_types, q=None):
1092
1077
  settings[key] = settings[key][0]
1093
1078
 
1094
1079
  elif expected_type == bool:
1095
- settings[key] = value if isinstance(value, bool) else value.lower() in ['true', '1', 't', 'y', 'yes']
1080
+ settings[key] = value.lower() in ['true', '1', 't', 'y', 'yes'] if isinstance(value, str) else bool(value)
1081
+
1096
1082
  elif expected_type == (int, type(None)):
1097
- settings[key] = settings[key] = int(value) if isinstance(value, int) or str(value).isdigit() else None
1083
+ if value is None or str(value).isdigit():
1084
+ settings[key] = int(value) if value is not None else None
1085
+ else:
1086
+ raise ValueError(f"Expected an integer or None for '{key}', but got '{value}'.")
1087
+
1098
1088
  elif expected_type == (float, type(None)):
1099
- settings[key] = float(value) if isinstance(value, float) or (isinstance(value, str) and value.replace(".", "", 1).isdigit()) else None
1089
+ if value is None or (isinstance(value, str) and value.replace(".", "", 1).isdigit()):
1090
+ settings[key] = float(value) if value is not None else None
1091
+ else:
1092
+ raise ValueError(f"Expected a float or None for '{key}', but got '{value}'.")
1093
+
1100
1094
  elif expected_type == (int, float):
1101
- settings[key] = float(value) if '.' in value else int(value)
1095
+ try:
1096
+ settings[key] = float(value) if '.' in str(value) else int(value)
1097
+ except ValueError:
1098
+ raise ValueError(f"Expected an integer or float for '{key}', but got '{value}'.")
1099
+
1102
1100
  elif expected_type == (str, type(None)):
1103
- settings[key] = str(value) if value else None
1101
+ settings[key] = str(value) if value is not None else None
1102
+
1104
1103
  elif expected_type == (str, type(None), list):
1105
1104
  if isinstance(value, list):
1106
1105
  settings[key] = parse_list(value) if value else None
1107
1106
  elif isinstance(value, str):
1108
- settings[key] = str(value)
1107
+ settings[key] = str(value)
1109
1108
  else:
1110
1109
  settings[key] = None
1111
1110
 
1112
1111
  elif expected_type == dict:
1113
1112
  try:
1114
- # Ensure that the value is a string that can be converted to a dictionary
1115
1113
  if isinstance(value, str):
1116
- settings[key] = ast.literal_eval(value)
1114
+ parsed_dict = ast.literal_eval(value)
1117
1115
  else:
1118
1116
  raise ValueError("Expected a string representation of a dictionary.")
1119
-
1120
- # Check if the result is actually a dictionary
1121
- if not isinstance(settings[key], dict):
1122
- raise ValueError("Value is not a valid dictionary.")
1117
+
1118
+ if not isinstance(parsed_dict, dict):
1119
+ raise ValueError(f"Expected a dictionary for '{key}', but got {type(parsed_dict).__name__}.")
1120
+
1121
+ settings[key] = parsed_dict
1123
1122
  except (ValueError, SyntaxError) as e:
1124
1123
  settings[key] = {}
1125
- q.put(f"Error: Invalid format for {key}. Expected type: dict. Error: {e}")
1124
+ errors.append(f"Error: Invalid dictionary format for '{key}'. Expected type: dict. Error: {e}")
1125
+
1126
1126
  elif isinstance(expected_type, tuple):
1127
1127
  for typ in expected_type:
1128
1128
  try:
@@ -1131,15 +1131,25 @@ def check_settings(vars_dict, expected_types, q=None):
1131
1131
  except (ValueError, TypeError):
1132
1132
  continue
1133
1133
  else:
1134
- raise ValueError
1134
+ raise ValueError(f"Value '{value}' for '{key}' does not match any expected types: {expected_type}.")
1135
+
1135
1136
  else:
1136
- settings[key] = expected_type(value) if value else None
1137
+ try:
1138
+ settings[key] = expected_type(value) if value else None
1139
+ except (ValueError, TypeError):
1140
+ raise ValueError(f"Expected type {expected_type.__name__} for '{key}', but got '{value}'.")
1141
+
1137
1142
  except (ValueError, SyntaxError) as e:
1138
1143
  expected_type_name = ' or '.join([t.__name__ for t in expected_type]) if isinstance(expected_type, tuple) else expected_type.__name__
1139
- q.put(f"Error: Invalid format for {key}. Expected type: {expected_type_name}. Error: {e}, Value entered: {value}")
1140
- return
1144
+ errors.append(f"Error: '{key}' has invalid format. Expected type: {expected_type_name}. Got value: '{value}'. Error: {e}")
1141
1145
 
1142
- return settings
1146
+ # Send all collected errors to the queue
1147
+ for error in errors:
1148
+ q.put(error)
1149
+
1150
+
1151
+
1152
+ return settings, errors
1143
1153
 
1144
1154
  def generate_fields(variables, scrollable_frame):
1145
1155
  from .gui_utils import create_input_field
@@ -1164,16 +1174,25 @@ def generate_fields(variables, scrollable_frame):
1164
1174
  "black_background": "(bool) - Whether to use a black background for plots.",
1165
1175
  "calculate_correlation": "(bool) - Whether to calculate correlations between features.",
1166
1176
  "cell_CP_prob": "(float) - The cellpose probability threshold for the cell channel. This will be used in cell segmentation.",
1177
+ "nucleus_CP_prob": "(float) - The cellpose probability threshold for the nucleus channel. This will be used in cell segmentation.",
1178
+ "pathogen_CP_prob": "(float) - The cellpose probability threshold for the pathogen channel. This will be used in cell segmentation.",
1167
1179
  "cell_FT": "(float) - The flow threshold for cell objects. This will be used to segment the cells.",
1168
- "cell_background": "(float) - The background intensity for the cell channel. This will be used to remove background noise.",
1180
+ "nucleus_FT": "(float) - The flow threshold for nucleus objects. This will be used to segment the cells.",
1181
+ "pathogen_FT": "(float) - The flow threshold for pathogen objects. This will be used to segment the cells.",
1182
+ "cell_background": "(int) - The background intensity for the cell channel. This will be used to remove background noise.",
1183
+ "nucleus_background": "(int) - The background intensity for the nucleus channel. This will be used to remove background noise.",
1184
+ "pathogen_background": "(int) - The background intensity for the pathogen channel. This will be used to remove background noise.",
1169
1185
  "cell_chann_dim": "(int) - Dimension of the channel to use for cell segmentation.",
1170
- "cell_channel": "(int) - The channel to use for the cell. If None, the cell will not be segmented.",
1186
+ "cell_channel": "(int) - The channel to use for generatin cell masks. If None, cell masks will not be generated.",
1187
+ "nucleus_channel": "(int) - The channel to use for generatin nucleus masks. If None, nucleus masks will not be generated.",
1188
+ "pathogen_channel": "(int) - The channel to use for generatin pathogen masks. If None, pathogen masks will not be generated.",
1171
1189
  "cell_intensity_range": "(list) - Intensity range for cell segmentation.",
1172
1190
  "cell_loc": "(list) - The locations of the cell types in the images.",
1173
- "cell_mask_dim": "(int) - The dimension of the array the cell mask is saved in.",
1191
+ "cell_mask_dim": "(int) - The dimension of the array the cell mask is saved in (array order:channels,cell, nucleus, pathogen, cytoplasm) array starts at dimension 0.",
1192
+ "nucleus_mask_dim": "(int) - The dimension of the array the nucleus mask is saved in (array order:channels,cell, nucleus, pathogen, cytoplasm) array starts at dimension 0.",
1174
1193
  "cell_min_size": "(int) - The minimum size of cell objects in pixels^2.",
1175
1194
  "cell_plate_metadata": "(str) - Metadata for the cell plate.",
1176
- "cell_Signal_to_noise": "(float) - The signal-to-noise ratio for the cell channel. This will be used to determine the range of intensities to normalize images to for cell segmentation.",
1195
+ "cell_Signal_to_noise": "(int) - The signal-to-noise ratio for the cell channel. This will be used to determine the range of intensities to normalize images to for cell segmentation.",
1177
1196
  "cell_size_range": "(list) - Size range for cell segmentation.",
1178
1197
  "cell_types": "(list) - Types of cells to include in the analysis.",
1179
1198
  "cells": "(list of lists) - The cell types to include in the analysis.",
@@ -1188,13 +1207,17 @@ def generate_fields(variables, scrollable_frame):
1188
1207
  "col_to_compare": "(str) - Column to compare in the embeddings.",
1189
1208
  "color_by": "(str) - Coloring scheme for the plots.",
1190
1209
  "compartments": "(list) - The compartments to measure in the images.",
1210
+ "consolidate": "(bool) - Consolidate image files from subfolders into one folder named consolidated.",
1191
1211
  "CP_prob": "(float) - Cellpose probability threshold for segmentation.",
1192
1212
  "crop_mode": "(str) - Mode to use for cropping images (cell, nucleus, pathogen, cytoplasm).",
1193
1213
  "custom_model": "(str) - Path to a custom Cellpose model.",
1194
- "custom_regex": "(str) - Custom regex pattern to extract metadata from the image names. This will only be used if 'custom' is selected for 'metadata_type'.",
1214
+ "custom_regex": "(str) - Custom regex pattern to extract metadata from the image names. This will only be used if 'custom' or 'auto' is selected for 'metadata_type'.",
1195
1215
  "cytoplasm": "(bool) - Whether to segment the cytoplasm (Cell - Nucleus + Pathogen).",
1196
1216
  "cytoplasm_min_size": "(int) - The minimum size of cytoplasm objects in pixels^2.",
1217
+ "nucleus_min_size": "(int) - The minimum size of nucleus objects in pixels^2.",
1218
+ "normalize_by": "(str) - Normalize cropped png images by png or by field of view.",
1197
1219
  "dependent_variable": "(str) - The dependent variable for the regression analysis.",
1220
+ "delete_intermediate": "(bool) - Delete intermediate folders (stack, channel, norm_channel_stack).",
1198
1221
  "diameter": "(float) - Diameter of the objects to segment.",
1199
1222
  "dialate_png_ratios": "(list) - The ratios to use for dilating the PNG images. This will determine the amount of dilation applied to the images before cropping.",
1200
1223
  "dialate_pngs": "(bool) - Whether to dilate the PNG images before saving.",
@@ -1242,7 +1265,7 @@ def generate_fields(variables, scrollable_frame):
1242
1265
  "manders_thresholds": "(list) - Thresholds for Manders' coefficients.",
1243
1266
  "mask": "(bool) - Whether to generate masks for the segmented objects. If True, masks will be generated for the nucleus, cell, and pathogen.",
1244
1267
  "measurement": "(str) - The measurement to use for the analysis.",
1245
- "metadata_type": "(str) - Type of metadata to expect in the images. This will determine how the images are processed. If 'custom' is selected, you can provide a custom regex pattern to extract metadata from the image names.",
1268
+ "metadata_type": "(str) - Type of metadata to expect in the images. If 'custom' is selected, you can provide a custom regex pattern to extract metadata from the image names. auto will attempt to automatically extract metadata from the image names. cellvoyager and cq1 will use the default metadata extraction for CellVoyager and CQ1 images.",
1246
1269
  "metadata_types": "(list) - Types of metadata to include in the analysis.",
1247
1270
  "merge_edge_pathogen_cells": "(bool) - Whether to merge cells that share pathogen objects.",
1248
1271
  "merge_pathogens": "(bool) - Whether to merge pathogen objects that share more than 75 percent of their perimeter.",
@@ -1263,13 +1286,13 @@ def generate_fields(variables, scrollable_frame):
1263
1286
  "n_jobs": "(int) - The number of n_jobs to use for processing the images. This will determine how many images are processed in parallel. Increase to speed up processing.",
1264
1287
  "n_neighbors": "(int) - Number of neighbors for UMAP.",
1265
1288
  "n_repeats": "(int) - Number of repeats for the pathogen plate.",
1266
- "pathogen_Signal_to_noise": "(float) - The signal-to-noise ratio for the pathogen channel. This will be used to determine the range of intensities to normalize images to for pathogen segmentation.",
1289
+ "pathogen_Signal_to_noise": "(int) - The signal-to-noise ratio for the pathogen channel. This will be used to determine the range of intensities to normalize images to for pathogen segmentation.",
1290
+ "nucleus_Signal_to_noise": "(int) - The signal-to-noise ratio for the nucleus channel. This will be used to determine the range of intensities to normalize images to for nucleus segmentation.",
1267
1291
  "pathogen_size_range": "(list) - Size range for pathogen segmentation.",
1268
1292
  "pathogen_types": "(list) - Types of pathogens to include in the analysis.",
1269
1293
  "pc": "(str) - Positive control identifier.",
1270
1294
  "pc_loc": "(str) - Location of the positive control in the images.",
1271
1295
  "percentiles": "(list) - Percentiles to use for normalizing the images.",
1272
- "pick_slice": "(bool) - Whether to pick a single slice from the z-stack images. If False, the maximum intensity projection will be used.",
1273
1296
  "pin_memory": "(bool) - Whether to pin memory for the data loader.",
1274
1297
  "plate": "(str) - Plate identifier for the experiment.",
1275
1298
  "plate_dict": "(dict) - Dictionary of plate metadata.",
@@ -1310,10 +1333,11 @@ def generate_fields(variables, scrollable_frame):
1310
1333
  "save_measurements": "(bool) - Whether to save the measurements to disk.",
1311
1334
  "save_png": "(bool) - Whether to save the segmented objects as PNG images.",
1312
1335
  "schedule": "(str) - Schedule for processing the data.",
1313
- "Signal_to_noise": "(float) - Signal-to-noise ratio for the images.",
1336
+ "Signal_to_noise": "(int) - Signal-to-noise ratio for the images.",
1314
1337
  "skip_mode": "(str) - The mode to use for skipping images. This will determine how to handle images that cannot be processed.",
1315
1338
  "smooth_lines": "(bool) - Whether to smooth lines in the plots.",
1316
1339
  "src": "(str, path) - Path to source directory.",
1340
+ "segmentation_mode": "(str) - Algorithm to use for segmentation (cellpose or mediar).",
1317
1341
  "target": "(str) - Target variable for the analysis.",
1318
1342
  "target_height": "(int) - Target height for resizing the images.",
1319
1343
  "target_intensity_min": "(float) - Minimum intensity for the target objects.",
@@ -1363,7 +1387,7 @@ def generate_fields(variables, scrollable_frame):
1363
1387
  "masks": "(bool) - Whether to generate masks for the segmented objects.",
1364
1388
  "timelapse": "(bool) - Whether to analyze images as a timelapse.",
1365
1389
  "pathogen_min_size": "(int) - The minimum size of pathogen objects in pixels^2.",
1366
- "pathogen_mask_dim": "(int) - The dimension of the array the pathogen mask is saved in.",
1390
+ "pathogen_mask_dim": "(int) - The dimension of the array the pathogen mask is saved in (array order:channels,cell, nucleus, pathogen, cytoplasm) array starts at dimension 0.",
1367
1391
  "use_bounding_box": "(bool) - Whether to use the bounding box for cropping the images.",
1368
1392
  "plot_points": "(bool) - Whether to plot scatterplot points.",
1369
1393
  "embedding_by_controls": "(bool) - Use the controlls to greate the embedding, then apply this embedding to all of the data.",
@@ -1393,6 +1417,7 @@ def generate_fields(variables, scrollable_frame):
1393
1417
  "shuffle": "(bool) - Shuffle the dataset bufore generating the activation maps",
1394
1418
  "correlation": "(bool) - Calculate correlation between image channels and activation maps. Data is saved to .db.",
1395
1419
  "normalize_input": "(bool) - Normalize the input images before passing them to the model.",
1420
+ "normalize_plots": "(bool) - Normalize images before plotting.",
1396
1421
  }
1397
1422
 
1398
1423
  for key, (var_type, options, default_value) in variables.items():
@@ -1444,8 +1469,8 @@ def set_annotate_default_settings(settings):
1444
1469
  settings.setdefault('normalize', 'False')
1445
1470
  settings.setdefault('normalize_channels', "r,g,b")
1446
1471
  settings.setdefault('percentiles', [2, 98])
1447
- settings.setdefault('measurement', '')#'cytoplasm_channel_3_mean_intensity,pathogen_channel_3_mean_intensity')
1448
- settings.setdefault('threshold', '')#'2')
1472
+ settings.setdefault('measurement', '') #'cytoplasm_channel_3_mean_intensity,pathogen_channel_3_mean_intensity')
1473
+ settings.setdefault('threshold', '') #'2')
1449
1474
  return settings
1450
1475
 
1451
1476
  def set_default_generate_barecode_mapping(settings={}):
@@ -1465,6 +1490,7 @@ def set_default_generate_barecode_mapping(settings={}):
1465
1490
  settings.setdefault('mode', 'paired')
1466
1491
  settings.setdefault('single_direction', 'R1')
1467
1492
  settings.setdefault('test', False)
1493
+ settings.setdefault('fill_na', False)
1468
1494
  return settings
1469
1495
 
1470
1496
  def get_default_generate_activation_map_settings(settings):