spacr 0.1.1__py3-none-any.whl → 0.1.7__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/settings.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
1
+ import os, ast
2
2
 
3
3
  def set_default_plot_merge_settings():
4
4
  settings = {}
@@ -27,7 +27,13 @@ def set_default_plot_merge_settings():
27
27
 
28
28
  def set_default_settings_preprocess_generate_masks(src, settings={}):
29
29
  # Main settings
30
- settings['src'] = src
30
+ if src != None:
31
+ settings['src'] = src
32
+ else:
33
+ settings.setdefault('src', 'path')
34
+ if 'src' not in settings:
35
+ settings['src'] = 'path'
36
+
31
37
  settings.setdefault('preprocess', True)
32
38
  settings.setdefault('masks', True)
33
39
  settings.setdefault('save', True)
@@ -37,7 +43,7 @@ def set_default_settings_preprocess_generate_masks(src, settings={}):
37
43
  settings.setdefault('magnification', 20)
38
44
  settings.setdefault('custom_regex', None)
39
45
  settings.setdefault('metadata_type', 'cellvoyager')
40
- settings.setdefault('workers', os.cpu_count()-4)
46
+ settings.setdefault('n_job', os.cpu_count()-4)
41
47
  settings.setdefault('randomize', True)
42
48
  settings.setdefault('verbose', True)
43
49
  settings.setdefault('remove_background_cell', False)
@@ -162,9 +168,9 @@ def _get_object_settings(object_type, settings):
162
168
  if settings['verbose']:
163
169
  print(object_settings)
164
170
 
165
- return object_settings
171
+ return object_settings
166
172
 
167
- def get_umap_image_settings(settings={}):
173
+ def set_default_umap_image_settings(settings={}):
168
174
  settings.setdefault('src', 'path')
169
175
  settings.setdefault('row_limit', 1000)
170
176
  settings.setdefault('tables', ['cell', 'cytoplasm', 'nucleus', 'pathogen'])
@@ -212,9 +218,13 @@ def get_umap_image_settings(settings={}):
212
218
 
213
219
  def get_measure_crop_settings(settings):
214
220
 
221
+ settings.setdefault('src', 'path')
222
+ settings.setdefault('verbose', False)
223
+
215
224
  # Test mode
216
225
  settings.setdefault('test_mode', False)
217
226
  settings.setdefault('test_nr', 10)
227
+ settings.setdefault('channels', [0,1,2,3])
218
228
 
219
229
  #measurement settings
220
230
  settings.setdefault('save_measurements',True)
@@ -244,7 +254,7 @@ def get_measure_crop_settings(settings):
244
254
  settings.setdefault('plot',False)
245
255
  settings.setdefault('plot_filtration',False)
246
256
  settings.setdefault('representative_images', False)
247
- settings.setdefault('max_workers', os.cpu_count()-2)
257
+ settings.setdefault('n_job', os.cpu_count()-2)
248
258
 
249
259
  # Object settings
250
260
  settings.setdefault('cell_mask_dim',None)
@@ -260,7 +270,7 @@ def get_measure_crop_settings(settings):
260
270
 
261
271
  # Miscellaneous settings
262
272
  settings.setdefault('experiment', 'exp')
263
- settings.setdefault('cells', 'HeLa')
273
+ settings.setdefault('cells', ['HeLa'])
264
274
  settings.setdefault('cell_loc', None)
265
275
  settings.setdefault('pathogens', ['ME49Dku80WT', 'ME49Dku80dgra8:GRA8', 'ME49Dku80dgra8', 'ME49Dku80TKO'])
266
276
  settings.setdefault('pathogen_loc', [['c1', 'c2', 'c3', 'c4', 'c5', 'c6'], ['c7', 'c8', 'c9', 'c10', 'c11', 'c12'], ['c13', 'c14', 'c15', 'c16', 'c17', 'c18'], ['c19', 'c20', 'c21', 'c22', 'c23', 'c24']])
@@ -273,6 +283,7 @@ def get_measure_crop_settings(settings):
273
283
  settings.setdefault('um_per_pixel', 0.1)
