spacr 0.1.50__py3-none-any.whl → 0.1.61__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/__init__.py +8 -2
- spacr/app_annotate.py +3 -3
- spacr/app_make_masks.py +3 -6
- spacr/app_make_masks_v2.py +4 -4
- spacr/app_sequencing.py +8 -0
- spacr/app_umap.py +8 -0
- spacr/core.py +9 -7
- spacr/gui.py +12 -6
- spacr/gui_core.py +608 -0
- spacr/gui_elements.py +322 -0
- spacr/gui_run.py +58 -0
- spacr/gui_utils.py +21 -1407
- spacr/gui_wrappers.py +137 -0
- spacr/measure.py +6 -8
- spacr/plot.py +53 -1
- spacr/sequencing.py +1 -17
- spacr/settings.py +428 -4
- spacr/utils.py +19 -11
- {spacr-0.1.50.dist-info → spacr-0.1.61.dist-info}/METADATA +1 -1
- {spacr-0.1.50.dist-info → spacr-0.1.61.dist-info}/RECORD +24 -18
- {spacr-0.1.50.dist-info → spacr-0.1.61.dist-info}/LICENSE +0 -0
- {spacr-0.1.50.dist-info → spacr-0.1.61.dist-info}/WHEEL +0 -0
- {spacr-0.1.50.dist-info → spacr-0.1.61.dist-info}/entry_points.txt +0 -0
- {spacr-0.1.50.dist-info → spacr-0.1.61.dist-info}/top_level.txt +0 -0
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 = {}
|
@@ -168,9 +168,9 @@ def _get_object_settings(object_type, settings):
|
|
168
168
|
if settings['verbose']:
|
169
169
|
print(object_settings)
|
170
170
|
|
171
|
-
return object_settings
|
171
|
+
return object_settings
|
172
172
|
|
173
|
-
def
|
173
|
+
def set_default_umap_image_settings(settings={}):
|
174
174
|
settings.setdefault('src', 'path')
|
175
175
|
settings.setdefault('row_limit', 1000)
|
176
176
|
settings.setdefault('tables', ['cell', 'cytoplasm', 'nucleus', 'pathogen'])
|
@@ -485,4 +485,428 @@ def get_identify_masks_finetune_default_settings(settings):
|
|
485
485
|
settings.setdefault('rescale', False)
|
486
486
|
settings.setdefault('resample', False)
|
487
487
|
settings.setdefault('grayscale', True)
|
488
|
-
return settings
|
488
|
+
return settings
|
489
|
+
|
490
|
+
q = None
|
491
|
+
|
492
|
+
def check_settings(vars_dict):
|
493
|
+
global q
|
494
|
+
from .gui_utils import parse_list
|
495
|
+
settings = {}
|
496
|
+
# Define the expected types for each key, including None where applicable
|
497
|
+
expected_types = {
|
498
|
+
"src": str,
|
499
|
+
"metadata_type": str,
|
500
|
+
"custom_regex": (str, type(None)),
|
501
|
+
"experiment": str,
|
502
|
+
"channels": list,
|
503
|
+
"magnification": int,
|
504
|
+
"nucleus_channel": (int, type(None)),
|
505
|
+
"nucleus_background": int,
|
506
|
+
"nucleus_Signal_to_noise": float,
|
507
|
+
"nucleus_CP_prob": float,
|
508
|
+
"nucleus_FT": float,
|
509
|
+
"cell_channel": (int, type(None)),
|
510
|
+
"cell_background": (int, float),
|
511
|
+
"cell_Signal_to_noise": (int, float),
|
512
|
+
"cell_CP_prob": (int, float),
|
513
|
+
"cell_FT": (int, float),
|
514
|
+
"pathogen_channel": (int, type(None)),
|
515
|
+
"pathogen_background": (int, float),
|
516
|
+
"pathogen_Signal_to_noise": (int, float),
|
517
|
+
"pathogen_CP_prob": (int, float),
|
518
|
+
"pathogen_FT": (int, float),
|
519
|
+
"preprocess": bool,
|
520
|
+
"masks": bool,
|
521
|
+
"examples_to_plot": int,
|
522
|
+
"randomize": bool,
|
523
|
+
"batch_size": int,
|
524
|
+
"timelapse": bool,
|
525
|
+
"timelapse_displacement": int,
|
526
|
+
"timelapse_memory": int,
|
527
|
+
"timelapse_frame_limits": list, # This can be a list of lists
|
528
|
+
"timelapse_remove_transient": bool,
|
529
|
+
"timelapse_mode": str,
|
530
|
+
"timelapse_objects": list,
|
531
|
+
"fps": int,
|
532
|
+
"remove_background": bool,
|
533
|
+
"lower_percentile": (int, float),
|
534
|
+
"merge_pathogens": bool,
|
535
|
+
"normalize_plots": bool,
|
536
|
+
"all_to_mip": bool,
|
537
|
+
"pick_slice": bool,
|
538
|
+
"skip_mode": str,
|
539
|
+
"save": bool,
|
540
|
+
"plot": bool,
|
541
|
+
"workers": int,
|
542
|
+
"verbose": bool,
|
543
|
+
"input_folder": str,
|
544
|
+
"cell_mask_dim": int,
|
545
|
+
"cell_min_size": int,
|
546
|
+
"cytoplasm_min_size": int,
|
547
|
+
"nucleus_mask_dim": int,
|
548
|
+
"nucleus_min_size": int,
|
549
|
+
"pathogen_mask_dim": int,
|
550
|
+
"pathogen_min_size": int,
|
551
|
+
"save_png": bool,
|
552
|
+
"crop_mode": list,
|
553
|
+
"use_bounding_box": bool,
|
554
|
+
"png_size": list, # This can be a list of lists
|
555
|
+
"normalize": bool,
|
556
|
+
"png_dims": list,
|
557
|
+
"normalize_by": str,
|
558
|
+
"save_measurements": bool,
|
559
|
+
"representative_images": bool,
|
560
|
+
"plot_filtration": bool,
|
561
|
+
"include_uninfected": bool,
|
562
|
+
"dialate_pngs": bool,
|
563
|
+
"dialate_png_ratios": list,
|
564
|
+
"max_workers": int,
|
565
|
+
"cells": list,
|
566
|
+
"cell_loc": list,
|
567
|
+
"pathogens": list,
|
568
|
+
"pathogen_loc": (list, list), # This can be a list of lists
|
569
|
+
"treatments": list,
|
570
|
+
"treatment_loc": (list, list), # This can be a list of lists
|
571
|
+
"channel_of_interest": int,
|
572
|
+
"compartments": list,
|
573
|
+
"measurement": str,
|
574
|
+
"nr_imgs": int,
|
575
|
+
"um_per_pixel": (int, float),
|
576
|
+
# Additional settings based on provided defaults
|
577
|
+
"include_noninfected": bool,
|
578
|
+
"include_multiinfected": bool,
|
579
|
+
"include_multinucleated": bool,
|
580
|
+
"filter_min_max": (list, type(None)),
|
581
|
+
"channel_dims": list,
|
582
|
+
"backgrounds": list,
|
583
|
+
"outline_thickness": int,
|
584
|
+
"outline_color": str,
|
585
|
+
"overlay_chans": list,
|
586
|
+
"overlay": bool,
|
587
|
+
"normalization_percentiles": list,
|
588
|
+
"print_object_number": bool,
|
589
|
+
"nr": int,
|
590
|
+
"figuresize": int,
|
591
|
+
"cmap": str,
|
592
|
+
"test_mode": bool,
|
593
|
+
"test_images": int,
|
594
|
+
"remove_background_cell": bool,
|
595
|
+
"remove_background_nucleus": bool,
|
596
|
+
"remove_background_pathogen": bool,
|
597
|
+
"pathogen_model": (str, type(None)),
|
598
|
+
"filter": bool,
|
599
|
+
"upscale": bool,
|
600
|
+
"upscale_factor": float,
|
601
|
+
"adjust_cells": bool,
|
602
|
+
"row_limit": int,
|
603
|
+
"tables": list,
|
604
|
+
"visualize": str,
|
605
|
+
"image_nr": int,
|
606
|
+
"dot_size": int,
|
607
|
+
"n_neighbors": int,
|
608
|
+
"min_dist": float,
|
609
|
+
"metric": str,
|
610
|
+
"eps": float,
|
611
|
+
"min_samples": int,
|
612
|
+
"filter_by": str,
|
613
|
+
"img_zoom": float,
|
614
|
+
"plot_by_cluster": bool,
|
615
|
+
"plot_cluster_grids": bool,
|
616
|
+
"remove_cluster_noise": bool,
|
617
|
+
"remove_highly_correlated": bool,
|
618
|
+
"log_data": bool,
|
619
|
+
"black_background": bool,
|
620
|
+
"remove_image_canvas": bool,
|
621
|
+
"plot_outlines": bool,
|
622
|
+
"plot_points": bool,
|
623
|
+
"smooth_lines": bool,
|
624
|
+
"clustering": str,
|
625
|
+
"exclude": (str, type(None)),
|
626
|
+
"col_to_compare": str,
|
627
|
+
"pos": str,
|
628
|
+
"neg": str,
|
629
|
+
"embedding_by_controls": bool,
|
630
|
+
"plot_images": bool,
|
631
|
+
"reduction_method": str,
|
632
|
+
"save_figure": bool,
|
633
|
+
"color_by": (str, type(None)),
|
634
|
+
"analyze_clusters": bool,
|
635
|
+
"resnet_features": bool,
|
636
|
+
"test_nr": int,
|
637
|
+
"radial_dist": bool,
|
638
|
+
"calculate_correlation": bool,
|
639
|
+
"manders_thresholds": list,
|
640
|
+
"homogeneity": bool,
|
641
|
+
"homogeneity_distances": list,
|
642
|
+
"save_arrays": bool,
|
643
|
+
"cytoplasm": bool,
|
644
|
+
"merge_edge_pathogen_cells": bool,
|
645
|
+
"cells_per_well": int,
|
646
|
+
"pathogen_size_range": list,
|
647
|
+
"nucleus_size_range": list,
|
648
|
+
"cell_size_range": list,
|
649
|
+
"pathogen_intensity_range": list,
|
650
|
+
"nucleus_intensity_range": list,
|
651
|
+
"cell_intensity_range": list,
|
652
|
+
"target_intensity_min": int,
|
653
|
+
"model_type": str,
|
654
|
+
"heatmap_feature": str,
|
655
|
+
"grouping": str,
|
656
|
+
"min_max": str,
|
657
|
+
"minimum_cell_count": int,
|
658
|
+
"n_estimators": int,
|
659
|
+
"test_size": float,
|
660
|
+
"location_column": str,
|
661
|
+
"positive_control": str,
|
662
|
+
"negative_control": str,
|
663
|
+
"n_repeats": int,
|
664
|
+
"top_features": int,
|
665
|
+
"remove_low_variance_features": bool,
|
666
|
+
"n_jobs": int,
|
667
|
+
"classes": list,
|
668
|
+
"schedule": str,
|
669
|
+
"loss_type": str,
|
670
|
+
"image_size": int,
|
671
|
+
"epochs": int,
|
672
|
+
"val_split": float,
|
673
|
+
"train_mode": str,
|
674
|
+
"learning_rate": float,
|
675
|
+
"weight_decay": float,
|
676
|
+
"dropout_rate": float,
|
677
|
+
"init_weights": bool,
|
678
|
+
"amsgrad": bool,
|
679
|
+
"use_checkpoint": bool,
|
680
|
+
"gradient_accumulation": bool,
|
681
|
+
"gradient_accumulation_steps": int,
|
682
|
+
"intermedeate_save": bool,
|
683
|
+
"pin_memory": bool,
|
684
|
+
"num_workers": int,
|
685
|
+
"augment": bool,
|
686
|
+
"target": str,
|
687
|
+
"cell_types": list,
|
688
|
+
"cell_plate_metadata": (list, type(None)),
|
689
|
+
"pathogen_types": list,
|
690
|
+
"pathogen_plate_metadata": (list, list), # This can be a list of lists
|
691
|
+
"treatment_plate_metadata": (list, list), # This can be a list of lists
|
692
|
+
"metadata_types": list,
|
693
|
+
"cell_chann_dim": int,
|
694
|
+
"nucleus_chann_dim": int,
|
695
|
+
"pathogen_chann_dim": int,
|
696
|
+
"plot_nr": int,
|
697
|
+
"plot_control": bool,
|
698
|
+
"remove_background": bool,
|
699
|
+
"target": str,
|
700
|
+
"upstream": str,
|
701
|
+
"downstream": str,
|
702
|
+
"barecode_length_1": int,
|
703
|
+
"barecode_length_2": int,
|
704
|
+
"chunk_size": int,
|
705
|
+
"grna": str,
|
706
|
+
"barcodes": str,
|
707
|
+
"plate_dict": dict,
|
708
|
+
"pc": str,
|
709
|
+
"pc_loc": str,
|
710
|
+
"nc": str,
|
711
|
+
"nc_loc": str,
|
712
|
+
"dependent_variable": str,
|
713
|
+
"transform": (str, type(None)),
|
714
|
+
"agg_type": str,
|
715
|
+
"min_cell_count": int,
|
716
|
+
"regression_type": str,
|
717
|
+
"remove_row_column_effect": bool,
|
718
|
+
"alpha": float,
|
719
|
+
"fraction_threshold": float,
|
720
|
+
"class_1_threshold": (float, type(None)),
|
721
|
+
"batch_size": int,
|
722
|
+
"CP_prob": float,
|
723
|
+
"flow_threshold": float,
|
724
|
+
"percentiles": (list, type(None)),
|
725
|
+
"circular": bool,
|
726
|
+
"invert": bool,
|
727
|
+
"diameter": int,
|
728
|
+
"grayscale": bool,
|
729
|
+
"resize": bool,
|
730
|
+
"target_height": (int, type(None)),
|
731
|
+
"target_width": (int, type(None)),
|
732
|
+
"rescale": bool,
|
733
|
+
"resample": bool,
|
734
|
+
"model_name": str,
|
735
|
+
"Signal_to_noise": int,
|
736
|
+
"learning_rate": float,
|
737
|
+
"weight_decay": float,
|
738
|
+
"batch_size": int,
|
739
|
+
"n_epochs": int,
|
740
|
+
"from_scratch": bool,
|
741
|
+
"width_height": list,
|
742
|
+
"resize": bool,
|
743
|
+
"gene_weights_csv": str,
|
744
|
+
"fraction_threshold": float,
|
745
|
+
}
|
746
|
+
|
747
|
+
for key, (label, widget, var) in vars_dict.items():
|
748
|
+
if key not in expected_types:
|
749
|
+
if key not in ["General","Nucleus","Cell","Pathogen","Timelapse","Plot","Object Image","Annotate Data","Measurements","Advanced","Miscellaneous","Test"]:
|
750
|
+
|
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 generate_fields(variables, scrollable_frame):
|
798
|
+
from .gui_utils import create_input_field
|
799
|
+
from .gui_elements import spacrToolTip
|
800
|
+
row = 1
|
801
|
+
vars_dict = {}
|
802
|
+
tooltips = {
|
803
|
+
"src": "Path to the folder containing the images.",
|
804
|
+
"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.",
|
805
|
+
"custom_regex": "Custom regex pattern to extract metadata from the image names. This will only be used if 'custom' is selected for 'metadata_type'.",
|
806
|
+
"experiment": "Name of the experiment. This will be used to name the output files.",
|
807
|
+
"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.",
|
808
|
+
"magnification": "At what magnification the images were taken. This will be used to determine the size of the objects in the images.",
|
809
|
+
"nucleus_channel": "The channel to use for the nucleus. If None, the nucleus will not be segmented.",
|
810
|
+
"nucleus_background": "The background intensity for the nucleus channel. This will be used to remove background noise.",
|
811
|
+
"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.",
|
812
|
+
"nucleus_CP_prob": "The cellpose probability threshold for the nucleus channel. This will be used to segment the nucleus.",
|
813
|
+
"nucleus_FT": "The flow threshold for nucleus objects. This will be used in nuclues segmentation.",
|
814
|
+
"cell_channel": "The channel to use for the cell. If None, the cell will not be segmented.",
|
815
|
+
"cell_background": "The background intensity for the cell channel. This will be used to remove background noise.",
|
816
|
+
"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.",
|
817
|
+
"cell_CP_prob": "The cellpose probability threshold for the cell channel. This will be used in cell segmentation.",
|
818
|
+
"cell_FT": "The flow threshold for cell objects. This will be used to segment the cells.",
|
819
|
+
"pathogen_channel": "The channel to use for the pathogen. If None, the pathogen will not be segmented.",
|
820
|
+
"pathogen_background": "The background intensity for the pathogen channel. This will be used to remove background noise.",
|
821
|
+
"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.",
|
822
|
+
"pathogen_CP_prob": "The cellpose probability threshold for the pathogen channel. This will be used to segment the pathogen.",
|
823
|
+
"pathogen_FT": "The flow threshold for pathogen objects. This will be used in pathogen segmentation.",
|
824
|
+
"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.",
|
825
|
+
"masks": "Whether to generate masks for the segmented objects. If True, masks will be generated for the nucleus, cell, and pathogen.",
|
826
|
+
"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.",
|
827
|
+
"randomize": "Whether to randomize the order of the images before processing. Recommended to avoid bias in the segmentation.",
|
828
|
+
"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.",
|
829
|
+
"timelapse": "Whether to process the images as a timelapse.",
|
830
|
+
"timelapse_displacement": "The displacement between frames in the timelapse. This will be used to align the frames before processing.",
|
831
|
+
"timelapse_memory": "The number of frames to in tandem objects must be present in to be considered the same object in the timelapse.",
|
832
|
+
"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.",
|
833
|
+
"timelapse_remove_transient": "Whether to remove transient objects in the timelapse. Transient objects are present in fewer than all frames.",
|
834
|
+
"timelapse_mode": "The mode to use for processing the timelapse. 'trackpy' uses the trackpy library for tracking objects, while 'btrack' uses the btrack library.",
|
835
|
+
"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.",
|
836
|
+
"fps": "Frames per second of the automatically generated timelapse movies.",
|
837
|
+
"remove_background": "Whether to remove background noise from the images. This will help improve the quality of the segmentation.",
|
838
|
+
"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.",
|
839
|
+
"merge_pathogens": "Whether to merge pathogen objects that share more than 75% of their perimeter.",
|
840
|
+
"normalize_plots": "Whether to normalize the plots.",
|
841
|
+
"all_to_mip": "Whether to convert all images to maximum intensity projections before processing.",
|
842
|
+
"pick_slice": "Whether to pick a single slice from the z-stack images. If False, the maximum intensity projection will be used.",
|
843
|
+
"skip_mode": "The mode to use for skipping images. This will determine how to handle images that cannot be processed.",
|
844
|
+
"save": "Whether to save the results to disk.",
|
845
|
+
"merge_edge_pathogen_cells": "Whether to merge cells that share pathogen objects.",
|
846
|
+
"plot": "Whether to plot the results.",
|
847
|
+
"workers": "The number of workers to use for processing the images. This will determine how many images are processed in parallel. Increase to speed up processing.",
|
848
|
+
"verbose": "Whether to print verbose output during processing.",
|
849
|
+
"input_folder": "Path to the folder containing the images.",
|
850
|
+
"cell_mask_dim": "The dimension of the array the cell mask is saved in.",
|
851
|
+
"cell_min_size": "The minimum size of cell objects in pixels^2.",
|
852
|
+
"cytoplasm": "Whether to segment the cytoplasm (Cell - Nucleus + Pathogen).",
|
853
|
+
"cytoplasm_min_size": "The minimum size of cytoplasm objects in pixels^2.",
|
854
|
+
"nucleus_mask_dim": "The dimension of the array the nucleus mask is saved in.",
|
855
|
+
"nucleus_min_size": "The minimum size of nucleus objects in pixels^2.",
|
856
|
+
"pathogen_mask_dim": "The dimension of the array the pathogen mask is saved in.",
|
857
|
+
"pathogen_min_size": "The minimum size of pathogen objects in pixels^2.",
|
858
|
+
"save_png": "Whether to save the segmented objects as PNG images.",
|
859
|
+
"crop_mode": "The mode to use for cropping the images. This will determine which objects are cropped from the images (cell, nucleus, pathogen, cytoplasm).",
|
860
|
+
"use_bounding_box": "Whether to use the bounding box of the objects for cropping. If False, only the object itself will be cropped.",
|
861
|
+
"png_size": "The size of the PNG images to save. This will determine the size of the saved images.",
|
862
|
+
"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.",
|
863
|
+
"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].",
|
864
|
+
"normalize_by": "Whether to normalize the images by field of view (fov) or by PNG image (png).",
|
865
|
+
"save_measurements": "Whether to save the measurements to disk.",
|
866
|
+
"representative_images": "Whether to save representative images of the segmented objects (Not working yet).",
|
867
|
+
"plot_filtration": "Whether to plot the filtration steps.",
|
868
|
+
"include_uninfected": "Whether to include uninfected cells in the analysis.",
|
869
|
+
"dialate_pngs": "Whether to dilate the PNG images before saving.",
|
870
|
+
"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.",
|
871
|
+
"max_workers": "The number of workers to use for processing the images. This will determine how many images are processed in parallel. Increase to speed up processing.",
|
872
|
+
"cells": "The cell types to include in the analysis.",
|
873
|
+
"cell_loc": "The locations of the cell types in the images.",
|
874
|
+
"pathogens": "The pathogen types to include in the analysis.",
|
875
|
+
"pathogen_loc": "The locations of the pathogen types in the images.",
|
876
|
+
"treatments": "The treatments to include in the analysis.",
|
877
|
+
"treatment_loc": "The locations of the treatments in the images.",
|
878
|
+
"channel_of_interest": "The channel of interest to use for the analysis.",
|
879
|
+
"compartments": "The compartments to measure in the images.",
|
880
|
+
"measurement": "The measurement to use for the analysis.",
|
881
|
+
"nr_imgs": "The number of images to plot.",
|
882
|
+
"um_per_pixel": "The micrometers per pixel for the images."
|
883
|
+
}
|
884
|
+
|
885
|
+
for key, (var_type, options, default_value) in variables.items():
|
886
|
+
label, widget, var = create_input_field(scrollable_frame.scrollable_frame, key, row, var_type, options, default_value)
|
887
|
+
vars_dict[key] = (label, widget, var) # Store the label, widget, and variable
|
888
|
+
|
889
|
+
# Add tooltip to the label if it exists in the tooltips dictionary
|
890
|
+
if key in tooltips:
|
891
|
+
spacrToolTip(label, tooltips[key])
|
892
|
+
row += 1
|
893
|
+
return vars_dict
|
894
|
+
|
895
|
+
categories = {
|
896
|
+
"General": ["src", "input_folder", "metadata_type", "custom_regex", "experiment", "channels", "magnification"],
|
897
|
+
"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"],
|
898
|
+
"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"],
|
899
|
+
"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"],
|
900
|
+
"Timelapse": ["timelapse", "fps", "timelapse_displacement", "timelapse_memory", "timelapse_frame_limits", "timelapse_remove_transient", "timelapse_mode", "timelapse_objects", "compartments"],
|
901
|
+
"Plot": ["plot_filtration", "examples_to_plot", "normalize_plots", "normalize", "cmap", "figuresize", "plot", "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"],
|
902
|
+
"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"],
|
903
|
+
"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"],
|
904
|
+
"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"],
|
905
|
+
"Advanced": ["schedule", "test_size","exclude","n_repeats","top_features","n_jobs", "model_type","minimum_cell_count","n_estimators","preprocess", "remove_background", "normalize", "lower_percentile", "merge_pathogens", "batch_size", "filter", "save", "masks", "verbose", "randomize", "max_workers", "workers", "train_mode","amsgrad","use_checkpoint","gradient_accumulation","gradient_accumulation_steps","intermedeate_save","pin_memory","num_workers","channels","augment"],
|
906
|
+
"Clustering": ["eps","min_samples","analyze_clusters","clustering","remove_cluster_noise"],
|
907
|
+
"Embedding": ["visualize","n_neighbors","min_dist","metric","resnet_features","reduction_method","embedding_by_controls","col_to_compare","log_data"],
|
908
|
+
"Train DL Model": ["epochs", "loss_type", "optimizer_type","image_size","val_split","learning_rate","weight_decay","dropout_rate","init_weights", "train", "classes"],
|
909
|
+
"Miscellaneous": ["all_to_mip", "pick_slice", "skip_mode", "upscale", "upscale_factor"],
|
910
|
+
"Test": ["test_mode", "test_images", "random_test", "test_nr"],
|
911
|
+
"Sequencing": ["upstream", "downstream", "barecode_length_1", "barecode_length_2", "chunk_size", "test"]
|
912
|
+
}
|
spacr/utils.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import sys, os, re, sqlite3, torch, torchvision, random, string, shutil, cv2, tarfile, glob
|
1
|
+
import sys, os, re, sqlite3, torch, torchvision, random, string, shutil, cv2, tarfile, glob, psutil, platform, signal
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
from cellpose import models as cp_models
|
@@ -72,13 +72,12 @@ from sklearn.cluster import KMeans
|
|
72
72
|
from scipy import stats
|
73
73
|
|
74
74
|
from .logger import log_function_call
|
75
|
-
|
76
|
-
import os
|
77
|
-
import signal
|
78
|
-
import psutil
|
79
|
-
import platform
|
80
75
|
from multiprocessing import set_start_method, get_start_method
|
81
76
|
|
77
|
+
import tkinter as tk
|
78
|
+
from tkinter import ttk
|
79
|
+
import tkinter.font as tkFont
|
80
|
+
|
82
81
|
def reset_mp():
|
83
82
|
current_method = get_start_method()
|
84
83
|
system = platform.system()
|
@@ -473,7 +472,7 @@ def is_list_of_lists(var):
|
|
473
472
|
return True
|
474
473
|
return False
|
475
474
|
|
476
|
-
def normalize_to_dtype(array, p1=2, p2=98, percentile_list=None):
|
475
|
+
def normalize_to_dtype(array, p1=2, p2=98, percentile_list=None, new_dtype=None):
|
477
476
|
"""
|
478
477
|
Normalize each image in the stack to its own percentiles.
|
479
478
|
|
@@ -492,7 +491,16 @@ def normalize_to_dtype(array, p1=2, p2=98, percentile_list=None):
|
|
492
491
|
The normalized stack with the same shape as the input stack.
|
493
492
|
"""
|
494
493
|
|
495
|
-
|
494
|
+
if new_dtype is None:
|
495
|
+
out_range = (0, np.iinfo(array.dtype).max)
|
496
|
+
elif new_dtype in [np.uint8, np.uint16]:
|
497
|
+
out_range = (0, np.iinfo(new_dtype).max)
|
498
|
+
elif new_dtype in ['uint8', 'uint16']:
|
499
|
+
new_dtype = np.uint8 if new_dtype == 'uint8' else np.uint16
|
500
|
+
out_range = (0, np.iinfo(new_dtype).max)
|
501
|
+
else:
|
502
|
+
out_range = (0, np.iinfo(array.dtype).max)
|
503
|
+
|
496
504
|
nimg = array.shape[2]
|
497
505
|
new_stack = np.empty_like(array, dtype=array.dtype)
|
498
506
|
|
@@ -4051,7 +4059,7 @@ def _merge_cells_based_on_parasite_overlap(parasite_mask, cell_mask, nuclei_mask
|
|
4051
4059
|
|
4052
4060
|
# Relabel the merged cell mask
|
4053
4061
|
relabeled_cell_mask, _ = label(cell_mask, return_num=True)
|
4054
|
-
return relabeled_cell_mask
|
4062
|
+
return relabeled_cell_mask.astype(np.uint16)
|
4055
4063
|
|
4056
4064
|
def adjust_cell_masks(parasite_folder, cell_folder, nuclei_folder, overlap_threshold=5, perimeter_threshold=30):
|
4057
4065
|
|
@@ -4091,7 +4099,7 @@ def adjust_cell_masks(parasite_folder, cell_folder, nuclei_folder, overlap_thres
|
|
4091
4099
|
merged_cell_mask = _merge_cells_based_on_parasite_overlap(parasite_mask, cell_mask, nuclei_mask, overlap_threshold, perimeter_threshold)
|
4092
4100
|
|
4093
4101
|
# Force 16 bit
|
4094
|
-
|
4102
|
+
#merged_cell_mask = merged_cell_mask.astype(np.uint16)
|
4095
4103
|
|
4096
4104
|
# Overwrite the original cell mask file with the merged result
|
4097
4105
|
np.save(cell_path, merged_cell_mask)
|
@@ -4383,4 +4391,4 @@ def correct_masks(src):
|
|
4383
4391
|
|
4384
4392
|
cell_path = os.path.join(src,'norm_channel_stack', 'cell_mask_stack')
|
4385
4393
|
convert_and_relabel_masks(cell_path)
|
4386
|
-
_load_and_concatenate_arrays(src, [0,1,2,3], 1, 0, 2)
|
4394
|
+
_load_and_concatenate_arrays(src, [0,1,2,3], 1, 0, 2)
|
@@ -1,54 +1,60 @@
|
|
1
|
-
spacr/__init__.py,sha256=
|
1
|
+
spacr/__init__.py,sha256=8uhfJ_RcnX4OmvflNRcts4zxnyfML6xiyIeFGZeMpXg,1416
|
2
2
|
spacr/__main__.py,sha256=bkAJJD2kjIqOP-u1kLvct9jQQCeUXzlEjdgitwi1Lm8,75
|
3
3
|
spacr/alpha.py,sha256=Y95sLEfpK2OSYKRn3M8eUOU33JJeXfV8zhrC4KnwSTY,35244
|
4
4
|
spacr/annotate_app.py,sha256=imQ7ZEXDyM6ce1dxZ1xUS1-KequuF_NCI4xCaPLjvco,29275
|
5
5
|
spacr/annotate_app_v2.py,sha256=imQ7ZEXDyM6ce1dxZ1xUS1-KequuF_NCI4xCaPLjvco,29275
|
6
|
-
spacr/app_annotate.py,sha256=
|
6
|
+
spacr/app_annotate.py,sha256=QKWQ0GGiKu5ik14OB4Z3YIqIJYpmsNJlqpnfnQPowAM,23563
|
7
7
|
spacr/app_classify.py,sha256=urTP_wlZ58hSyM5a19slYlBxN0PdC-9-ga0hvq8CGWc,165
|
8
|
-
spacr/app_make_masks.py,sha256=
|
9
|
-
spacr/app_make_masks_v2.py,sha256=
|
8
|
+
spacr/app_make_masks.py,sha256=0N8Wfby3HaVX4m9tOyBy7OQolamYG9lVwmnlzkK4uaE,44993
|
9
|
+
spacr/app_make_masks_v2.py,sha256=OkNeskNbgep8wQa4ES3jpJjZLfn4yIkGwQOd9r0spfA,30497
|
10
10
|
spacr/app_mask.py,sha256=l-dBY8ftzCMdDe6-pXc2Nh_u-idNL9G7UOARiLJBtds,153
|
11
11
|
spacr/app_measure.py,sha256=_K7APYIeOKpV6e_LcqabBjvEi7mfq9Fch8175x1x0k8,162
|
12
|
+
spacr/app_sequencing.py,sha256=DjG26jy4cpddnV8WOOAIiExtOe9MleVMY4MFa5uTo5w,157
|
13
|
+
spacr/app_umap.py,sha256=ZWAmf_OsIKbYvolYuWPMYhdlVe-n2CADoJulAizMiEo,153
|
12
14
|
spacr/chris.py,sha256=YlBjSgeZaY8HPy6jkrT_ISAnCMAKVfvCxF0I9eAZLFM,2418
|
13
15
|
spacr/classify_app.py,sha256=Zi15ryc1ocYitRF4kyxlC27XxGyzfSPdvj2d6ZrSh7E,8446
|
14
16
|
spacr/cli.py,sha256=507jfOOEV8BoL4eeUcblvH-iiDHdBrEVJLu1ghAAPSc,1800
|
15
|
-
spacr/core.py,sha256=
|
17
|
+
spacr/core.py,sha256=JZ8LerUgXarhCQWsUlBD6KULhsIBDlpvotZCSwRt1rI,160317
|
16
18
|
spacr/deep_spacr.py,sha256=rvqOoY9dadcTcKiABf61Nb8HEMVp1NouFmtAE2ee1T4,37056
|
17
19
|
spacr/foldseek.py,sha256=YIP1d4Ci6CeA9jSyiv-HTDbNmAmcSM9Y_DaOs7wYzLY,33546
|
18
20
|
spacr/get_alfafold_structures.py,sha256=ehx_MQgb12k3hFecP6cYVlm5TLO8iWjgevy8ESyS3cw,3544
|
19
21
|
spacr/graph_learning.py,sha256=1tR-ZxvXE3dBz1Saw7BeVFcrsUFu9OlUZeZVifih9eo,13070
|
20
|
-
spacr/gui.py,sha256=
|
22
|
+
spacr/gui.py,sha256=kvQ0X9nyZz_BWsOyJSNSv7gEG1ZuTqjz4EH78e0uul4,7783
|
21
23
|
spacr/gui_2.py,sha256=ZAI5quQYbhQJ40vK0NCqU_UMSPLkpfeQpomBWUSM0fc,6946
|
22
24
|
spacr/gui_annotate.py,sha256=ugBksLGOHdtOLlEuRyyc59TrkYKu3rDf8JxEgiBSVao,6536
|
23
25
|
spacr/gui_classify_app.py,sha256=Zi15ryc1ocYitRF4kyxlC27XxGyzfSPdvj2d6ZrSh7E,8446
|
26
|
+
spacr/gui_core.py,sha256=itgdS6bokEi2ouRMTKjB6T3TnMyUaAPHNTscAEsq4jE,28401
|
27
|
+
spacr/gui_elements.py,sha256=IX1Wsh4V1vk3R6ot0CYKgoDgybbd5IcuAGjmst-EpBc,15008
|
24
28
|
spacr/gui_make_masks_app.py,sha256=tl4M4Q2WQgrrwjRBJVevxJxpNowqzPhWkdCOm2UfRbw,45053
|
25
29
|
spacr/gui_make_masks_app_v2.py,sha256=X3izTBXdCZDlkVe-fbG-jmCQtcAbmK0OIivjyWaLhug,30576
|
26
30
|
spacr/gui_mask_app.py,sha256=mhTl_XzXLFl8Tx3WYEMpdYB_qw9u5JJa0EdkvlcIzAE,10706
|
27
31
|
spacr/gui_measure_app.py,sha256=_C1-XFL5HSquUEEbM_NcxdvHx-socPFCx85MBG4d6xo,10598
|
32
|
+
spacr/gui_run.py,sha256=0x85MJqFtREuWuNeIRLB8hFeibKGszfN14POQQWzPDQ,1998
|
28
33
|
spacr/gui_sim_app.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
|
-
spacr/gui_utils.py,sha256=
|
34
|
+
spacr/gui_utils.py,sha256=sDPmdXonIiCkXm2NBH_Tghf05_2PPV-ltWY8YCgzOzA,5441
|
35
|
+
spacr/gui_wrappers.py,sha256=OBSArqRrM0neEOz44Z_YVceISLqY6WverrVm60GCgqo,4248
|
30
36
|
spacr/io.py,sha256=IoERqSwoxJrInYl-E0WfwFOEDZXFdJofk5DmpbyLGWM,112077
|
31
37
|
spacr/logger.py,sha256=7Zqr3TuuOQLWT32gYr2q1qvv7x0a2JhLANmZcnBXAW8,670
|
32
38
|
spacr/make_masks_app.py,sha256=iGaTwhowoe2JMOSOf8bJwQZTooRhLQx7KO0ewnAmqDY,45138
|
33
39
|
spacr/make_masks_app_v2.py,sha256=X3izTBXdCZDlkVe-fbG-jmCQtcAbmK0OIivjyWaLhug,30576
|
34
40
|
spacr/mask_app.py,sha256=mhTl_XzXLFl8Tx3WYEMpdYB_qw9u5JJa0EdkvlcIzAE,10706
|
35
|
-
spacr/measure.py,sha256=
|
41
|
+
spacr/measure.py,sha256=C8el2DFz1xMa8_V5xU2q5QHs-aZzfCniI-ylcY5RYSI,55736
|
36
42
|
spacr/measure_app.py,sha256=_C1-XFL5HSquUEEbM_NcxdvHx-socPFCx85MBG4d6xo,10598
|
37
43
|
spacr/old_code.py,sha256=jw67DAGoLBd7mWofVzRJSEmCI1Qrff26zIo65SEkV00,13817
|
38
|
-
spacr/plot.py,sha256=
|
39
|
-
spacr/sequencing.py,sha256=
|
40
|
-
spacr/settings.py,sha256=
|
44
|
+
spacr/plot.py,sha256=DYJEoK1kz2ih6ZGvKiA3xTqeIeKQNhuQKwgrscopFxA,69101
|
45
|
+
spacr/sequencing.py,sha256=fHZRnoMSxmhMdadkei3lUeBdckqFyptWdQyWsDW3aaU,83304
|
46
|
+
spacr/settings.py,sha256=Yp4VlkmZLuklSbAf3kiIm7iNTWpy2tJuhLNmLUqvFeM,45668
|
41
47
|
spacr/sim.py,sha256=FveaVgBi3eypO2oVB5Dx-v0CC1Ny7UPfXkJiiRRodAk,71212
|
42
48
|
spacr/sim_app.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
43
49
|
spacr/timelapse.py,sha256=KMYCgHzf9LTZe-lWl5mvH2EjbKRE6OhpwdY13wEumGc,39504
|
44
|
-
spacr/utils.py,sha256=
|
50
|
+
spacr/utils.py,sha256=149Bbha9OXAKyDwABgHz5h4O7Gqy6aeFLA1pMSq311s,186966
|
45
51
|
spacr/version.py,sha256=axH5tnGwtgSnJHb5IDhiu4Zjk5GhLyAEDRe-rnaoFOA,409
|
46
52
|
spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model,sha256=z8BbHWZPRnE9D_BHO0fBREE85c1vkltDs-incs2ytXQ,26566572
|
47
53
|
spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model_settings.csv,sha256=fBAGuL_B8ERVdVizO3BHozTDSbZUh1yFzsYK3wkQN68,420
|
48
54
|
spacr/models/cp/toxo_pv_lumen.CP_model,sha256=2y_CindYhmTvVwBH39SNILF3rI3x9SsRn6qrMxHy3l0,26562451
|
49
|
-
spacr-0.1.
|
50
|
-
spacr-0.1.
|
51
|
-
spacr-0.1.
|
52
|
-
spacr-0.1.
|
53
|
-
spacr-0.1.
|
54
|
-
spacr-0.1.
|
55
|
+
spacr-0.1.61.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
|
56
|
+
spacr-0.1.61.dist-info/METADATA,sha256=wpoz_0ZyZMECzyrobsB7uA27_NsOalPZVRSC9f8Gn9w,5050
|
57
|
+
spacr-0.1.61.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
58
|
+
spacr-0.1.61.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
|
59
|
+
spacr-0.1.61.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
|
60
|
+
spacr-0.1.61.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|