spacr 0.4.12__py3-none-any.whl → 0.4.60__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/core.py +54 -8
- spacr/deep_spacr.py +2 -3
- spacr/gui_core.py +259 -75
- spacr/gui_elements.py +133 -2
- spacr/gui_utils.py +24 -20
- spacr/io.py +553 -61
- spacr/measure.py +11 -12
- spacr/ml.py +141 -258
- spacr/plot.py +76 -34
- spacr/sequencing.py +73 -38
- spacr/settings.py +160 -93
- spacr/submodules.py +620 -214
- spacr/timelapse.py +25 -25
- spacr/toxo.py +23 -23
- spacr/utils.py +249 -95
- {spacr-0.4.12.dist-info → spacr-0.4.60.dist-info}/METADATA +2 -1
- {spacr-0.4.12.dist-info → spacr-0.4.60.dist-info}/RECORD +21 -21
- {spacr-0.4.12.dist-info → spacr-0.4.60.dist-info}/LICENSE +0 -0
- {spacr-0.4.12.dist-info → spacr-0.4.60.dist-info}/WHEEL +0 -0
- {spacr-0.4.12.dist-info → spacr-0.4.60.dist-info}/entry_points.txt +0 -0
- {spacr-0.4.12.dist-info → spacr-0.4.60.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,7 +88,7 @@ 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',
|
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)
|
@@ -219,7 +221,7 @@ def set_default_umap_image_settings(settings={}):
|
|
219
221
|
settings.setdefault('smooth_lines', True)
|
220
222
|
settings.setdefault('clustering', 'dbscan')
|
221
223
|
settings.setdefault('exclude', None)
|
222
|
-
settings.setdefault('col_to_compare', '
|
224
|
+
settings.setdefault('col_to_compare', 'columnID')
|
223
225
|
settings.setdefault('pos', 'c1')
|
224
226
|
settings.setdefault('neg', 'c2')
|
225
227
|
settings.setdefault('mix', 'c3')
|
@@ -256,7 +258,13 @@ def get_measure_crop_settings(settings={}):
|
|
256
258
|
settings.setdefault('homogeneity', True)
|
257
259
|
settings.setdefault('homogeneity_distances', [8,16,32])
|
258
260
|
|
259
|
-
# Cropping settings
|
261
|
+
# Cropping settings # Cropping settings
|
262
|
+
settings.setdefault('save_arrays', False)
|
263
|
+
settings.setdefault('save_png',True)
|
264
|
+
settings.setdefault('use_bounding_box',False)
|
265
|
+
settings.setdefault('png_size',[224,224])
|
266
|
+
settings.setdefault('png_dims',[0,1,2])
|
267
|
+
settings.setdefault('normalize',False) # Cropping settings
|
260
268
|
settings.setdefault('save_arrays', False)
|
261
269
|
settings.setdefault('save_png',True)
|
262
270
|
settings.setdefault('use_bounding_box',False)
|
@@ -277,9 +285,9 @@ def get_measure_crop_settings(settings={}):
|
|
277
285
|
settings.setdefault('n_jobs', os.cpu_count()-2)
|
278
286
|
|
279
287
|
# Object settings
|
280
|
-
settings.setdefault('cell_mask_dim',
|
281
|
-
settings.setdefault('nucleus_mask_dim',
|
282
|
-
settings.setdefault('pathogen_mask_dim',
|
288
|
+
settings.setdefault('cell_mask_dim',4)
|
289
|
+
settings.setdefault('nucleus_mask_dim',5)
|
290
|
+
settings.setdefault('pathogen_mask_dim',6)
|
283
291
|
settings.setdefault('cytoplasm',False)
|
284
292
|
settings.setdefault('uninfected',True)
|
285
293
|
settings.setdefault('cell_min_size',0)
|
@@ -312,7 +320,7 @@ def set_default_analyze_screen(settings):
|
|
312
320
|
settings.setdefault('learning_rate',0.001)
|
313
321
|
settings.setdefault('n_estimators',1000)
|
314
322
|
settings.setdefault('test_size',0.2)
|
315
|
-
settings.setdefault('location_column','
|
323
|
+
settings.setdefault('location_column','columnID')
|
316
324
|
settings.setdefault('positive_control','c2')
|
317
325
|
settings.setdefault('negative_control','c1')
|
318
326
|
settings.setdefault('exclude',None)
|
@@ -375,7 +383,7 @@ def set_generate_training_dataset_defaults(settings):
|
|
375
383
|
settings.setdefault('size',224)
|
376
384
|
settings.setdefault('test_split',0.1)
|
377
385
|
settings.setdefault('class_metadata',[['c1'],['c2']])
|
378
|
-
settings.setdefault('metadata_type_by','
|
386
|
+
settings.setdefault('metadata_type_by','columnID')
|
379
387
|
settings.setdefault('channel_of_interest',3)
|
380
388
|
settings.setdefault('custom_measurement',None)
|
381
389
|
settings.setdefault('tables',None)
|
@@ -397,7 +405,7 @@ def deep_spacr_defaults(settings):
|
|
397
405
|
settings.setdefault('size',224)
|
398
406
|
settings.setdefault('test_split',0.1)
|
399
407
|
settings.setdefault('class_metadata',[['c1'],['c2']])
|
400
|
-
settings.setdefault('metadata_type_by','
|
408
|
+
settings.setdefault('metadata_type_by','columnID')
|
401
409
|
settings.setdefault('channel_of_interest',3)
|
402
410
|
settings.setdefault('custom_measurement',None)
|
403
411
|
settings.setdefault('tables',None)
|
@@ -473,7 +481,7 @@ def get_train_test_model_settings(settings):
|
|
473
481
|
return settings
|
474
482
|
|
475
483
|
def get_analyze_recruitment_default_settings(settings):
|
476
|
-
settings.setdefault('src','path')
|
484
|
+
settings.setdefault('src', 'path')
|
477
485
|
settings.setdefault('target','protein')
|
478
486
|
settings.setdefault('cell_types',['HeLa'])
|
479
487
|
settings.setdefault('cell_plate_metadata',None)
|
@@ -481,7 +489,7 @@ def get_analyze_recruitment_default_settings(settings):
|
|
481
489
|
settings.setdefault('pathogen_plate_metadata',[['c1', 'c2', 'c3'],['c4','c5', 'c6']])
|
482
490
|
settings.setdefault('treatments',['cm', 'lovastatin'])
|
483
491
|
settings.setdefault('treatment_plate_metadata',[['r1', 'r2','r3'], ['r4', 'r5','r6']])
|
484
|
-
#settings.setdefault('metadata_types',['
|
492
|
+
#settings.setdefault('metadata_types',['columnID', 'columnID', 'rowID'])
|
485
493
|
settings.setdefault('channel_dims',[0,1,2,3])
|
486
494
|
settings.setdefault('cell_chann_dim',3)
|
487
495
|
settings.setdefault('cell_mask_dim',4)
|
@@ -503,7 +511,40 @@ def get_analyze_recruitment_default_settings(settings):
|
|
503
511
|
settings.setdefault('pathogen_intensity_range',[0,100000])
|
504
512
|
settings.setdefault('nucleus_intensity_range',[0,100000])
|
505
513
|
settings.setdefault('cell_intensity_range',[0,100000])
|
506
|
-
settings.setdefault('target_intensity_min',
|
514
|
+
settings.setdefault('target_intensity_min',1)
|
515
|
+
return settings
|
516
|
+
|
517
|
+
def get_default_test_cellpose_model_settings(settings):
|
518
|
+
settings.setdefault('src','path')
|
519
|
+
settings.setdefault('model_path','path')
|
520
|
+
settings.setdefault('save',True)
|
521
|
+
settings.setdefault('normalize',True)
|
522
|
+
settings.setdefault('percentiles',(2,98))
|
523
|
+
settings.setdefault('batch_size',50)
|
524
|
+
settings.setdefault('CP_probability',0)
|
525
|
+
settings.setdefault('FT',100)
|
526
|
+
settings.setdefault('target_size',1000)
|
527
|
+
return settings
|
528
|
+
|
529
|
+
def get_default_apply_cellpose_model_settings(settings):
|
530
|
+
settings.setdefault('src','path')
|
531
|
+
settings.setdefault('model_path','path')
|
532
|
+
settings.setdefault('save',True)
|
533
|
+
settings.setdefault('normalize',True)
|
534
|
+
settings.setdefault('percentiles',(2,98))
|
535
|
+
settings.setdefault('batch_size',50)
|
536
|
+
settings.setdefault('CP_probability',0)
|
537
|
+
settings.setdefault('FT',100)
|
538
|
+
settings.setdefault('circularize',False)
|
539
|
+
settings.setdefault('target_size',1000)
|
540
|
+
return settings
|
541
|
+
|
542
|
+
def default_settings_analyze_percent_positive(settings):
|
543
|
+
settings.setdefault('src','path')
|
544
|
+
settings.setdefault('tables',['cell'])
|
545
|
+
settings.setdefault('filter_1',['cell_area',1000])
|
546
|
+
settings.setdefault('value_col','cell_channel_2_mean_intensity')
|
547
|
+
settings.setdefault('threshold',2000)
|
507
548
|
return settings
|
508
549
|
|
509
550
|
def get_analyze_reads_default_settings(settings):
|
@@ -578,9 +619,8 @@ def get_perform_regression_default_settings(settings):
|
|
578
619
|
settings.setdefault('cov_type',None)
|
579
620
|
settings.setdefault('alpha',1)
|
580
621
|
settings.setdefault('filter_value',['c1', 'c2', 'c3'])
|
581
|
-
settings.setdefault('filter_column','
|
582
|
-
settings.setdefault('
|
583
|
-
settings.setdefault('class_1_threshold',None)
|
622
|
+
settings.setdefault('filter_column','columnID')
|
623
|
+
settings.setdefault('plateID','plate1')
|
584
624
|
settings.setdefault('metadata_files',['/home/carruthers/Documents/TGGT1_Summary.csv','/home/carruthers/Documents/TGME49_Summary.csv'])
|
585
625
|
settings.setdefault('volcano','gene')
|
586
626
|
settings.setdefault('toxo', True)
|
@@ -672,6 +712,7 @@ expected_types = {
|
|
672
712
|
"timelapse_displacement": int,
|
673
713
|
"timelapse_memory": int,
|
674
714
|
"timelapse_frame_limits": (list, type(None)), # This can be a list of lists
|
715
|
+
#"timelapse_frame_limits": (list, type(None)), # This can be a list of lists
|
675
716
|
"timelapse_remove_transient": bool,
|
676
717
|
"timelapse_mode": str,
|
677
718
|
"timelapse_objects": list,
|
@@ -848,6 +889,7 @@ expected_types = {
|
|
848
889
|
"agg_type": str,
|
849
890
|
"min_cell_count": int,
|
850
891
|
"resize": bool,
|
892
|
+
"denoise":bool,
|
851
893
|
"target_height": (int, type(None)),
|
852
894
|
"target_width": (int, type(None)),
|
853
895
|
"rescale": bool,
|
@@ -940,30 +982,30 @@ expected_types = {
|
|
940
982
|
"flow_threshold":float,
|
941
983
|
"cell_diamiter":int,
|
942
984
|
"nucleus_diamiter":int,
|
943
|
-
"pathogen_diamiter":int
|
985
|
+
"pathogen_diamiter":int,
|
986
|
+
"consolidate":bool
|
944
987
|
}
|
945
988
|
|
946
989
|
categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset","model_path","grna_csv","row_csv","column_csv", "metadata_files", "score_data","count_data"],
|
947
|
-
"General": ["metadata_type", "custom_regex", "experiment", "channels", "magnification", "channel_dims", "apply_model_to_dataset", "generate_training_dataset", "train_DL_model", "segmentation_mode", "delete_intermediate"],
|
948
|
-
"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"],
|
949
|
-
"Cell": ["cell_diamiter","cell_intensity_range", "cell_size_range", "
|
950
|
-
"Nucleus": ["nucleus_diamiter","nucleus_intensity_range", "nucleus_size_range", "
|
951
|
-
"Pathogen": ["pathogen_diamiter","pathogen_intensity_range", "pathogen_size_range", "
|
990
|
+
"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", ],
|
991
|
+
"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"],
|
992
|
+
"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"],
|
993
|
+
"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"],
|
994
|
+
"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", ],
|
952
995
|
"Measurements": ["remove_image_canvas", "remove_highly_correlated", "homogeneity", "homogeneity_distances", "radial_dist", "calculate_correlation", "manders_thresholds", "save_measurements", "tables", "image_nr", "dot_size", "filter_by", "remove_highly_correlated_features", "remove_low_variance_features", "channel_of_interest"],
|
953
|
-
"Object Image": ["save_png", "dialate_pngs", "dialate_png_ratios", "png_size", "png_dims", "save_arrays", "normalize_by", "crop_mode", "
|
996
|
+
"Object Image": ["save_png", "dialate_pngs", "dialate_png_ratios", "png_size", "png_dims", "save_arrays", "normalize_by", "crop_mode", "use_bounding_box"],
|
954
997
|
"Sequencing": ["outlier_detection","offset_start","chunk_size","single_direction", "signal_direction","mode","comp_level","comp_type","save_h5","expected_end","offset","target_sequence","regex", "highlight"],
|
955
998
|
"Generate Dataset":["save_to_db","file_metadata","class_metadata", "annotation_column","annotated_classes", "dataset_mode", "metadata_type_by","custom_measurement", "sample", "size"],
|
956
999
|
"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"],
|
957
1000
|
"Hyperparamiters (Embedding)": ["visualize","n_neighbors","min_dist","metric","resnet_features","reduction_method","embedding_by_controls","col_to_compare","log_data"],
|
958
1001
|
"Hyperparamiters (Clustering)": ["eps","min_samples","analyze_clusters","clustering","remove_cluster_noise"],
|
959
|
-
"Hyperparamiters (Regression)":["cross_validation","prune_features","reg_lambda","reg_alpha","cov_type", "
|
1002
|
+
"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"],
|
960
1003
|
"Hyperparamiters (Activation)":["cam_type", "overlay", "correlation", "target_layer", "normalize_input"],
|
961
1004
|
"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"],
|
962
|
-
"Plot": ["
|
963
|
-
"Test": ["test_mode", "test_images", "random_test", "test_nr", "test", "test_split"],
|
1005
|
+
"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"],
|
964
1006
|
"Timelapse": ["timelapse", "fps", "timelapse_displacement", "timelapse_memory", "timelapse_frame_limits", "timelapse_remove_transient", "timelapse_mode", "timelapse_objects", "compartments"],
|
965
|
-
"Advanced": ["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"],
|
966
|
-
"
|
1007
|
+
"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"],
|
1008
|
+
"Beta": ["all_to_mip", "pick_slice", "skip_mode", "upscale", "upscale_factor", "consolidate"]
|
967
1009
|
}
|
968
1010
|
|
969
1011
|
|
@@ -977,32 +1019,38 @@ def check_settings(vars_dict, expected_types, q=None):
|
|
977
1019
|
q = Queue()
|
978
1020
|
|
979
1021
|
settings = {}
|
1022
|
+
errors = [] # Collect errors instead of stopping at the first one
|
980
1023
|
|
981
1024
|
for key, (label, widget, var, _) in vars_dict.items():
|
982
|
-
if key not in expected_types:
|
983
|
-
|
984
|
-
|
985
|
-
continue
|
1025
|
+
if key not in expected_types and key not in category_keys:
|
1026
|
+
errors.append(f"Warning: Key '{key}' not found in expected types.")
|
1027
|
+
continue
|
986
1028
|
|
987
1029
|
value = var.get()
|
988
|
-
if value
|
1030
|
+
if value in ['None', '']:
|
989
1031
|
value = None
|
990
1032
|
|
991
1033
|
expected_type = expected_types.get(key, str)
|
992
1034
|
|
993
1035
|
try:
|
994
|
-
if key in ["cell_plate_metadata", "timelapse_frame_limits", "png_size", "
|
995
|
-
|
1036
|
+
if key in ["cell_plate_metadata", "timelapse_frame_limits", "png_size", "png_dims", "pathogen_plate_metadata", "treatment_plate_metadata", "class_metadata", "crop_mode"]:
|
1037
|
+
if value is None:
|
1038
|
+
parsed_value = None
|
1039
|
+
else:
|
1040
|
+
try:
|
1041
|
+
parsed_value = ast.literal_eval(value)
|
1042
|
+
except (ValueError, SyntaxError):
|
1043
|
+
raise ValueError(f"Expected a list or list of lists but got an invalid format: {value}")
|
1044
|
+
|
996
1045
|
if isinstance(parsed_value, list):
|
997
1046
|
if all(isinstance(i, list) for i in parsed_value) or all(not isinstance(i, list) for i in parsed_value):
|
998
1047
|
settings[key] = parsed_value
|
999
1048
|
else:
|
1000
|
-
raise ValueError("Invalid format:
|
1001
|
-
|
1002
|
-
# settings[key] = None
|
1049
|
+
raise ValueError(f"Invalid format: '{key}' contains mixed types (single values and lists).")
|
1050
|
+
|
1003
1051
|
else:
|
1004
|
-
raise ValueError("
|
1005
|
-
|
1052
|
+
raise ValueError(f"Expected a list for '{key}', but got {type(parsed_value).__name__}.")
|
1053
|
+
|
1006
1054
|
elif expected_type == list:
|
1007
1055
|
settings[key] = parse_list(value) if value else None
|
1008
1056
|
|
@@ -1010,37 +1058,52 @@ def check_settings(vars_dict, expected_types, q=None):
|
|
1010
1058
|
settings[key] = settings[key][0]
|
1011
1059
|
|
1012
1060
|
elif expected_type == bool:
|
1013
|
-
settings[key] = value
|
1061
|
+
settings[key] = value.lower() in ['true', '1', 't', 'y', 'yes'] if isinstance(value, str) else bool(value)
|
1062
|
+
|
1014
1063
|
elif expected_type == (int, type(None)):
|
1015
|
-
|
1064
|
+
if value is None or str(value).isdigit():
|
1065
|
+
settings[key] = int(value) if value is not None else None
|
1066
|
+
else:
|
1067
|
+
raise ValueError(f"Expected an integer or None for '{key}', but got '{value}'.")
|
1068
|
+
|
1016
1069
|
elif expected_type == (float, type(None)):
|
1017
|
-
|
1070
|
+
if value is None or (isinstance(value, str) and value.replace(".", "", 1).isdigit()):
|
1071
|
+
settings[key] = float(value) if value is not None else None
|
1072
|
+
else:
|
1073
|
+
raise ValueError(f"Expected a float or None for '{key}', but got '{value}'.")
|
1074
|
+
|
1018
1075
|
elif expected_type == (int, float):
|
1019
|
-
|
1076
|
+
try:
|
1077
|
+
settings[key] = float(value) if '.' in str(value) else int(value)
|
1078
|
+
except ValueError:
|
1079
|
+
raise ValueError(f"Expected an integer or float for '{key}', but got '{value}'.")
|
1080
|
+
|
1020
1081
|
elif expected_type == (str, type(None)):
|
1021
|
-
settings[key] = str(value) if value else None
|
1082
|
+
settings[key] = str(value) if value is not None else None
|
1083
|
+
|
1022
1084
|
elif expected_type == (str, type(None), list):
|
1023
1085
|
if isinstance(value, list):
|
1024
1086
|
settings[key] = parse_list(value) if value else None
|
1025
1087
|
elif isinstance(value, str):
|
1026
|
-
settings[key] = str(value)
|
1088
|
+
settings[key] = str(value)
|
1027
1089
|
else:
|
1028
1090
|
settings[key] = None
|
1029
1091
|
|
1030
1092
|
elif expected_type == dict:
|
1031
1093
|
try:
|
1032
|
-
# Ensure that the value is a string that can be converted to a dictionary
|
1033
1094
|
if isinstance(value, str):
|
1034
|
-
|
1095
|
+
parsed_dict = ast.literal_eval(value)
|
1035
1096
|
else:
|
1036
1097
|
raise ValueError("Expected a string representation of a dictionary.")
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1098
|
+
|
1099
|
+
if not isinstance(parsed_dict, dict):
|
1100
|
+
raise ValueError(f"Expected a dictionary for '{key}', but got {type(parsed_dict).__name__}.")
|
1101
|
+
|
1102
|
+
settings[key] = parsed_dict
|
1041
1103
|
except (ValueError, SyntaxError) as e:
|
1042
1104
|
settings[key] = {}
|
1043
|
-
|
1105
|
+
errors.append(f"Error: Invalid dictionary format for '{key}'. Expected type: dict. Error: {e}")
|
1106
|
+
|
1044
1107
|
elif isinstance(expected_type, tuple):
|
1045
1108
|
for typ in expected_type:
|
1046
1109
|
try:
|
@@ -1049,15 +1112,25 @@ def check_settings(vars_dict, expected_types, q=None):
|
|
1049
1112
|
except (ValueError, TypeError):
|
1050
1113
|
continue
|
1051
1114
|
else:
|
1052
|
-
raise ValueError
|
1115
|
+
raise ValueError(f"Value '{value}' for '{key}' does not match any expected types: {expected_type}.")
|
1116
|
+
|
1053
1117
|
else:
|
1054
|
-
|
1118
|
+
try:
|
1119
|
+
settings[key] = expected_type(value) if value else None
|
1120
|
+
except (ValueError, TypeError):
|
1121
|
+
raise ValueError(f"Expected type {expected_type.__name__} for '{key}', but got '{value}'.")
|
1122
|
+
|
1055
1123
|
except (ValueError, SyntaxError) as e:
|
1056
1124
|
expected_type_name = ' or '.join([t.__name__ for t in expected_type]) if isinstance(expected_type, tuple) else expected_type.__name__
|
1057
|
-
|
1058
|
-
return
|
1125
|
+
errors.append(f"Error: '{key}' has invalid format. Expected type: {expected_type_name}. Got value: '{value}'. Error: {e}")
|
1059
1126
|
|
1060
|
-
|
1127
|
+
# Send all collected errors to the queue
|
1128
|
+
for error in errors:
|
1129
|
+
q.put(error)
|
1130
|
+
|
1131
|
+
|
1132
|
+
|
1133
|
+
return settings, errors
|
1061
1134
|
|
1062
1135
|
def generate_fields(variables, scrollable_frame):
|
1063
1136
|
from .gui_utils import create_input_field
|
@@ -1082,16 +1155,25 @@ def generate_fields(variables, scrollable_frame):
|
|
1082
1155
|
"black_background": "(bool) - Whether to use a black background for plots.",
|
1083
1156
|
"calculate_correlation": "(bool) - Whether to calculate correlations between features.",
|
1084
1157
|
"cell_CP_prob": "(float) - The cellpose probability threshold for the cell channel. This will be used in cell segmentation.",
|
1158
|
+
"nucleus_CP_prob": "(float) - The cellpose probability threshold for the nucleus channel. This will be used in cell segmentation.",
|
1159
|
+
"pathogen_CP_prob": "(float) - The cellpose probability threshold for the pathogen channel. This will be used in cell segmentation.",
|
1085
1160
|
"cell_FT": "(float) - The flow threshold for cell objects. This will be used to segment the cells.",
|
1086
|
-
"
|
1161
|
+
"nucleus_FT": "(float) - The flow threshold for nucleus objects. This will be used to segment the cells.",
|
1162
|
+
"pathogen_FT": "(float) - The flow threshold for pathogen objects. This will be used to segment the cells.",
|
1163
|
+
"cell_background": "(int) - The background intensity for the cell channel. This will be used to remove background noise.",
|
1164
|
+
"nucleus_background": "(int) - The background intensity for the nucleus channel. This will be used to remove background noise.",
|
1165
|
+
"pathogen_background": "(int) - The background intensity for the pathogen channel. This will be used to remove background noise.",
|
1087
1166
|
"cell_chann_dim": "(int) - Dimension of the channel to use for cell segmentation.",
|
1088
|
-
"cell_channel": "(int) - The channel to use for
|
1167
|
+
"cell_channel": "(int) - The channel to use for generatin cell masks. If None, cell masks will not be generated.",
|
1168
|
+
"nucleus_channel": "(int) - The channel to use for generatin nucleus masks. If None, nucleus masks will not be generated.",
|
1169
|
+
"pathogen_channel": "(int) - The channel to use for generatin pathogen masks. If None, pathogen masks will not be generated.",
|
1089
1170
|
"cell_intensity_range": "(list) - Intensity range for cell segmentation.",
|
1090
1171
|
"cell_loc": "(list) - The locations of the cell types in the images.",
|
1091
|
-
"cell_mask_dim": "(int) - The dimension of the array the cell mask is saved in.",
|
1172
|
+
"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.",
|
1173
|
+
"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.",
|
1092
1174
|
"cell_min_size": "(int) - The minimum size of cell objects in pixels^2.",
|
1093
1175
|
"cell_plate_metadata": "(str) - Metadata for the cell plate.",
|
1094
|
-
"cell_Signal_to_noise": "(
|
1176
|
+
"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.",
|
1095
1177
|
"cell_size_range": "(list) - Size range for cell segmentation.",
|
1096
1178
|
"cell_types": "(list) - Types of cells to include in the analysis.",
|
1097
1179
|
"cells": "(list of lists) - The cell types to include in the analysis.",
|
@@ -1106,13 +1188,17 @@ def generate_fields(variables, scrollable_frame):
|
|
1106
1188
|
"col_to_compare": "(str) - Column to compare in the embeddings.",
|
1107
1189
|
"color_by": "(str) - Coloring scheme for the plots.",
|
1108
1190
|
"compartments": "(list) - The compartments to measure in the images.",
|
1191
|
+
"consolidate": "(bool) - Consolidate image files from subfolders into one folder named consolidated.",
|
1109
1192
|
"CP_prob": "(float) - Cellpose probability threshold for segmentation.",
|
1110
1193
|
"crop_mode": "(str) - Mode to use for cropping images (cell, nucleus, pathogen, cytoplasm).",
|
1111
1194
|
"custom_model": "(str) - Path to a custom Cellpose model.",
|
1112
|
-
"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'.",
|
1195
|
+
"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'.",
|
1113
1196
|
"cytoplasm": "(bool) - Whether to segment the cytoplasm (Cell - Nucleus + Pathogen).",
|
1114
1197
|
"cytoplasm_min_size": "(int) - The minimum size of cytoplasm objects in pixels^2.",
|
1198
|
+
"nucleus_min_size": "(int) - The minimum size of nucleus objects in pixels^2.",
|
1199
|
+
"normalize_by": "(str) - Normalize cropped png images by png or by field of view.",
|
1115
1200
|
"dependent_variable": "(str) - The dependent variable for the regression analysis.",
|
1201
|
+
"delete_intermediate": "(bool) - Delete intermediate folders (stack, channel, norm_channel_stack).",
|
1116
1202
|
"diameter": "(float) - Diameter of the objects to segment.",
|
1117
1203
|
"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.",
|
1118
1204
|
"dialate_pngs": "(bool) - Whether to dilate the PNG images before saving.",
|
@@ -1160,7 +1246,7 @@ def generate_fields(variables, scrollable_frame):
|
|
1160
1246
|
"manders_thresholds": "(list) - Thresholds for Manders' coefficients.",
|
1161
1247
|
"mask": "(bool) - Whether to generate masks for the segmented objects. If True, masks will be generated for the nucleus, cell, and pathogen.",
|
1162
1248
|
"measurement": "(str) - The measurement to use for the analysis.",
|
1163
|
-
"metadata_type": "(str) - Type of metadata to expect in the images.
|
1249
|
+
"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.",
|
1164
1250
|
"metadata_types": "(list) - Types of metadata to include in the analysis.",
|
1165
1251
|
"merge_edge_pathogen_cells": "(bool) - Whether to merge cells that share pathogen objects.",
|
1166
1252
|
"merge_pathogens": "(bool) - Whether to merge pathogen objects that share more than 75 percent of their perimeter.",
|
@@ -1180,31 +1266,9 @@ def generate_fields(variables, scrollable_frame):
|
|
1180
1266
|
"n_epochs": "(int) - Number of epochs for training the Cellpose model.",
|
1181
1267
|
"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.",
|
1182
1268
|
"n_neighbors": "(int) - Number of neighbors for UMAP.",
|
1183
|
-
"n_repeats": "(int) - Number of repeats for
|
1184
|
-
"
|
1185
|
-
"
|
1186
|
-
"normalize_plots": "(bool) - Whether to normalize the plots.",
|
1187
|
-
"nr_imgs": "(int) - The number of images to plot.",
|
1188
|
-
"nucleus_CP_prob": "(float) - The cellpose probability threshold for the nucleus channel. This will be used to segment the nucleus.",
|
1189
|
-
"nucleus_FT": "(float) - The flow threshold for nucleus objects. This will be used in nucleus segmentation.",
|
1190
|
-
"nucleus_background": "(float) - The background intensity for the nucleus channel. This will be used to remove background noise.",
|
1191
|
-
"nucleus_chann_dim": "(int) - Dimension of the channel to use for nucleus segmentation.",
|
1192
|
-
"nucleus_channel": "(int) - The channel to use for the nucleus. If None, the nucleus will not be segmented.",
|
1193
|
-
"nucleus_intensity_range": "(list) - Intensity range for nucleus segmentation.",
|
1194
|
-
"nucleus_loc": "(str) - Location of the nucleus in the images.",
|
1195
|
-
"nucleus_mask_dim": "(int) - The dimension of the array the nucleus mask is saved in.",
|
1196
|
-
"nucleus_min_size": "(int) - The minimum size of nucleus objects in pixels^2.",
|
1197
|
-
"nucleus_Signal_to_noise": "(float) - 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.",
|
1198
|
-
"nucleus_size_range": "(list) - Size range for nucleus segmentation.",
|
1199
|
-
"optimizer_type": "(str) - Type of optimizer to use.",
|
1200
|
-
"other": "(dict) - Additional parameters for the regression analysis.",
|
1201
|
-
"pathogen_CP_prob": "(float) - The cellpose probability threshold for the pathogen channel. This will be used to segment the pathogen.",
|
1202
|
-
"pathogen_FT": "(float) - The flow threshold for pathogen objects. This will be used in pathogen segmentation.",
|
1203
|
-
"pathogen_background": "(float) - The background intensity for the pathogen channel. This will be used to remove background noise.",
|
1204
|
-
"pathogen_chann_dim": "(int) - Dimension of the channel to use for pathogen segmentation.",
|
1205
|
-
"pathogen_channel": "(int) - The channel to use for the pathogen. If None, the pathogen will not be segmented.",
|
1206
|
-
"pathogen_intensity_range": "(str) - Metadata for the pathogen plate.",
|
1207
|
-
"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.",
|
1269
|
+
"n_repeats": "(int) - Number of repeats for the pathogen plate.",
|
1270
|
+
"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.",
|
1271
|
+
"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.",
|
1208
1272
|
"pathogen_size_range": "(list) - Size range for pathogen segmentation.",
|
1209
1273
|
"pathogen_types": "(list) - Types of pathogens to include in the analysis.",
|
1210
1274
|
"pc": "(str) - Positive control identifier.",
|
@@ -1222,7 +1286,7 @@ def generate_fields(variables, scrollable_frame):
|
|
1222
1286
|
"plot_nr": "(int) - Number of plots to generate.",
|
1223
1287
|
"plot_outlines": "(bool) - Whether to plot outlines of segmented objects.",
|
1224
1288
|
"png_dims": "(list) - The dimensions of the PNG images to save. This will determine the dimensions of the saved images. Maximum of 3 dimensions e.g. [1,2,3].",
|
1225
|
-
"png_size": "(
|
1289
|
+
"png_size": "(list) - The size of the PNG images to save. This will determine the size of the saved images.",
|
1226
1290
|
"positive_control": "(str) - Identifier for the positive control.",
|
1227
1291
|
"preprocess": "(bool) - Whether to preprocess the images before segmentation. This includes background removal and normalization. Set to False only if this step has already been done.",
|
1228
1292
|
"radial_dist": "(list) - Radial distances for measuring features.",
|
@@ -1251,10 +1315,11 @@ def generate_fields(variables, scrollable_frame):
|
|
1251
1315
|
"save_measurements": "(bool) - Whether to save the measurements to disk.",
|
1252
1316
|
"save_png": "(bool) - Whether to save the segmented objects as PNG images.",
|
1253
1317
|
"schedule": "(str) - Schedule for processing the data.",
|
1254
|
-
"Signal_to_noise": "(
|
1318
|
+
"Signal_to_noise": "(int) - Signal-to-noise ratio for the images.",
|
1255
1319
|
"skip_mode": "(str) - The mode to use for skipping images. This will determine how to handle images that cannot be processed.",
|
1256
1320
|
"smooth_lines": "(bool) - Whether to smooth lines in the plots.",
|
1257
1321
|
"src": "(str, path) - Path to source directory.",
|
1322
|
+
"segmentation_mode": "(str) - Algorithm to use for segmentation (cellpose or mediar).",
|
1258
1323
|
"target": "(str) - Target variable for the analysis.",
|
1259
1324
|
"target_height": "(int) - Target height for resizing the images.",
|
1260
1325
|
"target_intensity_min": "(float) - Minimum intensity for the target objects.",
|
@@ -1304,7 +1369,7 @@ def generate_fields(variables, scrollable_frame):
|
|
1304
1369
|
"masks": "(bool) - Whether to generate masks for the segmented objects.",
|
1305
1370
|
"timelapse": "(bool) - Whether to analyze images as a timelapse.",
|
1306
1371
|
"pathogen_min_size": "(int) - The minimum size of pathogen objects in pixels^2.",
|
1307
|
-
"pathogen_mask_dim": "(int) - The dimension of the array the pathogen mask is saved in.",
|
1372
|
+
"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.",
|
1308
1373
|
"use_bounding_box": "(bool) - Whether to use the bounding box for cropping the images.",
|
1309
1374
|
"plot_points": "(bool) - Whether to plot scatterplot points.",
|
1310
1375
|
"embedding_by_controls": "(bool) - Use the controlls to greate the embedding, then apply this embedding to all of the data.",
|
@@ -1334,6 +1399,7 @@ def generate_fields(variables, scrollable_frame):
|
|
1334
1399
|
"shuffle": "(bool) - Shuffle the dataset bufore generating the activation maps",
|
1335
1400
|
"correlation": "(bool) - Calculate correlation between image channels and activation maps. Data is saved to .db.",
|
1336
1401
|
"normalize_input": "(bool) - Normalize the input images before passing them to the model.",
|
1402
|
+
"normalize_plots": "(bool) - Normalize images before plotting.",
|
1337
1403
|
}
|
1338
1404
|
|
1339
1405
|
for key, (var_type, options, default_value) in variables.items():
|
@@ -1385,8 +1451,8 @@ def set_annotate_default_settings(settings):
|
|
1385
1451
|
settings.setdefault('normalize', 'False')
|
1386
1452
|
settings.setdefault('normalize_channels', "r,g,b")
|
1387
1453
|
settings.setdefault('percentiles', [2, 98])
|
1388
|
-
settings.setdefault('measurement', '')#'cytoplasm_channel_3_mean_intensity,pathogen_channel_3_mean_intensity')
|
1389
|
-
settings.setdefault('threshold', '')#'2')
|
1454
|
+
settings.setdefault('measurement', '') #'cytoplasm_channel_3_mean_intensity,pathogen_channel_3_mean_intensity')
|
1455
|
+
settings.setdefault('threshold', '') #'2')
|
1390
1456
|
return settings
|
1391
1457
|
|
1392
1458
|
def set_default_generate_barecode_mapping(settings={}):
|
@@ -1406,6 +1472,7 @@ def set_default_generate_barecode_mapping(settings={}):
|
|
1406
1472
|
settings.setdefault('mode', 'paired')
|
1407
1473
|
settings.setdefault('single_direction', 'R1')
|
1408
1474
|
settings.setdefault('test', False)
|
1475
|
+
settings.setdefault('fill_na', False)
|
1409
1476
|
return settings
|
1410
1477
|
|
1411
1478
|
def get_default_generate_activation_map_settings(settings):
|