274
284
 
275
285
  if settings['test_mode']:
286
+ settings['verbose'] = True
276
287
  settings['plot'] = True
277
288
  settings['plot_filtration'] = True
278
289
  test_imgs = settings['test_nr']
@@ -304,6 +315,8 @@ def set_default_analyze_screen(settings):
304
315
 
305
316
  def set_default_train_test_model(settings):
306
317
  cores = os.cpu_count()-2
318
+
319
+ settings.setdefault('src','path')
307
320
  settings.setdefault('train',True)
308
321
  settings.setdefault('test',False)
309
322
  settings.setdefault('classes',['nc','pc'])
@@ -327,7 +340,7 @@ def set_default_train_test_model(settings):
327
340
  settings.setdefault('gradient_accumulation_steps',4)
328
341
  settings.setdefault('intermedeate_save',True)
329
342
  settings.setdefault('pin_memory',True)
330
- settings.setdefault('num_workers',cores)
343
+ settings.setdefault('n_job',cores)
331
344
  settings.setdefault('channels',['r','g','b'])
332
345
  settings.setdefault('augment',False)
333
346
  settings.setdefault('verbose',False)
@@ -474,4 +487,484 @@ def get_identify_masks_finetune_default_settings(settings):
474
487
  settings.setdefault('rescale', False)
475
488
  settings.setdefault('resample', False)
476
489
  settings.setdefault('grayscale', True)
477
- return settings
490
+ return settings
491
+
492
+ q = None
493
+ expected_types = {
494
+ "src": str,
495
+ "metadata_type": str,
496
+ "custom_regex": (str, type(None)),
497
+ "experiment": str,
498
+ "channels": list,
499
+ "magnification": int,
500
+ "nucleus_channel": (int, type(None)),
501
+ "nucleus_background": int,
502
+ "nucleus_Signal_to_noise": float,
503
+ "nucleus_CP_prob": float,
504
+ "nucleus_FT": float,
505
+ "cell_channel": (int, type(None)),
506
+ "cell_background": (int, float),
507
+ "cell_Signal_to_noise": (int, float),
508
+ "cell_CP_prob": (int, float),
509
+ "cell_FT": (int, float),
510
+ "pathogen_channel": (int, type(None)),
511
+ "pathogen_background": (int, float),
512
+ "pathogen_Signal_to_noise": (int, float),
513
+ "pathogen_CP_prob": (int, float),
514
+ "pathogen_FT": (int, float),
515
+ "preprocess": bool,
516
+ "masks": bool,
517
+ "examples_to_plot": int,
518
+ "randomize": bool,
519
+ "batch_size": int,
520
+ "timelapse": bool,
521
+ "timelapse_displacement": int,
522
+ "timelapse_memory": int,
523
+ "timelapse_frame_limits": list, # This can be a list of lists
524
+ "timelapse_remove_transient": bool,
525
+ "timelapse_mode": str,
526
+ "timelapse_objects": list,
527
+ "fps": int,
528
+ "remove_background": bool,
529
+ "lower_percentile": (int, float),
530
+ "merge_pathogens": bool,
531
+ "normalize_plots": bool,
532
+ "all_to_mip": bool,
533
+ "pick_slice": bool,
534
+ "skip_mode": str,
535
+ "save": bool,
536
+ "plot": bool,
537
+ "n_job": int,
538
+ "verbose": bool,
539
+ "input_folder": str,
540
+ "cell_mask_dim": int,
541
+ "cell_min_size": int,
542
+ "cytoplasm_min_size": int,
543
+ "nucleus_mask_dim": int,
544
+ "nucleus_min_size": int,
545
+ "pathogen_mask_dim": int,
546
+ "pathogen_min_size": int,
547
+ "save_png": bool,
548
+ "crop_mode": list,
549
+ "use_bounding_box": bool,
550
+ "png_size": list, # This can be a list of lists
551
+ "normalize": bool,
552
+ "png_dims": list,
553
+ "normalize_by": str,
554
+ "save_measurements": bool,
555
+ "representative_images": bool,
556
+ "plot_filtration": bool,
557
+ "include_uninfected": bool,
558
+ "dialate_pngs": bool,
559
+ "dialate_png_ratios": list,
560
+ "n_job": int,
561
+ "cells": list,
562
+ "cell_loc": list,
563
+ "pathogens": list,
564
+ "pathogen_loc": (list, list), # This can be a list of lists
565
+ "treatments": list,
566
+ "treatment_loc": (list, list), # This can be a list of lists
567
+ "channel_of_interest": int,
568
+ "compartments": list,
569
+ "measurement": str,
570
+ "nr_imgs": int,
571
+ "um_per_pixel": (int, float),
572
+ # Additional settings based on provided defaults
573
+ "include_noninfected": bool,
574
+ "include_multiinfected": bool,
575
+ "include_multinucleated": bool,
576
+ "filter_min_max": (list, type(None)),
577
+ "channel_dims": list,
578
+ "backgrounds": list,
579
+ "outline_thickness": int,
580
+ "outline_color": str,
581
+ "overlay_chans": list,
582
+ "overlay": bool,
583
+ "normalization_percentiles": list,
584
+ "print_object_number": bool,
585
+ "nr": int,
586
+ "figuresize": int,
587
+ "cmap": str,
588
+ "test_mode": bool,
589
+ "test_images": int,
590
+ "remove_background_cell": bool,
591
+ "remove_background_nucleus": bool,
592
+ "remove_background_pathogen": bool,
593
+ "pathogen_model": (str, type(None)),
594
+ "filter": bool,
595
+ "upscale": bool,
596
+ "upscale_factor": float,
597
+ "adjust_cells": bool,
598
+ "row_limit": int,
599
+ "tables": list,
600
+ "visualize": str,
601
+ "image_nr": int,
602
+ "dot_size": int,
603
+ "n_neighbors": int,
604
+ "min_dist": float,
605
+ "metric": str,
606
+ "eps": float,
607
+ "min_samples": int,
608
+ "filter_by": str,
609
+ "img_zoom": float,
610
+ "plot_by_cluster": bool,
611
+ "plot_cluster_grids": bool,
612
+ "remove_cluster_noise": bool,
613
+ "remove_highly_correlated": bool,
614
+ "log_data": bool,
615
+ "black_background": bool,
616
+ "remove_image_canvas": bool,
617
+ "plot_outlines": bool,
618
+ "plot_points": bool,
619
+ "smooth_lines": bool,
620
+ "clustering": str,
621
+ "exclude": (str, type(None)),
622
+ "col_to_compare": str,
623
+ "pos": str,
624
+ "neg": str,
625
+ "embedding_by_controls": bool,
626
+ "plot_images": bool,
627
+ "reduction_method": str,
628
+ "save_figure": bool,
629
+ "color_by": (str, type(None)),
630
+ "analyze_clusters": bool,
631
+ "resnet_features": bool,
632
+ "test_nr": int,
633
+ "radial_dist": bool,
634
+ "calculate_correlation": bool,
635
+ "manders_thresholds": list,
636
+ "homogeneity": bool,
637
+ "homogeneity_distances": list,
638
+ "save_arrays": bool,
639
+ "cytoplasm": bool,
640
+ "merge_edge_pathogen_cells": bool,
641
+ "cells_per_well": int,
642
+ "pathogen_size_range": list,
643
+ "nucleus_size_range": list,
644
+ "cell_size_range": list,
645
+ "pathogen_intensity_range": list,
646
+ "nucleus_intensity_range": list,
647
+ "cell_intensity_range": list,
648
+ "target_intensity_min": int,
649
+ "model_type": str,
650
+ "heatmap_feature": str,
651
+ "grouping": str,
652
+ "min_max": str,
653
+ "minimum_cell_count": int,
654
+ "n_estimators": int,
655
+ "test_size": float,
656
+ "location_column": str,
657
+ "positive_control": str,
658
+ "negative_control": str,
659
+ "n_repeats": int,
660
+ "top_features": int,
661
+ "remove_low_variance_features": bool,
662
+ "n_jobs": int,
663
+ "classes": list,
664
+ "schedule": str,
665
+ "loss_type": str,
666
+ "image_size": int,
667
+ "epochs": int,
668
+ "val_split": float,
669
+ "train_mode": str,
670
+ "learning_rate": float,
671
+ "weight_decay": float,
672
+ "dropout_rate": float,
673
+ "init_weights": bool,
674
+ "amsgrad": bool,
675
+ "use_checkpoint": bool,
676
+ "gradient_accumulation": bool,
677
+ "gradient_accumulation_steps": int,
678
+ "intermedeate_save": bool,
679
+ "pin_memory": bool,
680
+ "n_job": int,
681
+ "augment": bool,
682
+ "target": str,
683
+ "cell_types": list,
684
+ "cell_plate_metadata": (list, type(None)),
685
+ "pathogen_types": list,
686
+ "pathogen_plate_metadata": (list, list), # This can be a list of lists
687
+ "treatment_plate_metadata": (list, list), # This can be a list of lists
688
+ "metadata_types": list,
689
+ "cell_chann_dim": int,
690
+ "nucleus_chann_dim": int,
691
+ "pathogen_chann_dim": int,
692
+ "plot_nr": int,
693
+ "plot_control": bool,
694
+ "remove_background": bool,
695
+ "target": str,
696
+ "upstream": str,
697
+ "downstream": str,
698
+ "barecode_length_1": int,
699
+ "barecode_length_2": int,
700
+ "chunk_size": int,
701
+ "grna": str,
702
+ "barcodes": str,
703
+ "plate_dict": dict,
704
+ "pc": str,
705
+ "pc_loc": str,
706
+ "nc": str,
707
+ "nc_loc": str,
708
+ "dependent_variable": str,
709
+ "transform": (str, type(None)),
710
+ "agg_type": str,
711
+ "min_cell_count": int,
712
+ "regression_type": str,
713
+ "remove_row_column_effect": bool,
714
+ "alpha": float,
715
+ "fraction_threshold": float,
716
+ "class_1_threshold": (float, type(None)),
717
+ "batch_size": int,
718
+ "CP_prob": float,
719
+ "flow_threshold": float,
720
+ "percentiles": (list, type(None)),
721
+ "circular": bool,
722
+ "invert": bool,
723
+ "diameter": int,
724
+ "grayscale": bool,
725
+ "resize": bool,
726
+ "target_height": (int, type(None)),
727
+ "target_width": (int, type(None)),
728
+ "rescale": bool,
729
+ "resample": bool,
730
+ "model_name": str,
731
+ "Signal_to_noise": int,
732
+ "learning_rate": float,
733
+ "weight_decay": float,
734
+ "batch_size": int,
735
+ "n_epochs": int,
736
+ "from_scratch": bool,
737
+ "width_height": list,
738
+ "resize": bool,
739
+ "gene_weights_csv": str,
740
+ "fraction_threshold": float,
741
+ }
742
+
743
+ def check_settings_v1(vars_dict, expected_types,q=None):
744
+ from .gui_utils import parse_list
745
+ settings = {}
746
+ # Define the expected types for each key, including None where applicable
747
+
748
+ for key, (label, widget, var) in vars_dict.items():
749
+ if key not in expected_types:
750
+ if key not in ["General","Nucleus","Cell","Pathogen","Timelapse","Plot","Object Image","Annotate Data","Measurements","Advanced","Miscellaneous","Test"]:
751
+ q.put(f"Key {key} not found in expected types.")
752
+ continue
753
+
754
+ value = var.get()
755
+ expected_type = expected_types.get(key, str)
756
+
757
+ try:
758
+ if key in ["png_size", "pathogen_plate_metadata", "treatment_plate_metadata"]:
759
+ parsed_value = ast.literal_eval(value) if value else None
760
+ if isinstance(parsed_value, list):
761
+ if all(isinstance(i, list) for i in parsed_value) or all(not isinstance(i, list) for i in parsed_value):
762
+ settings[key] = parsed_value
763
+ else:
764
+ raise ValueError("Invalid format: Mixed list and list of lists")
765
+ else:
766
+ raise ValueError("Invalid format for list or list of lists")
767
+ elif expected_type == list:
768
+ settings[key] = parse_list(value) if value else None
769
+ elif expected_type == bool:
770
+ settings[key] = value if isinstance(value, bool) else value.lower() in ['true', '1', 't', 'y', 'yes']
771
+ elif expected_type == (int, type(None)):
772
+ settings[key] = int(value) if value else None
773
+ elif expected_type == (float, type(None)):
774
+ settings[key] = float(value) if value else None
775
+ elif expected_type == (int, float):
776
+ settings[key] = float(value) if '.' in value else int(value)
777
+ elif expected_type == (str, type(None)):
778
+ settings[key] = str(value) if value else None
779
+ elif isinstance(expected_type, tuple):
780
+ for typ in expected_type:
781
+ try:
782
+ settings[key] = typ(value) if value else None
783
+ break
784
+ except (ValueError, TypeError):
785
+ continue
786
+ else:
787
+ raise ValueError
788
+ else:
789
+ settings[key] = expected_type(value) if value else None
790
+ except (ValueError, SyntaxError):
791
+ expected_type_name = ' or '.join([t.__name__ for t in expected_type]) if isinstance(expected_type, tuple) else expected_type.__name__
792
+ q.put(f"Error: Invalid format for {key}. Expected type: {expected_type_name}.")
793
+ return
794
+
795
+ return settings
796
+
797
+ def check_settings(vars_dict, expected_types, q=None):
798
+ from .gui_utils import parse_list
799
+
800
+ if q is None:
801
+ from multiprocessing import Queue
802
+ q = Queue()
803
+
804
+ settings = {}
805
+
806
+ for key, (label, widget, var) in vars_dict.items():
807
+ if key not in expected_types:
808
+ if key not in ["General", "Nucleus", "Cell", "Pathogen", "Timelapse", "Plot", "Object Image", "Annotate Data", "Measurements", "Advanced", "Miscellaneous", "Test"]:
809
+ q.put(f"Key {key} not found in expected types.")
810
+ continue
811
+
812
+ value = var.get()
813
+ expected_type = expected_types.get(key, str)
814
+
815
+ try:
816
+ if key in ["png_size", "pathogen_plate_metadata", "treatment_plate_metadata"]:
817
+ parsed_value = ast.literal_eval(value) if value else None
818
+ if isinstance(parsed_value, list):
819
+ if all(isinstance(i, list) for i in parsed_value) or all(not isinstance(i, list) for i in parsed_value):
820
+ settings[key] = parsed_value
821
+ else:
822
+ raise ValueError("Invalid format: Mixed list and list of lists")
823
+ else:
824
+ raise ValueError("Invalid format for list or list of lists")
825
+ elif expected_type == list:
826
+ settings[key] = parse_list(value) if value else None
827
+ elif expected_type == bool:
828
+ settings[key] = value if isinstance(value, bool) else value.lower() in ['true', '1', 't', 'y', 'yes']
829
+ elif expected_type == (int, type(None)):
830
+ settings[key] = int(value) if value else None
831
+ elif expected_type == (float, type(None)):
832
+ settings[key] = float(value) if value else None
833
+ elif expected_type == (int, float):
834
+ settings[key] = float(value) if '.' in value else int(value)
835
+ elif expected_type == (str, type(None)):
836
+ settings[key] = str(value) if value else None
837
+ elif isinstance(expected_type, tuple):
838
+ for typ in expected_type:
839
+ try:
840
+ settings[key] = typ(value) if value else None
841
+ break
842
+ except (ValueError, TypeError):
843
+ continue
844
+ else:
845
+ raise ValueError
846
+ else:
847
+ settings[key] = expected_type(value) if value else None
848
+ except (ValueError, SyntaxError) as e:
849
+ expected_type_name = ' or '.join([t.__name__ for t in expected_type]) if isinstance(expected_type, tuple) else expected_type.__name__
850
+ q.put(f"Error: Invalid format for {key}. Expected type: {expected_type_name}. Error: {e}")
851
+ return
852
+
853
+ return settings
854
+
855
+ def generate_fields(variables, scrollable_frame):
856
+ from .gui_utils import create_input_field
857
+ from .gui_elements import spacrToolTip
858
+ row = 1
859
+ vars_dict = {}
860
+ tooltips = {
861
+ "src": "Path to the folder containing the images.",
862
+ "metadata_type": "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.",
863
+ "custom_regex": "Custom regex pattern to extract metadata from the image names. This will only be used if 'custom' is selected for 'metadata_type'.",
864
+ "experiment": "Name of the experiment. This will be used to name the output files.",
865
+ "channels": "List of channels to use for the analysis. The first channel is 0, the second is 1, and so on. For example, [0,1,2] will use channels 0, 1, and 2.",
866
+ "magnification": "At what magnification the images were taken. This will be used to determine the size of the objects in the images.",
867
+ "nucleus_channel": "The channel to use for the nucleus. If None, the nucleus will not be segmented.",
868
+ "nucleus_background": "The background intensity for the nucleus channel. This will be used to remove background noise.",
869
+ "nucleus_Signal_to_noise": "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.",
870
+ "nucleus_CP_prob": "The cellpose probability threshold for the nucleus channel. This will be used to segment the nucleus.",
871
+ "nucleus_FT": "The flow threshold for nucleus objects. This will be used in nuclues segmentation.",
872
+ "cell_channel": "The channel to use for the cell. If None, the cell will not be segmented.",
873
+ "cell_background": "The background intensity for the cell channel. This will be used to remove background noise.",
874
+ "cell_Signal_to_noise": "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.",
875
+ "cell_CP_prob": "The cellpose probability threshold for the cell channel. This will be used in cell segmentation.",
876
+ "cell_FT": "The flow threshold for cell objects. This will be used to segment the cells.",
877
+ "pathogen_channel": "The channel to use for the pathogen. If None, the pathogen will not be segmented.",
878
+ "pathogen_background": "The background intensity for the pathogen channel. This will be used to remove background noise.",
879
+ "pathogen_Signal_to_noise": "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.",
880
+ "pathogen_CP_prob": "The cellpose probability threshold for the pathogen channel. This will be used to segment the pathogen.",
881
+ "pathogen_FT": "The flow threshold for pathogen objects. This will be used in pathogen segmentation.",
882
+ "preprocess": "Whether to preprocess the images before segmentation. This includes background removal and normalization. Set to False only if this step has already been done.",
883
+ "masks": "Whether to generate masks for the segmented objects. If True, masks will be generated for the nucleus, cell, and pathogen.",
884
+ "examples_to_plot": "The number of images to plot for each segmented object. This will be used to visually inspect the segmentation results and normalization.",
885
+ "randomize": "Whether to randomize the order of the images before processing. Recommended to avoid bias in the segmentation.",
886
+ "batch_size": "The batch size to use for processing the images. This will determine how many images are processed at once. Images are normalized and segmented in batches. Lower if application runs out of RAM or VRAM.",
887
+ "timelapse": "Whether to process the images as a timelapse.",
888
+ "timelapse_displacement": "The displacement between frames in the timelapse. This will be used to align the frames before processing.",
889
+ "timelapse_memory": "The number of frames to in tandem objects must be present in to be considered the same object in the timelapse.",
890
+ "timelapse_frame_limits": "The frame limits to use for the timelapse. This will determine which frames are processed. For example, [5,20] will process frames 5 to 20.",
891
+ "timelapse_remove_transient": "Whether to remove transient objects in the timelapse. Transient objects are present in fewer than all frames.",
892
+ "timelapse_mode": "The mode to use for processing the timelapse. 'trackpy' uses the trackpy library for tracking objects, while 'btrack' uses the btrack library.",
893
+ "timelapse_objects": "The objects to track in the timelapse (cell, nucleus or pathogen). This will determine which objects are tracked over time. If None, all objects will be tracked.",
894
+ "fps": "Frames per second of the automatically generated timelapse movies.",
895
+ "remove_background": "Whether to remove background noise from the images. This will help improve the quality of the segmentation.",
896
+ "lower_percentile": "The lower quantile to use for normalizing the images. This will be used to determine the range of intensities to normalize images to.",
897
+ "merge_pathogens": "Whether to merge pathogen objects that share more than 75% of their perimeter.",
898
+ "normalize_plots": "Whether to normalize the plots.",
899
+ "all_to_mip": "Whether to convert all images to maximum intensity projections before processing.",
900
+ "pick_slice": "Whether to pick a single slice from the z-stack images. If False, the maximum intensity projection will be used.",
901
+ "skip_mode": "The mode to use for skipping images. This will determine how to handle images that cannot be processed.",
902
+ "save": "Whether to save the results to disk.",
903
+ "merge_edge_pathogen_cells": "Whether to merge cells that share pathogen objects.",
904
+ "plot": "Whether to plot the results.",
905
+ "n_job": "The number of n_job to use for processing the images. This will determine how many images are processed in parallel. Increase to speed up processing.",
906
+ "verbose": "Whether to print verbose output during processing.",
907
+ "input_folder": "Path to the folder containing the images.",
908
+ "cell_mask_dim": "The dimension of the array the cell mask is saved in.",
909
+ "cell_min_size": "The minimum size of cell objects in pixels^2.",
910
+ "cytoplasm": "Whether to segment the cytoplasm (Cell - Nucleus + Pathogen).",
911
+ "cytoplasm_min_size": "The minimum size of cytoplasm objects in pixels^2.",
912
+ "nucleus_mask_dim": "The dimension of the array the nucleus mask is saved in.",
913
+ "nucleus_min_size": "The minimum size of nucleus objects in pixels^2.",
914
+ "pathogen_mask_dim": "The dimension of the array the pathogen mask is saved in.",
915
+ "pathogen_min_size": "The minimum size of pathogen objects in pixels^2.",
916
+ "save_png": "Whether to save the segmented objects as PNG images.",
917
+ "crop_mode": "The mode to use for cropping the images. This will determine which objects are cropped from the images (cell, nucleus, pathogen, cytoplasm).",
918
+ "use_bounding_box": "Whether to use the bounding box of the objects for cropping. If False, only the object itself will be cropped.",
919
+ "png_size": "The size of the PNG images to save. This will determine the size of the saved images.",
920
+ "normalize": "The percentiles to use for normalizing the images. This will be used to determine the range of intensities to normalize images to. If None, no normalization is done.",
921
+ "png_dims": "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].",
922
+ "normalize_by": "Whether to normalize the images by field of view (fov) or by PNG image (png).",
923
+ "save_measurements": "Whether to save the measurements to disk.",
924
+ "representative_images": "Whether to save representative images of the segmented objects (Not working yet).",
925
+ "plot_filtration": "Whether to plot the filtration steps.",
926
+ "include_uninfected": "Whether to include uninfected cells in the analysis.",
927
+ "dialate_pngs": "Whether to dilate the PNG images before saving.",
928
+ "dialate_png_ratios": "The ratios to use for dilating the PNG images. This will determine the amount of dilation applied to the images before cropping.",
929
+ "n_job": "The number of n_job to use for processing the images. This will determine how many images are processed in parallel. Increase to speed up processing.",
930
+ "cells": "The cell types to include in the analysis.",
931
+ "cell_loc": "The locations of the cell types in the images.",
932
+ "pathogens": "The pathogen types to include in the analysis.",
933
+ "pathogen_loc": "The locations of the pathogen types in the images.",
934
+ "treatments": "The treatments to include in the analysis.",
935
+ "treatment_loc": "The locations of the treatments in the images.",
936
+ "channel_of_interest": "The channel of interest to use for the analysis.",
937
+ "compartments": "The compartments to measure in the images.",
938
+ "measurement": "The measurement to use for the analysis.",
939
+ "nr_imgs": "The number of images to plot.",
940
+ "um_per_pixel": "The micrometers per pixel for the images."
941
+ }
942
+
943
+ for key, (var_type, options, default_value) in variables.items():
944
+ label, widget, var = create_input_field(scrollable_frame.scrollable_frame, key, row, var_type, options, default_value)
945
+ vars_dict[key] = (label, widget, var) # Store the label, widget, and variable
946
+
947
+ # Add tooltip to the label if it exists in the tooltips dictionary
948
+ if key in tooltips:
949
+ spacrToolTip(label, tooltips[key])
950
+ row += 1
951
+ return vars_dict
952
+
953
+ categories = {
954
+ "General": ["src", "input_folder", "metadata_type", "custom_regex", "experiment", "channels", "magnification"],
955
+ "Nucleus": ["nucleus_channel", "nucleus_background", "nucleus_Signal_to_noise", "nucleus_CP_prob", "nucleus_FT", "remove_background_nucleus", "nucleus_min_size", "nucleus_mask_dim", "nucleus_loc"],
956
+ "Cell": ["cell_channel", "cell_background", "cell_Signal_to_noise", "cell_CP_prob", "cell_FT", "remove_background_cell", "cell_min_size", "cell_mask_dim", "cytoplasm", "cytoplasm_min_size", "include_uninfected", "merge_edge_pathogen_cells", "adjust_cells"],
957
+ "Pathogen": ["pathogen_channel", "pathogen_background", "pathogen_Signal_to_noise", "pathogen_CP_prob", "pathogen_FT", "pathogen_model", "remove_background_pathogen", "pathogen_min_size", "pathogen_mask_dim"],
958
+ "Timelapse": ["fps", "timelapse_displacement", "timelapse_memory", "timelapse_frame_limits", "timelapse_remove_transient", "timelapse_mode", "timelapse_objects", "compartments"],
959
+ "Plot": ["plot_filtration", "examples_to_plot", "normalize_plots", "normalize", "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"],
960
+ "Object Image": ["save_png", "dialate_pngs", "dialate_png_ratios", "png_size", "png_dims", "save_arrays", "normalize_by", "dialate_png_ratios", "crop_mode", "dialate_pngs", "normalize", "use_bounding_box"],
961
+ "Annotate Data": ["positive_control","negative_control", "location_column", "treatment_loc", "cells", "cell_loc", "pathogens", "pathogen_loc", "channel_of_interest", "measurement", "treatments", "representative_images", "um_per_pixel", "nr_imgs", "exclude", "exclude_conditions", "mix", "pos", "neg"],
962
+ "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"],
963
+ "Advanced": ["plot", "timelapse", "schedule", "test_size","exclude","n_repeats","top_features", "model_type","minimum_cell_count","n_estimators","preprocess", "remove_background", "normalize", "lower_percentile", "merge_pathogens", "batch_size", "filter", "save", "masks", "verbose", "randomize", "n_job", "train_mode","amsgrad","use_checkpoint","gradient_accumulation","gradient_accumulation_steps","intermedeate_save","pin_memory","n_job","channels","augment"],
964
+ "Clustering": ["eps","min_samples","analyze_clusters","clustering","remove_cluster_noise"],
965
+ "Embedding": ["visualize","n_neighbors","min_dist","metric","resnet_features","reduction_method","embedding_by_controls","col_to_compare","log_data"],
966
+ "Train DL Model": ["epochs", "loss_type", "optimizer_type","image_size","val_split","learning_rate","weight_decay","dropout_rate","init_weights", "train", "classes"],
967
+ "Miscellaneous": ["all_to_mip", "pick_slice", "skip_mode", "upscale", "upscale_factor"],
968
+ "Test": ["test_mode", "test_images", "random_test", "test_nr"],
969
+ "Sequencing": ["upstream", "downstream", "barecode_length_1", "barecode_length_2", "chunk_size", "test"]
970
+ }
spacr/sim_app.py ADDED
File without changes