spacr 1.0.7__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spacr/app_classify.py +10 -0
- spacr/app_mask.py +9 -0
- spacr/app_measure.py +9 -0
- spacr/app_sequencing.py +9 -0
- spacr/core.py +172 -1
- spacr/deep_spacr.py +296 -7
- spacr/gui.py +68 -0
- spacr/gui_core.py +319 -10
- spacr/gui_elements.py +772 -13
- spacr/gui_utils.py +301 -151
- spacr/io.py +887 -71
- spacr/logger.py +36 -0
- spacr/measure.py +206 -28
- spacr/ml.py +606 -142
- spacr/plot.py +797 -131
- spacr/sequencing.py +363 -8
- spacr/settings.py +1158 -38
- spacr/sp_stats.py +80 -12
- spacr/spacr_cellpose.py +115 -2
- spacr/submodules.py +747 -19
- spacr/timelapse.py +237 -53
- spacr/toxo.py +132 -6
- spacr/utils.py +2422 -80
- {spacr-1.0.7.dist-info → spacr-1.1.0.dist-info}/METADATA +31 -17
- {spacr-1.0.7.dist-info → spacr-1.1.0.dist-info}/RECORD +29 -29
- {spacr-1.0.7.dist-info → spacr-1.1.0.dist-info}/LICENSE +0 -0
- {spacr-1.0.7.dist-info → spacr-1.1.0.dist-info}/WHEEL +0 -0
- {spacr-1.0.7.dist-info → spacr-1.1.0.dist-info}/entry_points.txt +0 -0
- {spacr-1.0.7.dist-info → spacr-1.1.0.dist-info}/top_level.txt +0 -0
spacr/settings.py
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
import os, ast
|
2
2
|
|
3
3
|
def set_default_plot_merge_settings():
|
4
|
+
"""
|
5
|
+
Set default configuration values for plotting merged image masks and overlays.
|
6
|
+
|
7
|
+
Returns:
|
8
|
+
dict: Dictionary of default settings for plotting merged masks and overlays.
|
9
|
+
|
10
|
+
Default Parameters:
|
11
|
+
- pathogen_limit (int): Maximum number of pathogen objects to display (default: 10).
|
12
|
+
- nuclei_limit (int): Maximum number of nuclei objects to display (default: 1).
|
13
|
+
- remove_background (bool): Whether to subtract background intensity (default: False).
|
14
|
+
- filter_min_max (tuple|None): Optional min/max filter for object values (default: None).
|
15
|
+
- channel_dims (list): Indices for raw image channels (default: [0,1,2,3]).
|
16
|
+
- backgrounds (list): Background values for each channel (default: [100,100,100,100]).
|
17
|
+
- cell_mask_dim (int): Index of cell mask channel (default: 4).
|
18
|
+
- nucleus_mask_dim (int): Index of nucleus mask channel (default: 5).
|
19
|
+
- pathogen_mask_dim (int): Index of pathogen mask channel (default: 6).
|
20
|
+
- outline_thickness (int): Thickness of outline for each object (default: 3).
|
21
|
+
- outline_color (str): Outline color in RGB channel string (default: 'gbr').
|
22
|
+
- overlay_chans (list): Channels to overlay on visualization (default: [1,2,3]).
|
23
|
+
- overlay (bool): Whether to show overlays (default: True).
|
24
|
+
- normalization_percentiles (list): Percentiles for image normalization (default: [2,98]).
|
25
|
+
- normalize (bool): Whether to normalize the image (default: True).
|
26
|
+
- print_object_number (bool): Print number of detected objects (default: True).
|
27
|
+
- nr (int): Number of examples to show (default: 1).
|
28
|
+
- figuresize (int): Size of output figure (default: 10).
|
29
|
+
- cmap (str): Color map to use (default: 'inferno').
|
30
|
+
- verbose (bool): Print debug info (default: True).
|
31
|
+
"""
|
4
32
|
settings = {}
|
5
33
|
settings.setdefault('pathogen_limit', 10)
|
6
34
|
settings.setdefault('nuclei_limit', 1)
|
@@ -25,7 +53,80 @@ def set_default_plot_merge_settings():
|
|
25
53
|
return settings
|
26
54
|
|
27
55
|
def set_default_settings_preprocess_generate_masks(settings={}):
|
28
|
-
|
56
|
+
"""
|
57
|
+
Set default settings for the preprocessing and mask generation pipeline using Cellpose or similar tools.
|
58
|
+
|
59
|
+
This function populates a settings dictionary with default values used during image preprocessing,
|
60
|
+
segmentation mask generation, background removal, plotting, timelapse handling, and more.
|
61
|
+
|
62
|
+
Parameters:
|
63
|
+
settings (dict): Optional dictionary with user-specified values. Defaults will only fill in missing keys.
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
dict: A dictionary containing default configuration parameters for mask generation.
|
67
|
+
|
68
|
+
Default Parameters:
|
69
|
+
# Core pipeline toggles
|
70
|
+
- denoise (bool): Apply denoising to input images.
|
71
|
+
- src (str): Path to image source directory.
|
72
|
+
- delete_intermediate (bool): Delete intermediate files after processing.
|
73
|
+
- preprocess (bool): Whether to run preprocessing steps.
|
74
|
+
- masks (bool): Whether to generate segmentation masks.
|
75
|
+
- save (bool): Save outputs to disk.
|
76
|
+
- consolidate (bool): Combine mask outputs from multiple sources.
|
77
|
+
- batch_size (int): Number of images to process in parallel.
|
78
|
+
- test_mode (bool): Run in test mode for quick inspection.
|
79
|
+
- test_images (int): Number of images to use in test mode.
|
80
|
+
- magnification (int): Objective magnification used for imaging.
|
81
|
+
- custom_regex (str|None): Custom regex for file parsing if needed.
|
82
|
+
- metadata_type (str): Format of metadata ('cellvoyager', etc.).
|
83
|
+
- n_jobs (int): Number of parallel jobs to use (default: CPU count - 4).
|
84
|
+
- randomize (bool): Shuffle processing order.
|
85
|
+
- verbose (bool): Print processing details.
|
86
|
+
- remove_background_{cell,nucleus,pathogen} (bool): Background subtraction toggles per channel.
|
87
|
+
|
88
|
+
# Object diameter estimates
|
89
|
+
- {cell,nucleus,pathogen}_diamiter (float|None): Expected diameter for each object type.
|
90
|
+
|
91
|
+
# Channel and background settings
|
92
|
+
- channels (list): List of image channel indices.
|
93
|
+
- {cell,nucleus,pathogen}_channel (int|None): Channel indices for each object type.
|
94
|
+
- {cell,nucleus,pathogen}_background (int): Background value for each channel.
|
95
|
+
- {cell,nucleus,pathogen}_Signal_to_noise (float): Threshold for SNR filtering.
|
96
|
+
- {cell,nucleus,pathogen}_CP_prob (float): Minimum Cellpose probability threshold.
|
97
|
+
- {cell,nucleus,pathogen}_FT (float): Feature threshold score.
|
98
|
+
|
99
|
+
# Plotting
|
100
|
+
- plot (bool): Enable visual output.
|
101
|
+
- figuresize (int): Plot size in inches.
|
102
|
+
- cmap (str): Color map for plots.
|
103
|
+
- normalize (bool): Normalize intensities for plotting.
|
104
|
+
- normalize_plots (bool): Normalize before visualizing masks.
|
105
|
+
- examples_to_plot (int): Number of plots to generate.
|
106
|
+
|
107
|
+
# Analysis settings
|
108
|
+
- pathogen_model (str|None): Optional path to pathogen model.
|
109
|
+
- merge_pathogens (bool): Merge all pathogen masks into one.
|
110
|
+
- filter (bool): Enable object filtering.
|
111
|
+
- lower_percentile (float): Intensity clipping lower bound.
|
112
|
+
|
113
|
+
# Timelapse tracking
|
114
|
+
- timelapse (bool): Enable timelapse mode.
|
115
|
+
- fps (int): Frames per second for exported timelapse.
|
116
|
+
- timelapse_displacement (float|None): Displacement threshold for linking.
|
117
|
+
- timelapse_memory (int): Maximum number of frames to retain object identity.
|
118
|
+
- timelapse_frame_limits (list): List of frames to keep.
|
119
|
+
- timelapse_remove_transient (bool): Remove transient objects.
|
120
|
+
- timelapse_mode (str): Tracking algorithm ('trackpy', etc.).
|
121
|
+
- timelapse_objects (str|None): Object types to track.
|
122
|
+
|
123
|
+
# Miscellaneous
|
124
|
+
- all_to_mip (bool): Convert all frames to maximum intensity projection.
|
125
|
+
- upscale (bool): Upsample image resolution.
|
126
|
+
- upscale_factor (float): Upsampling multiplier.
|
127
|
+
- adjust_cells (bool): Morphologically adjust cell boundaries.
|
128
|
+
- use_sam_{cell,nucleus,pathogen} (bool): Use Segment Anything Model (SAM) for segmentation.
|
129
|
+
"""
|
29
130
|
settings.setdefault('denoise', False)
|
30
131
|
settings.setdefault('src', 'path')
|
31
132
|
settings.setdefault('delete_intermediate', False)
|
@@ -104,6 +205,36 @@ def set_default_settings_preprocess_generate_masks(settings={}):
|
|
104
205
|
return settings
|
105
206
|
|
106
207
|
def set_default_plot_data_from_db(settings):
|
208
|
+
"""
|
209
|
+
Set default plotting settings for visualizing data from an SQL database.
|
210
|
+
|
211
|
+
Parameters:
|
212
|
+
settings (dict): Settings dictionary to populate.
|
213
|
+
|
214
|
+
Returns:
|
215
|
+
dict: Dictionary with default keys and values for graph plotting from database data.
|
216
|
+
|
217
|
+
Default Parameters:
|
218
|
+
- src (str): Path to the database directory (default: 'path').
|
219
|
+
- database (str): Filename of SQLite database (default: 'measurements.db').
|
220
|
+
- graph_name (str): Output name of the plot (default: 'Figure_1').
|
221
|
+
- table_names (list): Tables to include from the database (default: ['cell', 'cytoplasm', 'nucleus', 'pathogen']).
|
222
|
+
- data_column (str): Column to plot (default: 'recruitment').
|
223
|
+
- grouping_column (str): Column used to group data (default: 'condition').
|
224
|
+
- cell_types (list): Cell types to include (default: ['Hela']).
|
225
|
+
- cell_plate_metadata, pathogen_plate_metadata, treatment_plate_metadata (None): Optional metadata dictionaries.
|
226
|
+
- pathogen_types, treatments (None): Optional lists of types.
|
227
|
+
- graph_type (str): Type of plot (default: 'jitter').
|
228
|
+
- theme (str): Seaborn theme (default: 'deep').
|
229
|
+
- save (bool): Save plot to disk (default: True).
|
230
|
+
- y_lim (list): y-axis limits (default: [1, 1.5]).
|
231
|
+
- verbose (bool): Verbose output (default: False).
|
232
|
+
- channel_of_interest (int): Image channel to analyze (default: 1).
|
233
|
+
- nuclei_limit (int): Max nuclei per field (default: 2).
|
234
|
+
- pathogen_limit (int): Max pathogens per field (default: 3).
|
235
|
+
- representation (str): Plot representation ('well' or 'cell', default: 'well').
|
236
|
+
- uninfected (bool): Include uninfected controls (default: False).
|
237
|
+
"""
|
107
238
|
settings.setdefault('src', 'path')
|
108
239
|
settings.setdefault('database', 'measurements.db')
|
109
240
|
settings.setdefault('graph_name', 'Figure_1')
|
@@ -129,7 +260,34 @@ def set_default_plot_data_from_db(settings):
|
|
129
260
|
return settings
|
130
261
|
|
131
262
|
def set_default_settings_preprocess_img_data(settings):
|
132
|
-
|
263
|
+
"""
|
264
|
+
Set default values for preprocessing image data before analysis.
|
265
|
+
|
266
|
+
Parameters:
|
267
|
+
settings (dict): Settings dictionary to populate.
|
268
|
+
|
269
|
+
Returns:
|
270
|
+
dict: Updated dictionary with image preprocessing settings.
|
271
|
+
|
272
|
+
Default Parameters:
|
273
|
+
- metadata_type (str): Metadata parsing type (default: 'cellvoyager').
|
274
|
+
- custom_regex (str|None): Regex for file parsing (default: None).
|
275
|
+
- nr (int): Number of examples to plot (default: 1).
|
276
|
+
- plot (bool): Whether to show plots (default: True).
|
277
|
+
- batch_size (int): Number of images to process per batch (default: 50).
|
278
|
+
- timelapse (bool): Whether this is a time series dataset (default: False).
|
279
|
+
- lower_percentile (int): Lower percentile for intensity clipping (default: 2).
|
280
|
+
- randomize (bool): Shuffle input file order (default: True).
|
281
|
+
- all_to_mip (bool): Convert all frames to max-intensity projection (default: False).
|
282
|
+
- cmap (str): Color map for images (default: 'inferno').
|
283
|
+
- figuresize (int): Figure size for plots (default: 10).
|
284
|
+
- normalize (bool): Normalize image intensities (default: True).
|
285
|
+
- save_dtype (str): Data type for saving processed files (default: 'uint16').
|
286
|
+
- test_mode (bool): Whether to run in test mode (default: False).
|
287
|
+
- test_images (int): Number of test images to run in test mode (default: 10).
|
288
|
+
- random_test (bool): Randomly select test images (default: True).
|
289
|
+
- fps (int): Frames per second for timelapse visualization (default: 2).
|
290
|
+
"""
|
133
291
|
settings.setdefault('metadata_type', 'cellvoyager')
|
134
292
|
settings.setdefault('custom_regex', None)
|
135
293
|
settings.setdefault('nr', 1)
|
@@ -150,7 +308,44 @@ def set_default_settings_preprocess_img_data(settings):
|
|
150
308
|
return settings
|
151
309
|
|
152
310
|
def _get_object_settings(object_type, settings):
|
153
|
-
|
311
|
+
"""
|
312
|
+
Generate object-specific segmentation parameters for Cellpose or similar models.
|
313
|
+
|
314
|
+
This function constructs a dictionary of settings tailored to the object type
|
315
|
+
(e.g., 'cell', 'nucleus', or 'pathogen') based on user input and default rules.
|
316
|
+
It dynamically adjusts diameter, model selection, and filtering options.
|
317
|
+
|
318
|
+
Parameters:
|
319
|
+
object_type (str): Type of object to configure. Must be one of 'cell', 'nucleus', or 'pathogen'.
|
320
|
+
settings (dict): Configuration dictionary containing global pipeline parameters such as
|
321
|
+
'magnification', diameter overrides, SAM usage flags, and verbosity.
|
322
|
+
|
323
|
+
Returns:
|
324
|
+
dict: Object-specific segmentation settings.
|
325
|
+
|
326
|
+
Raises:
|
327
|
+
ValueError: If object_type is not one of the supported types.
|
328
|
+
|
329
|
+
Notes:
|
330
|
+
- The estimated object diameter is computed from magnification using `_get_diam`.
|
331
|
+
- If explicit diameters (e.g., `cell_diamiter`) are provided in settings, they override the computed value.
|
332
|
+
- The model name is chosen based on object type and SAM usage.
|
333
|
+
- Verbose output is printed if `settings['verbose']` is True.
|
334
|
+
|
335
|
+
Example output structure:
|
336
|
+
{
|
337
|
+
'diameter': 30.0,
|
338
|
+
'minimum_size': 225.0,
|
339
|
+
'maximum_size': 9000.0,
|
340
|
+
'merge': False,
|
341
|
+
'resample': True,
|
342
|
+
'remove_border_objects': False,
|
343
|
+
'model_name': 'cyto2',
|
344
|
+
'filter_size': False,
|
345
|
+
'filter_intensity': False,
|
346
|
+
'restore_type': None
|
347
|
+
}
|
348
|
+
"""
|
154
349
|
from .utils import _get_diam
|
155
350
|
object_settings = {}
|
156
351
|
|
@@ -224,6 +419,58 @@ def _get_object_settings(object_type, settings):
|
|
224
419
|
return object_settings
|
225
420
|
|
226
421
|
def set_default_umap_image_settings(settings={}):
|
422
|
+
"""
|
423
|
+
Set default configuration values for UMAP-based image embedding and clustering.
|
424
|
+
|
425
|
+
Parameters:
|
426
|
+
settings (dict): Optional dictionary of user-provided settings. Keys that are not present
|
427
|
+
will be set to their default values.
|
428
|
+
|
429
|
+
Returns:
|
430
|
+
dict: Updated settings dictionary containing all necessary UMAP image analysis parameters.
|
431
|
+
|
432
|
+
Default Parameters Set:
|
433
|
+
- src (str): Path to input directory (default: 'path').
|
434
|
+
- row_limit (int): Maximum number of rows to use (default: 1000).
|
435
|
+
- tables (list): List of object types to include (default: ['cell', 'cytoplasm', 'nucleus', 'pathogen']).
|
436
|
+
- visualize (str): Object type to visualize (default: 'cell').
|
437
|
+
- image_nr (int): Number of example images to display (default: 16).
|
438
|
+
- dot_size (int): Dot size in the scatter plot (default: 50).
|
439
|
+
- n_neighbors (int): UMAP parameter for local neighborhood size (default: 1000).
|
440
|
+
- min_dist (float): UMAP parameter controlling embedding compactness (default: 0.1).
|
441
|
+
- metric (str): Distance metric used in UMAP (default: 'euclidean').
|
442
|
+
- eps (float): DBSCAN epsilon parameter (default: 0.9).
|
443
|
+
- min_samples (int): Minimum number of samples per cluster in DBSCAN (default: 100).
|
444
|
+
- filter_by (str): Column used to filter features (default: 'channel_0').
|
445
|
+
- img_zoom (float): Zoom level for image thumbnails (default: 0.5).
|
446
|
+
- plot_by_cluster (bool): Whether to color plot by cluster ID (default: True).
|
447
|
+
- plot_cluster_grids (bool): Whether to plot grid of cluster example images (default: True).
|
448
|
+
- remove_cluster_noise (bool): Remove outliers/noise clusters (default: True).
|
449
|
+
- remove_highly_correlated (bool): Remove highly correlated features (default: True).
|
450
|
+
- log_data (bool): Log-transform input features (default: False).
|
451
|
+
- figuresize (int): Size of output figure (default: 10).
|
452
|
+
- black_background (bool): Whether to use a black background in plots (default: True).
|
453
|
+
- remove_image_canvas (bool): Crop out canvas margins in image plots (default: False).
|
454
|
+
- plot_outlines (bool): Overlay object outlines on image thumbnails (default: True).
|
455
|
+
- plot_points (bool): Plot UMAP/TSNE scatter points (default: True).
|
456
|
+
- smooth_lines (bool): Use smoothed lines in plots (default: True).
|
457
|
+
- clustering (str): Clustering method, e.g. 'dbscan' (default: 'dbscan').
|
458
|
+
- exclude (list|None): List of object classes or conditions to exclude (default: None).
|
459
|
+
- col_to_compare (str): Column used to compare conditions (default: 'columnID').
|
460
|
+
- pos (str): Label for positive control column (default: 'c1').
|
461
|
+
- neg (str): Label for negative control column (default: 'c2').
|
462
|
+
- mix (str): Label for mixed/experimental column (default: 'c3').
|
463
|
+
- embedding_by_controls (bool): Fit UMAP only on control samples (default: False).
|
464
|
+
- plot_images (bool): Whether to include image overlays in plot (default: True).
|
465
|
+
- reduction_method (str): Dimensionality reduction method (default: 'umap').
|
466
|
+
- save_figure (bool): Save output figure to disk (default: False).
|
467
|
+
- n_jobs (int): Number of parallel jobs to use (default: -1, i.e., all cores).
|
468
|
+
- color_by (str|None): Column name to use for color-coding scatter points (default: None).
|
469
|
+
- exclude_conditions (list|None): List of conditions to exclude from embedding (default: None).
|
470
|
+
- analyze_clusters (bool): Perform further statistical analysis on clusters (default: False).
|
471
|
+
- resnet_features (bool): Use pretrained ResNet features (default: False).
|
472
|
+
- verbose (bool): Print status messages (default: True).
|
473
|
+
"""
|
227
474
|
settings.setdefault('src', 'path')
|
228
475
|
settings.setdefault('row_limit', 1000)
|
229
476
|
settings.setdefault('tables', ['cell', 'cytoplasm', 'nucleus', 'pathogen'])
|
@@ -267,7 +514,70 @@ def set_default_umap_image_settings(settings={}):
|
|
267
514
|
return settings
|
268
515
|
|
269
516
|
def get_measure_crop_settings(settings={}):
|
270
|
-
|
517
|
+
"""
|
518
|
+
Set default configuration for object measurement and cropping.
|
519
|
+
|
520
|
+
This function initializes and returns a dictionary of settings used for
|
521
|
+
measuring and cropping segmented objects such as cells, nuclei, or pathogens.
|
522
|
+
It covers measurement parameters, image cropping/export options,
|
523
|
+
multiprocessing behavior, and test mode overrides.
|
524
|
+
|
525
|
+
Parameters:
|
526
|
+
settings (dict, optional): Existing settings dictionary to be updated with defaults.
|
527
|
+
|
528
|
+
Returns:
|
529
|
+
dict: Fully populated settings dictionary with default values applied.
|
530
|
+
|
531
|
+
Key Settings:
|
532
|
+
- Measurement:
|
533
|
+
'save_measurements' (bool): Whether to save measurement results.
|
534
|
+
'radial_dist' (bool): Compute radial distance profiles.
|
535
|
+
'calculate_correlation' (bool): Compute intensity correlations.
|
536
|
+
'manders_thresholds' (list): Thresholds (percentiles) for Manders overlap coefficient.
|
537
|
+
'homogeneity' (bool): Compute local homogeneity.
|
538
|
+
'homogeneity_distances' (list): Distances (in pixels) for homogeneity calculations.
|
539
|
+
|
540
|
+
- Cropping:
|
541
|
+
'save_png' (bool): Export cropped objects as PNGs.
|
542
|
+
'save_arrays' (bool): Save raw data arrays for cropped objects.
|
543
|
+
'png_size' (list): Output size of cropped PNGs [width, height].
|
544
|
+
'png_dims' (list): Channel indices to include in the output PNG.
|
545
|
+
'normalize' (bool): Apply intensity normalization.
|
546
|
+
'normalize_by' (str): Normalize based on object-level or global stats.
|
547
|
+
'crop_mode' (list): Objects to crop, e.g., ['cell'].
|
548
|
+
'use_bounding_box' (bool): Use tight bounding boxes instead of masks.
|
549
|
+
'dialate_pngs' (bool): Apply dilation to the object mask.
|
550
|
+
'dialate_png_ratios' (list): Dilation factors relative to object size.
|
551
|
+
|
552
|
+
- Timelapse:
|
553
|
+
'timelapse' (bool): Process timelapse series.
|
554
|
+
'timelapse_objects' (list): Objects to track over time.
|
555
|
+
|
556
|
+
- Miscellaneous:
|
557
|
+
'src' (str): Input directory path.
|
558
|
+
'experiment' (str): Name of the experiment.
|
559
|
+
'test_mode' (bool): Run in debug mode with fewer images and visual output.
|
560
|
+
'test_nr' (int): Number of test images to process.
|
561
|
+
'plot' (bool): Show debug plots.
|
562
|
+
'n_jobs' (int): Number of CPU threads to use.
|
563
|
+
'verbose' (bool): Enable verbose output.
|
564
|
+
|
565
|
+
- Object masks:
|
566
|
+
'cell_mask_dim', 'nucleus_mask_dim', 'pathogen_mask_dim' (int): Channels for respective masks.
|
567
|
+
'cytoplasm' (bool): Include cytoplasmic measurements.
|
568
|
+
'merge_edge_pathogen_cells' (bool): Option to merge pathogens at borders.
|
569
|
+
'min_size' (int): Minimum size for filtering objects by type.
|
570
|
+
|
571
|
+
- Advanced:
|
572
|
+
'distance_gaussian_sigma' (float): Smoothing factor for distance transforms.
|
573
|
+
|
574
|
+
Notes:
|
575
|
+
- When 'test_mode' is True, verbose and plot modes are automatically enabled.
|
576
|
+
- 'os.cpu_count()' is used to allocate available cores for parallel processing.
|
577
|
+
|
578
|
+
Example:
|
579
|
+
settings = get_measure_crop_settings()
|
580
|
+
"""
|
271
581
|
settings.setdefault('src', 'path')
|
272
582
|
settings.setdefault('delete_intermediate', False)
|
273
583
|
|
@@ -336,6 +646,65 @@ def get_measure_crop_settings(settings={}):
|
|
336
646
|
return settings
|
337
647
|
|
338
648
|
def set_default_analyze_screen(settings):
|
649
|
+
"""
|
650
|
+
Set default configuration for analyzing a CRISPR or compound screen.
|
651
|
+
|
652
|
+
This function populates a provided settings dictionary with defaults related to
|
653
|
+
feature extraction, model training, screen scoring, and heatmap visualization.
|
654
|
+
|
655
|
+
Parameters:
|
656
|
+
settings (dict): Dictionary of user-provided settings to be updated.
|
657
|
+
|
658
|
+
Returns:
|
659
|
+
dict: Updated settings dictionary with all necessary keys and default values.
|
660
|
+
|
661
|
+
Key Settings:
|
662
|
+
- Input/Output:
|
663
|
+
'src' (str): Path to the screen results folder.
|
664
|
+
'save_to_db' (bool): If True, results will be saved to a database.
|
665
|
+
'annotation_column' (str or None): Column used to group conditions or annotate classes.
|
666
|
+
'location_column' (str): Column identifying spatial layout (e.g., 'columnID').
|
667
|
+
|
668
|
+
- Modeling:
|
669
|
+
'model_type_ml' (str): Machine learning model to use ('xgboost' by default).
|
670
|
+
'learning_rate' (float): Learning rate for boosting models.
|
671
|
+
'n_estimators' (int): Number of trees for boosting.
|
672
|
+
'reg_alpha' (float): L1 regularization coefficient.
|
673
|
+
'reg_lambda' (float): L2 regularization coefficient.
|
674
|
+
'test_size' (float): Proportion of data used for testing.
|
675
|
+
'cross_validation' (bool): Whether to perform cross-validation.
|
676
|
+
'n_repeats' (int): Number of repetitions for performance evaluation.
|
677
|
+
'prune_features' (bool): Whether to apply feature pruning.
|
678
|
+
|
679
|
+
- Feature selection:
|
680
|
+
'remove_low_variance_features' (bool): Exclude features with low variance.
|
681
|
+
'remove_highly_correlated_features' (bool): Exclude highly collinear features.
|
682
|
+
'top_features' (int): Number of top features to retain after training.
|
683
|
+
|
684
|
+
- Screen summarization:
|
685
|
+
'heatmap_feature' (str): Feature used for heatmap visualization (e.g., 'predictions').
|
686
|
+
'grouping' (str): How to summarize replicate data ('mean', 'median', etc.).
|
687
|
+
'min_max' (str): Scaling mode for heatmap normalization ('allq', 'robust', etc.).
|
688
|
+
'cmap' (str): Colormap used for heatmap plotting.
|
689
|
+
|
690
|
+
- Controls:
|
691
|
+
'positive_control' (str): Label for the positive control condition.
|
692
|
+
'negative_control' (str): Label for the negative control condition.
|
693
|
+
'exclude' (list or None): List of condition labels to exclude from analysis.
|
694
|
+
|
695
|
+
- Filtering:
|
696
|
+
'minimum_cell_count' (int): Minimum number of cells per well required for inclusion.
|
697
|
+
'nuclei_limit' (bool): Whether to apply a nuclei count filter.
|
698
|
+
'pathogen_limit' (int): Maximum number of pathogens per object.
|
699
|
+
|
700
|
+
- Miscellaneous:
|
701
|
+
'channel_of_interest' (int): Imaging channel used for downstream focus.
|
702
|
+
'n_jobs' (int): Number of parallel jobs to run (-1 uses all CPUs).
|
703
|
+
'verbose' (bool): Enable verbose logging.
|
704
|
+
|
705
|
+
Example:
|
706
|
+
settings = set_default_analyze_screen({})
|
707
|
+
"""
|
339
708
|
settings.setdefault('src', 'path')
|
340
709
|
settings.setdefault('annotation_column', None)
|
341
710
|
settings.setdefault('save_to_db', False)
|
@@ -368,6 +737,67 @@ def set_default_analyze_screen(settings):
|
|
368
737
|
return settings
|
369
738
|
|
370
739
|
def set_default_train_test_model(settings):
|
740
|
+
"""
|
741
|
+
Set default configuration for training and testing a deep learning classification model.
|
742
|
+
|
743
|
+
This function populates a provided dictionary with default settings used for model training,
|
744
|
+
including architecture, optimizer, augmentation, and hardware preferences.
|
745
|
+
|
746
|
+
Parameters:
|
747
|
+
settings (dict): Dictionary of user-provided settings to be updated.
|
748
|
+
|
749
|
+
Returns:
|
750
|
+
dict: Updated settings dictionary with all necessary keys and default values.
|
751
|
+
|
752
|
+
Key Settings:
|
753
|
+
- Input/Output:
|
754
|
+
'src' (str): Path to dataset directory.
|
755
|
+
'train' (bool): Whether to perform training.
|
756
|
+
'test' (bool): Whether to run inference on test data.
|
757
|
+
'classes' (list): List of class labels (e.g., ['nc', 'pc']).
|
758
|
+
|
759
|
+
- Model architecture:
|
760
|
+
'model_type' (str): Model architecture to use (e.g., 'maxvit_t').
|
761
|
+
'init_weights' (bool): Whether to initialize model with pretrained weights.
|
762
|
+
'dropout_rate' (float): Dropout rate applied before final layers.
|
763
|
+
|
764
|
+
- Optimizer and scheduler:
|
765
|
+
'optimizer_type' (str): Optimizer to use (e.g., 'adamw').
|
766
|
+
'schedule' (str): Learning rate scheduler ('reduce_lr_on_plateau' or 'step_lr').
|
767
|
+
'amsgrad' (bool): Use AMSGrad variant of Adam.
|
768
|
+
'weight_decay' (float): Weight decay regularization.
|
769
|
+
'learning_rate' (float): Initial learning rate.
|
770
|
+
|
771
|
+
- Loss function:
|
772
|
+
'loss_type' (str): Loss function to use (e.g., 'focal_loss', 'binary_cross_entropy_with_logits').
|
773
|
+
|
774
|
+
- Training hyperparameters:
|
775
|
+
'batch_size' (int): Batch size used during training.
|
776
|
+
'epochs' (int): Number of training epochs.
|
777
|
+
'val_split' (float): Proportion of data used for validation.
|
778
|
+
'gradient_accumulation' (bool): Enable gradient accumulation to simulate larger batch sizes.
|
779
|
+
'gradient_accumulation_steps' (int): Number of steps for accumulation.
|
780
|
+
'pin_memory' (bool): Pin memory in DataLoader.
|
781
|
+
|
782
|
+
- Image preprocessing:
|
783
|
+
'image_size' (int): Size to which images are resized (assumes square).
|
784
|
+
'normalize' (bool): Whether to apply normalization.
|
785
|
+
'train_channels' (list): List of channels to use for training (e.g., ['r','g','b']).
|
786
|
+
'augment' (bool): Whether to apply data augmentation.
|
787
|
+
|
788
|
+
- Checkpointing:
|
789
|
+
'use_checkpoint' (bool): Save model checkpoints.
|
790
|
+
'intermedeate_save' (bool): Save intermediate models during training.
|
791
|
+
|
792
|
+
- Parallelization:
|
793
|
+
'n_jobs' (int): Number of parallel processes to use (default: available cores - 2).
|
794
|
+
|
795
|
+
- Miscellaneous:
|
796
|
+
'verbose' (bool): Enable detailed logging.
|
797
|
+
|
798
|
+
Example:
|
799
|
+
settings = set_default_train_test_model({})
|
800
|
+
"""
|
371
801
|
cores = os.cpu_count()-2
|
372
802
|
|
373
803
|
settings.setdefault('src','path')
|
@@ -400,7 +830,50 @@ def set_default_train_test_model(settings):
|
|
400
830
|
return settings
|
401
831
|
|
402
832
|
def set_generate_training_dataset_defaults(settings):
|
403
|
-
|
833
|
+
"""
|
834
|
+
Set default configuration for generating a training dataset from measurements and metadata.
|
835
|
+
|
836
|
+
This function populates the given dictionary with default values required for generating
|
837
|
+
a structured dataset for supervised learning based on annotated metadata or measurements.
|
838
|
+
|
839
|
+
Args:
|
840
|
+
settings (dict): Dictionary to populate with defaults if not already present.
|
841
|
+
|
842
|
+
Returns:
|
843
|
+
dict: Updated settings dictionary with default keys and values for dataset generation.
|
844
|
+
|
845
|
+
Key Settings:
|
846
|
+
- Input/Output:
|
847
|
+
'src' (str): Path to source data.
|
848
|
+
'png_type' (str): Type of image to extract (e.g., 'cell_png').
|
849
|
+
|
850
|
+
- Metadata and labels:
|
851
|
+
'dataset_mode' (str): Mode to derive labels ('metadata' or 'measurement').
|
852
|
+
'annotation_column' (str): Name of column in metadata used for annotation.
|
853
|
+
'annotated_classes' (list): List of class indices (e.g., [1, 2]).
|
854
|
+
'class_metadata' (list): List of metadata values corresponding to each class.
|
855
|
+
'metadata_item_1_name' (list): Primary metadata variable (e.g., conditions).
|
856
|
+
'metadata_item_1_value' (list of list): Metadata values for each class.
|
857
|
+
'metadata_item_2_name' (list): Secondary metadata variable.
|
858
|
+
'metadata_item_2_value' (list of list): Values of secondary variable by class.
|
859
|
+
'metadata_type_by' (str): Column to use for metadata grouping (e.g., 'columnID').
|
860
|
+
|
861
|
+
- Table and image options:
|
862
|
+
'tables' (list or None): Table(s) to source data from (e.g., 'cell', 'nucleus').
|
863
|
+
'channel_of_interest' (int): Channel to use for class derivation or filtering.
|
864
|
+
'custom_measurement' (str or None): Measurement key to use for class label if in measurement mode.
|
865
|
+
|
866
|
+
- Limits and filters:
|
867
|
+
'nuclei_limit' (bool): Whether to filter based on number of nuclei.
|
868
|
+
'pathogen_limit' (bool): Whether to filter based on number of pathogens.
|
869
|
+
|
870
|
+
- Image settings:
|
871
|
+
'size' (int): Target image size (square width/height in pixels).
|
872
|
+
'test_split' (float): Fraction of data to reserve for testing.
|
873
|
+
|
874
|
+
Example:
|
875
|
+
settings = set_generate_training_dataset_defaults({})
|
876
|
+
"""
|
404
877
|
settings.setdefault('src','path')
|
405
878
|
settings.setdefault('tables', ['cell', 'nucleus', 'pathogen', 'cytoplasm'])
|
406
879
|
settings.setdefault('dataset_mode','metadata')
|
@@ -425,7 +898,70 @@ def set_generate_training_dataset_defaults(settings):
|
|
425
898
|
return settings
|
426
899
|
|
427
900
|
def deep_spacr_defaults(settings):
|
428
|
-
|
901
|
+
"""
|
902
|
+
Set default arguments for deep learning analysis in spaCR.
|
903
|
+
|
904
|
+
This function fills in default arguments for training, testing, and applying deep learning
|
905
|
+
models on spaCR datasets, supporting both metadata and measurement-based annotations.
|
906
|
+
|
907
|
+
Args:
|
908
|
+
settings (dict): Dictionary to populate with default arguments.
|
909
|
+
|
910
|
+
Returns:
|
911
|
+
dict: Updated settings dictionary.
|
912
|
+
|
913
|
+
Default Args:
|
914
|
+
src (str): Path to dataset.
|
915
|
+
dataset_mode (str): 'metadata' or 'measurement' mode for annotation.
|
916
|
+
annotation_column (str): Metadata column containing annotations.
|
917
|
+
annotated_classes (list): Class indices (e.g., [1, 2]).
|
918
|
+
classes (list): Class labels (e.g., ['nc', 'pc']).
|
919
|
+
size (int): Image size for training.
|
920
|
+
test_split (float): Fraction of data reserved for testing.
|
921
|
+
class_metadata (list): Metadata values for each class.
|
922
|
+
metadata_type_by (str): Key used for metadata classification (e.g., 'columnID').
|
923
|
+
channel_of_interest (int): Channel used for classification or filtering.
|
924
|
+
custom_measurement (str or None): Measurement used for label derivation.
|
925
|
+
tables (list or None): Tables to extract measurements from (e.g., 'cell').
|
926
|
+
png_type (str): Image type used for training, e.g., 'cell_png'.
|
927
|
+
custom_model (bool): Whether to load a custom model.
|
928
|
+
custom_model_path (str): Path to the custom model file.
|
929
|
+
train (bool): Whether to perform training.
|
930
|
+
test (bool): Whether to perform testing.
|
931
|
+
model_type (str): Model architecture (e.g., 'maxvit_t').
|
932
|
+
optimizer_type (str): Optimizer to use (e.g., 'adamw').
|
933
|
+
schedule (str): Learning rate schedule ('reduce_lr_on_plateau' or 'step_lr').
|
934
|
+
loss_type (str): Loss function ('focal_loss', etc.).
|
935
|
+
normalize (bool): Whether to normalize input images.
|
936
|
+
image_size (int): Image dimensions (assumes square input).
|
937
|
+
batch_size (int): Batch size for training.
|
938
|
+
epochs (int): Number of training epochs.
|
939
|
+
val_split (float): Validation fraction from training data.
|
940
|
+
learning_rate (float): Initial learning rate.
|
941
|
+
weight_decay (float): Weight decay for optimizer.
|
942
|
+
dropout_rate (float): Dropout rate in model.
|
943
|
+
init_weights (bool): Whether to initialize weights.
|
944
|
+
amsgrad (bool): Use AMSGrad with Adam.
|
945
|
+
use_checkpoint (bool): Save and load checkpoints.
|
946
|
+
gradient_accumulation (bool): Use gradient accumulation.
|
947
|
+
gradient_accumulation_steps (int): Steps to accumulate gradients.
|
948
|
+
intermedeate_save (bool): Save intermediate weights.
|
949
|
+
pin_memory (bool): Use pin memory in DataLoader.
|
950
|
+
n_jobs (int): Number of CPU cores to use.
|
951
|
+
train_channels (list): Color channels for training (e.g., ['r', 'g', 'b']).
|
952
|
+
augment (bool): Use data augmentation.
|
953
|
+
verbose (bool): Verbose output.
|
954
|
+
apply_model_to_dataset (bool): Whether to apply model after training.
|
955
|
+
file_metadata (str or None): Path to metadata for inference.
|
956
|
+
sample (str or None): Sample identifier.
|
957
|
+
experiment (str): Experiment identifier.
|
958
|
+
score_threshold (float): Classification threshold.
|
959
|
+
dataset (str): Path to dataset for inference.
|
960
|
+
model_path (str): Path to saved model file.
|
961
|
+
file_type (str): File type of images (e.g., 'cell_png').
|
962
|
+
generate_training_dataset (bool): Whether to generate training dataset.
|
963
|
+
train_DL_model (bool): Whether to train the deep learning model.
|
964
|
+
"""
|
429
965
|
cores = os.cpu_count()-4
|
430
966
|
|
431
967
|
settings.setdefault('src','path')
|
@@ -481,37 +1017,123 @@ def deep_spacr_defaults(settings):
|
|
481
1017
|
return settings
|
482
1018
|
|
483
1019
|
def get_train_test_model_settings(settings):
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
1020
|
+
"""
|
1021
|
+
Set default args for training and testing a deep learning model.
|
1022
|
+
|
1023
|
+
This function populates the `settings` dictionary with default args used for
|
1024
|
+
training and evaluating deep learning models in spaCR.
|
1025
|
+
|
1026
|
+
Args:
|
1027
|
+
settings (dict): Dictionary to populate with default args.
|
1028
|
+
|
1029
|
+
Returns:
|
1030
|
+
dict: Updated settings dictionary.
|
1031
|
+
|
1032
|
+
Default Args:
|
1033
|
+
src (str): Path to input dataset.
|
1034
|
+
train (bool): Whether to train the model.
|
1035
|
+
test (bool): Whether to test the model.
|
1036
|
+
custom_model (bool): Whether to load a custom model.
|
1037
|
+
classes (list): List of class labels, e.g., ['nc', 'pc'].
|
1038
|
+
train_channels (list): Channels to use for training (e.g., ['r', 'g', 'b']).
|
1039
|
+
model_type (str): Type of model architecture, e.g., 'maxvit_t'.
|
1040
|
+
optimizer_type (str): Optimizer to use, e.g., 'adamw'.
|
1041
|
+
schedule (str): Learning rate schedule ('reduce_lr_on_plateau' or 'step_lr').
|
1042
|
+
loss_type (str): Loss function, e.g., 'focal_loss'.
|
1043
|
+
normalize (bool): Normalize images before training.
|
1044
|
+
image_size (int): Input image size (square).
|
1045
|
+
batch_size (int): Batch size for training.
|
1046
|
+
epochs (int): Number of epochs.
|
1047
|
+
val_split (float): Fraction of training data used for validation.
|
1048
|
+
learning_rate (float): Initial learning rate.
|
1049
|
+
weight_decay (float): Weight decay for regularization.
|
1050
|
+
dropout_rate (float): Dropout rate for model.
|
1051
|
+
init_weights (bool): Whether to initialize model weights.
|
1052
|
+
amsgrad (bool): Use AMSGrad variant of Adam.
|
1053
|
+
use_checkpoint (bool): Whether to use model checkpointing.
|
1054
|
+
gradient_accumulation (bool): Use gradient accumulation across batches.
|
1055
|
+
gradient_accumulation_steps (int): Steps to accumulate gradients before update.
|
1056
|
+
intermedeate_save (bool): Save intermediate models during training.
|
1057
|
+
pin_memory (bool): Enable pinned memory in DataLoader.
|
1058
|
+
n_jobs (int): Number of CPU cores to use.
|
1059
|
+
augment (bool): Whether to apply data augmentation.
|
1060
|
+
verbose (bool): Enable verbose output.
|
1061
|
+
"""
|
1062
|
+
settings.setdefault('src', 'path')
|
1063
|
+
settings.setdefault('train', True)
|
1064
|
+
settings.setdefault('test', False)
|
1065
|
+
settings.setdefault('custom_model', False)
|
1066
|
+
settings.setdefault('classes', ['nc','pc'])
|
1067
|
+
settings.setdefault('train_channels', ['r','g','b'])
|
1068
|
+
settings.setdefault('model_type', 'maxvit_t')
|
1069
|
+
settings.setdefault('optimizer_type', 'adamw')
|
1070
|
+
settings.setdefault('schedule', 'reduce_lr_on_plateau')
|
1071
|
+
settings.setdefault('loss_type', 'focal_loss')
|
1072
|
+
settings.setdefault('normalize', True)
|
1073
|
+
settings.setdefault('image_size', 224)
|
1074
|
+
settings.setdefault('batch_size', 64)
|
1075
|
+
settings.setdefault('epochs', 100)
|
1076
|
+
settings.setdefault('val_split', 0.1)
|
1077
|
+
settings.setdefault('learning_rate', 0.0001)
|
1078
|
+
settings.setdefault('weight_decay', 0.00001)
|
1079
|
+
settings.setdefault('dropout_rate', 0.1)
|
1080
|
+
settings.setdefault('init_weights', True)
|
1081
|
+
settings.setdefault('amsgrad', True)
|
1082
|
+
settings.setdefault('use_checkpoint', True)
|
1083
|
+
settings.setdefault('gradient_accumulation', True)
|
1084
|
+
settings.setdefault('gradient_accumulation_steps', 4)
|
1085
|
+
settings.setdefault('intermedeate_save',True)
|
1086
|
+
settings.setdefault('pin_memory', True)
|
1087
|
+
settings.setdefault('n_jobs', 30)
|
1088
|
+
settings.setdefault('augment', True)
|
1089
|
+
settings.setdefault('verbose', True)
|
1090
|
+
return settings
|
513
1091
|
|
514
1092
|
def get_analyze_recruitment_default_settings(settings):
|
1093
|
+
"""
|
1094
|
+
Set default args for recruitment analysis of host/pathogen protein localization.
|
1095
|
+
|
1096
|
+
This function populates the `settings` dictionary with default values for analyzing
|
1097
|
+
recruitment of host proteins (e.g., ESCRT) to pathogens under various treatment conditions.
|
1098
|
+
|
1099
|
+
Args:
|
1100
|
+
settings (dict): Dictionary to populate with default args.
|
1101
|
+
|
1102
|
+
Returns:
|
1103
|
+
dict: Updated settings dictionary.
|
1104
|
+
|
1105
|
+
Default Args:
|
1106
|
+
src (str): Path to input dataset.
|
1107
|
+
target (str): Protein target being analyzed.
|
1108
|
+
cell_types (list): List of host cell types (e.g., ['HeLa']).
|
1109
|
+
cell_plate_metadata (list or None): Metadata for host cells.
|
1110
|
+
pathogen_types (list): List of pathogen types.
|
1111
|
+
pathogen_plate_metadata (list): Plate layout metadata for pathogens.
|
1112
|
+
treatments (list): List of treatment conditions.
|
1113
|
+
treatment_plate_metadata (list): Plate layout metadata for treatments.
|
1114
|
+
channel_dims (list): List of image channel indices.
|
1115
|
+
cell_chann_dim (int): Index of cell signal channel.
|
1116
|
+
cell_mask_dim (int): Index of cell mask channel.
|
1117
|
+
nucleus_chann_dim (int): Index of nucleus signal channel.
|
1118
|
+
nucleus_mask_dim (int): Index of nucleus mask channel.
|
1119
|
+
pathogen_chann_dim (int): Index of pathogen signal channel.
|
1120
|
+
pathogen_mask_dim (int): Index of pathogen mask channel.
|
1121
|
+
channel_of_interest (int): Channel to analyze for recruitment.
|
1122
|
+
plot (bool): Whether to generate plots.
|
1123
|
+
plot_nr (int): Number of plots to generate.
|
1124
|
+
plot_control (bool): Include controls in plots.
|
1125
|
+
figuresize (int): Size of generated figures.
|
1126
|
+
pathogen_limit (int): Maximum pathogens per field.
|
1127
|
+
nuclei_limit (int): Minimum nuclei required per field.
|
1128
|
+
cells_per_well (int): Expected number of cells per well.
|
1129
|
+
pathogen_size_range (list): Min/max area for pathogen inclusion.
|
1130
|
+
nucleus_size_range (list): Min/max area for nucleus inclusion.
|
1131
|
+
cell_size_range (list): Min/max area for cell inclusion.
|
1132
|
+
pathogen_intensity_range (list): Min/max intensity for pathogen inclusion.
|
1133
|
+
nucleus_intensity_range (list): Min/max intensity for nucleus inclusion.
|
1134
|
+
cell_intensity_range (list): Min/max intensity for cell inclusion.
|
1135
|
+
target_intensity_min (int): Minimum intensity for target signal.
|
1136
|
+
"""
|
515
1137
|
settings.setdefault('src', 'path')
|
516
1138
|
settings.setdefault('target','protein')
|
517
1139
|
settings.setdefault('cell_types',['HeLa'])
|
@@ -546,6 +1168,26 @@ def get_analyze_recruitment_default_settings(settings):
|
|
546
1168
|
return settings
|
547
1169
|
|
548
1170
|
def get_default_test_cellpose_model_settings(settings):
|
1171
|
+
"""
|
1172
|
+
Set default args for testing a Cellpose model.
|
1173
|
+
|
1174
|
+
Args:
|
1175
|
+
settings (dict): Dictionary to populate with default args.
|
1176
|
+
|
1177
|
+
Returns:
|
1178
|
+
dict: Updated settings dictionary.
|
1179
|
+
|
1180
|
+
Default Args:
|
1181
|
+
src (str): Path to input image directory.
|
1182
|
+
model_path (str): Path to the Cellpose model.
|
1183
|
+
save (bool): Whether to save outputs.
|
1184
|
+
normalize (bool): Apply percentile normalization.
|
1185
|
+
percentiles (tuple): Lower and upper percentiles for normalization.
|
1186
|
+
batch_size (int): Number of images to process per batch.
|
1187
|
+
CP_probability (float): Minimum probability for Cellpose mask inclusion.
|
1188
|
+
FT (float): Flow threshold for Cellpose model.
|
1189
|
+
target_size (int): Resize input images to this size for model inference.
|
1190
|
+
"""
|
549
1191
|
settings.setdefault('src','path')
|
550
1192
|
settings.setdefault('model_path','path')
|
551
1193
|
settings.setdefault('save',True)
|
@@ -558,6 +1200,27 @@ def get_default_test_cellpose_model_settings(settings):
|
|
558
1200
|
return settings
|
559
1201
|
|
560
1202
|
def get_default_apply_cellpose_model_settings(settings):
|
1203
|
+
"""
|
1204
|
+
Set default args for applying a trained Cellpose model.
|
1205
|
+
|
1206
|
+
Args:
|
1207
|
+
settings (dict): Dictionary to populate with default args.
|
1208
|
+
|
1209
|
+
Returns:
|
1210
|
+
dict: Updated settings dictionary.
|
1211
|
+
|
1212
|
+
Default Args:
|
1213
|
+
src (str): Path to input image directory.
|
1214
|
+
model_path (str): Path to the Cellpose model.
|
1215
|
+
save (bool): Whether to save outputs.
|
1216
|
+
normalize (bool): Apply percentile normalization.
|
1217
|
+
percentiles (tuple): Lower and upper percentiles for normalization.
|
1218
|
+
batch_size (int): Number of images to process per batch.
|
1219
|
+
CP_probability (float): Minimum probability for Cellpose mask inclusion.
|
1220
|
+
FT (float): Flow threshold for Cellpose model.
|
1221
|
+
circularize (bool): Convert masks to circular contours.
|
1222
|
+
target_size (int): Resize input images to this size for model inference.
|
1223
|
+
"""
|
561
1224
|
settings.setdefault('src','path')
|
562
1225
|
settings.setdefault('model_path','path')
|
563
1226
|
settings.setdefault('save',True)
|
@@ -571,6 +1234,22 @@ def get_default_apply_cellpose_model_settings(settings):
|
|
571
1234
|
return settings
|
572
1235
|
|
573
1236
|
def default_settings_analyze_percent_positive(settings):
|
1237
|
+
"""
|
1238
|
+
Set default args for analyzing percent-positive cells based on intensity thresholding.
|
1239
|
+
|
1240
|
+
Args:
|
1241
|
+
settings (dict): Dictionary to populate with default args.
|
1242
|
+
|
1243
|
+
Returns:
|
1244
|
+
dict: Updated settings dictionary.
|
1245
|
+
|
1246
|
+
Default Args:
|
1247
|
+
src (str): Path to data table.
|
1248
|
+
tables (list): List of object types to analyze (e.g., ['cell']).
|
1249
|
+
filter_1 (list): Filtering rule, e.g., ['cell_area', 1000].
|
1250
|
+
value_col (str): Column name containing intensity values.
|
1251
|
+
threshold (float): Threshold above which objects are considered positive.
|
1252
|
+
"""
|
574
1253
|
settings.setdefault('src','path')
|
575
1254
|
settings.setdefault('tables',['cell'])
|
576
1255
|
settings.setdefault('filter_1',['cell_area',1000])
|
@@ -579,6 +1258,24 @@ def default_settings_analyze_percent_positive(settings):
|
|
579
1258
|
return settings
|
580
1259
|
|
581
1260
|
def get_analyze_reads_default_settings(settings):
|
1261
|
+
"""
|
1262
|
+
Set default args for analyzing NGS reads to extract barcodes.
|
1263
|
+
|
1264
|
+
Args:
|
1265
|
+
settings (dict): Dictionary to populate with default args.
|
1266
|
+
|
1267
|
+
Returns:
|
1268
|
+
dict: Updated settings dictionary.
|
1269
|
+
|
1270
|
+
Default Args:
|
1271
|
+
src (str): Path to FASTQ file or folder.
|
1272
|
+
upstream (str): Sequence upstream of the barcode.
|
1273
|
+
downstream (str): Sequence downstream of the barcode.
|
1274
|
+
barecode_length_1 (int): Length of the first barcode.
|
1275
|
+
barecode_length_2 (int): Length of the second barcode.
|
1276
|
+
chunk_size (int): Number of reads to process per chunk.
|
1277
|
+
test (bool): Enable test mode with limited read parsing.
|
1278
|
+
"""
|
582
1279
|
settings.setdefault('src', 'path')
|
583
1280
|
settings.setdefault('upstream', 'CTTCTGGTAAATGGGGATGTCAAGTT')
|
584
1281
|
settings.setdefault('downstream', 'GTTTAAGAGCTATGCTGGAAACAGCAG') #This is the reverce compliment of the column primer starting from the end #TGCTGTTTAAGAGCTATGCTGGAAACAGCA
|
@@ -589,6 +1286,27 @@ def get_analyze_reads_default_settings(settings):
|
|
589
1286
|
return settings
|
590
1287
|
|
591
1288
|
def get_map_barcodes_default_settings(settings):
|
1289
|
+
"""
|
1290
|
+
Set default args for mapping extracted barcodes to plate, grna, and control metadata.
|
1291
|
+
|
1292
|
+
Args:
|
1293
|
+
settings (dict): Dictionary to populate with default args.
|
1294
|
+
|
1295
|
+
Returns:
|
1296
|
+
dict: Updated settings dictionary.
|
1297
|
+
|
1298
|
+
Default Args:
|
1299
|
+
src (str): Path to barcode read count data.
|
1300
|
+
grna (str): Path to gRNA-barcode mapping CSV.
|
1301
|
+
barcodes (str): Path to screen barcode-to-well metadata CSV.
|
1302
|
+
plate_dict (str): Stringified dictionary mapping plate IDs to logical names.
|
1303
|
+
test (bool): Enable test mode with limited entries.
|
1304
|
+
verbose (bool): Print detailed progress information.
|
1305
|
+
pc (str): Positive control gRNA identifier.
|
1306
|
+
pc_loc (str): Well location of the positive control.
|
1307
|
+
nc (str): Negative control gRNA identifier.
|
1308
|
+
nc_loc (str): Well location of the negative control.
|
1309
|
+
"""
|
592
1310
|
settings.setdefault('src', 'path')
|
593
1311
|
settings.setdefault('grna', '/home/carruthers/Documents/grna_barcodes.csv')
|
594
1312
|
settings.setdefault('barcodes', '/home/carruthers/Documents/SCREEN_BARCODES.csv')
|
@@ -602,6 +1320,31 @@ def get_map_barcodes_default_settings(settings):
|
|
602
1320
|
return settings
|
603
1321
|
|
604
1322
|
def get_train_cellpose_default_settings(settings):
|
1323
|
+
"""
|
1324
|
+
Set default args for training a Cellpose model.
|
1325
|
+
|
1326
|
+
Args:
|
1327
|
+
settings (dict): Dictionary to populate with default args.
|
1328
|
+
|
1329
|
+
Returns:
|
1330
|
+
dict: Updated settings dictionary.
|
1331
|
+
|
1332
|
+
Default Args:
|
1333
|
+
model_name (str): Name to assign to the trained model.
|
1334
|
+
model_type (str): Type of model, e.g., 'cyto', 'nuclei'.
|
1335
|
+
Signal_to_noise (int): Signal-to-noise ratio in training images.
|
1336
|
+
background (int): Background intensity value.
|
1337
|
+
remove_background (bool): Whether to subtract background.
|
1338
|
+
learning_rate (float): Learning rate for optimization.
|
1339
|
+
weight_decay (float): Weight decay (L2 penalty).
|
1340
|
+
batch_size (int): Number of samples per batch.
|
1341
|
+
n_epochs (int): Maximum number of training epochs.
|
1342
|
+
from_scratch (bool): Whether to initialize weights randomly.
|
1343
|
+
diameter (float): Estimated object diameter.
|
1344
|
+
resize (bool): Whether to resize input images.
|
1345
|
+
width_height (list): Target width and height for resizing.
|
1346
|
+
verbose (bool): Print training progress.
|
1347
|
+
"""
|
605
1348
|
settings.setdefault('model_name','new_model')
|
606
1349
|
settings.setdefault('model_type','cyto')
|
607
1350
|
settings.setdefault('Signal_to_noise',10)
|
@@ -619,6 +1362,21 @@ def get_train_cellpose_default_settings(settings):
|
|
619
1362
|
return settings
|
620
1363
|
|
621
1364
|
def set_generate_dataset_defaults(settings):
|
1365
|
+
"""
|
1366
|
+
Set default args for generating a dataset from raw data and metadata.
|
1367
|
+
|
1368
|
+
Args:
|
1369
|
+
settings (dict): Dictionary to populate with default args.
|
1370
|
+
|
1371
|
+
Returns:
|
1372
|
+
dict: Updated settings dictionary.
|
1373
|
+
|
1374
|
+
Default Args:
|
1375
|
+
src (str): Root directory for the experiment.
|
1376
|
+
file_metadata (str or None): Path to metadata CSV file.
|
1377
|
+
experiment (str): Experiment identifier.
|
1378
|
+
sample (str or None): Sample name or ID.
|
1379
|
+
"""
|
622
1380
|
settings.setdefault('src','path')
|
623
1381
|
settings.setdefault('file_metadata',None)
|
624
1382
|
settings.setdefault('experiment','experiment_1')
|
@@ -626,6 +1384,46 @@ def set_generate_dataset_defaults(settings):
|
|
626
1384
|
return settings
|
627
1385
|
|
628
1386
|
def get_perform_regression_default_settings(settings):
|
1387
|
+
"""
|
1388
|
+
Set default args for performing regression on phenotype data.
|
1389
|
+
|
1390
|
+
Args:
|
1391
|
+
settings (dict): Dictionary to populate with default args.
|
1392
|
+
|
1393
|
+
Returns:
|
1394
|
+
dict: Updated settings dictionary.
|
1395
|
+
|
1396
|
+
Default Args:
|
1397
|
+
count_data (list): List of paths to count tables.
|
1398
|
+
score_data (list): List of paths to score tables.
|
1399
|
+
positive_control (str): Gene ID of positive control.
|
1400
|
+
negative_control (str): Gene ID of negative control.
|
1401
|
+
min_n (int): Minimum number of data points per group.
|
1402
|
+
controls (list): List of guide RNA IDs to exclude.
|
1403
|
+
fraction_threshold (float or None): Minimum fraction threshold.
|
1404
|
+
dependent_variable (str): Name of response variable.
|
1405
|
+
threshold_method (str): Method for outlier thresholding (e.g., 'std').
|
1406
|
+
threshold_multiplier (float): Multiplier for thresholding.
|
1407
|
+
target_unique_count (int): Minimum unique guides per gene.
|
1408
|
+
transform (str or None): Apply transformation to input data (e.g., 'log').
|
1409
|
+
log_x (bool): Apply log10 to x-values.
|
1410
|
+
log_y (bool): Apply log10 to y-values.
|
1411
|
+
x_lim (tuple or None): x-axis limits.
|
1412
|
+
outlier_detection (bool): Enable outlier removal.
|
1413
|
+
agg_type (str or None): Aggregation type ('mean', 'median').
|
1414
|
+
min_cell_count (int or None): Minimum cells per sample to include.
|
1415
|
+
regression_type (str): Regression type ('ols', 'quantile').
|
1416
|
+
random_row_column_effects (bool): Include row/column as random effects.
|
1417
|
+
split_axis_lims (str): Delimiter-separated axis ranges for plotting.
|
1418
|
+
cov_type (str or None): Covariance estimator for robust standard errors.
|
1419
|
+
alpha (float): Alpha level or quantile (for quantile regression).
|
1420
|
+
filter_value (list): Values to keep in filter_column.
|
1421
|
+
filter_column (str): Column name for filtering.
|
1422
|
+
plateID (str): Plate ID used in analysis.
|
1423
|
+
metadata_files (list): List of CSVs with gene metadata.
|
1424
|
+
volcano (str): Label column for volcano plot.
|
1425
|
+
toxo (bool): Whether to use Toxoplasma-specific annotations.
|
1426
|
+
"""
|
629
1427
|
settings.setdefault('count_data','list of paths')
|
630
1428
|
settings.setdefault('score_data','list of paths')
|
631
1429
|
settings.setdefault('positive_control','239740')
|
@@ -664,6 +1462,35 @@ def get_perform_regression_default_settings(settings):
|
|
664
1462
|
return settings
|
665
1463
|
|
666
1464
|
def get_check_cellpose_models_default_settings(settings):
|
1465
|
+
"""
|
1466
|
+
Set default args for checking Cellpose model predictions.
|
1467
|
+
|
1468
|
+
Args:
|
1469
|
+
settings (dict): Dictionary to populate with default args.
|
1470
|
+
|
1471
|
+
Returns:
|
1472
|
+
dict: Updated settings dictionary.
|
1473
|
+
|
1474
|
+
Default Args:
|
1475
|
+
batch_size (int): Number of images per batch.
|
1476
|
+
CP_prob (float): Cellpose probability threshold.
|
1477
|
+
flow_threshold (float): Threshold for mask flow consistency.
|
1478
|
+
save (bool): Save output masks to disk.
|
1479
|
+
normalize (bool): Normalize image intensities.
|
1480
|
+
channels (list): Channel indices for [nucleus, cytoplasm].
|
1481
|
+
percentiles (tuple or None): Intensity percentiles for normalization.
|
1482
|
+
invert (bool): Invert image intensities.
|
1483
|
+
plot (bool): Display Cellpose output.
|
1484
|
+
diameter (float): Estimated object diameter.
|
1485
|
+
grayscale (bool): Convert image to grayscale.
|
1486
|
+
remove_background (bool): Subtract background intensity.
|
1487
|
+
background (int): Background value to subtract.
|
1488
|
+
Signal_to_noise (int): Signal-to-noise ratio assumption.
|
1489
|
+
verbose (bool): Print debug info.
|
1490
|
+
resize (bool): Resize image to target dimensions.
|
1491
|
+
target_height (int or None): Resize target height.
|
1492
|
+
target_width (int or None): Resize target width.
|
1493
|
+
"""
|
667
1494
|
settings.setdefault('batch_size', 10)
|
668
1495
|
settings.setdefault('CP_prob', 0)
|
669
1496
|
settings.setdefault('flow_threshold', 0.4)
|
@@ -685,6 +1512,40 @@ def get_check_cellpose_models_default_settings(settings):
|
|
685
1512
|
return settings
|
686
1513
|
|
687
1514
|
def get_identify_masks_finetune_default_settings(settings):
|
1515
|
+
"""
|
1516
|
+
Set default args for identifying masks using fine-tuned Cellpose models.
|
1517
|
+
|
1518
|
+
Args:
|
1519
|
+
settings (dict): Dictionary to populate with default args.
|
1520
|
+
|
1521
|
+
Returns:
|
1522
|
+
dict: Updated settings dictionary.
|
1523
|
+
|
1524
|
+
Default Args:
|
1525
|
+
src (str): Path to input image directory.
|
1526
|
+
model_name (str): Pretrained Cellpose model name (e.g., 'cyto').
|
1527
|
+
custom_model (str or None): Path to a fine-tuned model (.pth).
|
1528
|
+
channels (list): Channel indices [nucleus, cytoplasm].
|
1529
|
+
background (int): Background value to subtract.
|
1530
|
+
remove_background (bool): Whether to subtract background.
|
1531
|
+
Signal_to_noise (int): Assumed SNR of input.
|
1532
|
+
CP_prob (float): Cellpose probability threshold.
|
1533
|
+
diameter (float): Estimated diameter of objects.
|
1534
|
+
batch_size (int): Number of images per batch.
|
1535
|
+
flow_threshold (float): Flow consistency threshold.
|
1536
|
+
save (bool): Save output masks to disk.
|
1537
|
+
verbose (bool): Print debug information.
|
1538
|
+
normalize (bool): Normalize image intensities.
|
1539
|
+
percentiles (tuple or None): Percentile normalization bounds.
|
1540
|
+
invert (bool): Invert intensities.
|
1541
|
+
resize (bool): Resize image to target dimensions.
|
1542
|
+
target_height (int or None): Resize target height.
|
1543
|
+
target_width (int or None): Resize target width.
|
1544
|
+
rescale (bool): Rescale image based on object size.
|
1545
|
+
resample (bool): Resample image for consistent shape.
|
1546
|
+
grayscale (bool): Convert to grayscale.
|
1547
|
+
fill_in (bool): Fill in holes in masks.
|
1548
|
+
"""
|
688
1549
|
settings.setdefault('src', 'path')
|
689
1550
|
settings.setdefault('model_name', 'cyto')
|
690
1551
|
settings.setdefault('custom_model', None)
|
@@ -1046,6 +1907,25 @@ categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset
|
|
1046
1907
|
category_keys = list(categories.keys())
|
1047
1908
|
|
1048
1909
|
def check_settings(vars_dict, expected_types, q=None):
|
1910
|
+
"""
|
1911
|
+
Validate and parse GUI-derived variable inputs according to expected types.
|
1912
|
+
|
1913
|
+
Args:
|
1914
|
+
vars_dict (dict): Dictionary mapping setting keys to a tuple of (label, widget, variable, category).
|
1915
|
+
expected_types (dict): Dictionary of expected types for each setting key.
|
1916
|
+
q (multiprocessing.Queue, optional): Queue to collect error messages. If None, a new queue is created.
|
1917
|
+
|
1918
|
+
Returns:
|
1919
|
+
tuple:
|
1920
|
+
- settings (dict): Parsed settings with values cast to the expected types.
|
1921
|
+
- errors (list): List of error messages describing issues with format or type mismatches.
|
1922
|
+
|
1923
|
+
Notes:
|
1924
|
+
- Supports nested structures such as list of lists and dicts.
|
1925
|
+
- Handles conversions to str, int, float, bool, list, dict, and None.
|
1926
|
+
- Custom parsing is performed for complex input types like Cellpose metadata or PNG config lists.
|
1927
|
+
- Errors are collected and returned without interrupting the full parsing process.
|
1928
|
+
"""
|
1049
1929
|
from .gui_utils import parse_list
|
1050
1930
|
|
1051
1931
|
if q is None:
|
@@ -1161,12 +2041,24 @@ def check_settings(vars_dict, expected_types, q=None):
|
|
1161
2041
|
# Send all collected errors to the queue
|
1162
2042
|
for error in errors:
|
1163
2043
|
q.put(error)
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
2044
|
return settings, errors
|
1168
2045
|
|
1169
2046
|
def generate_fields(variables, scrollable_frame):
|
2047
|
+
"""
|
2048
|
+
Dynamically generate labeled input fields with tooltips in a scrollable Tkinter frame.
|
2049
|
+
|
2050
|
+
Args:
|
2051
|
+
variables (dict): Dictionary mapping setting keys to (var_type, options, default_value).
|
2052
|
+
scrollable_frame (ScrollableFrame): A scrollable frame widget to place the input fields into.
|
2053
|
+
|
2054
|
+
Returns:
|
2055
|
+
vars_dict (dict): Dictionary mapping each setting key to a tuple of (label, widget, variable, parent frame).
|
2056
|
+
|
2057
|
+
Notes:
|
2058
|
+
- Uses `create_input_field` to generate the widgets.
|
2059
|
+
- Attaches tooltips using `spacrToolTip` where available.
|
2060
|
+
- Tooltips describe the expected format, data type, and function of each setting.
|
2061
|
+
"""
|
1170
2062
|
from .gui_utils import create_input_field
|
1171
2063
|
from .gui_elements import spacrToolTip
|
1172
2064
|
row = 1
|
@@ -1477,6 +2369,28 @@ descriptions = {
|
|
1477
2369
|
}
|
1478
2370
|
|
1479
2371
|
def set_annotate_default_settings(settings):
|
2372
|
+
"""
|
2373
|
+
Set default arguments for image annotation and visualization in the annotation tool.
|
2374
|
+
|
2375
|
+
Args:
|
2376
|
+
settings (dict): Dictionary to update with default annotation settings.
|
2377
|
+
|
2378
|
+
Returns:
|
2379
|
+
dict: Updated dictionary containing defaults for:
|
2380
|
+
- src: input path
|
2381
|
+
- image_type: type of image files
|
2382
|
+
- channels: channels to display
|
2383
|
+
- img_size: image display size
|
2384
|
+
- annotation_column: metadata column to use for annotation
|
2385
|
+
- normalize: apply intensity normalization
|
2386
|
+
- normalize_channels: which channels to normalize
|
2387
|
+
- outline: None or comma-separated channel(s) used to generate outline
|
2388
|
+
- outline_threshold_factor: scale factor for thresholding outlines
|
2389
|
+
- outline_sigma: sigma for Gaussian blur during outline generation
|
2390
|
+
- percentiles: intensity normalization range
|
2391
|
+
- measurement: comma-separated measurement columns to display
|
2392
|
+
- threshold: thresholds corresponding to measurement columns
|
2393
|
+
"""
|
1480
2394
|
settings.setdefault('src', 'path')
|
1481
2395
|
settings.setdefault('image_type', 'cell_png')
|
1482
2396
|
settings.setdefault('channels', "r,g,b")
|
@@ -1493,6 +2407,34 @@ def set_annotate_default_settings(settings):
|
|
1493
2407
|
return settings
|
1494
2408
|
|
1495
2409
|
def set_default_generate_barecode_mapping(settings={}):
|
2410
|
+
"""
|
2411
|
+
Sets default settings for barcode mapping from sequencing data.
|
2412
|
+
|
2413
|
+
Args:
|
2414
|
+
settings (dict): A dictionary to populate with default parameters if keys are missing.
|
2415
|
+
|
2416
|
+
Returns:
|
2417
|
+
dict: The updated settings dictionary with default values applied.
|
2418
|
+
|
2419
|
+
Default Settings:
|
2420
|
+
- src (str): Path to input FASTQ files.
|
2421
|
+
- regex (str): Regular expression to extract column, grna, and row barcodes.
|
2422
|
+
- target_sequence (str): Sequence to locate for alignment.
|
2423
|
+
- offset_start (int): Offset to start looking for target sequence.
|
2424
|
+
- expected_end (int): Expected ending position of the barcode pattern.
|
2425
|
+
- column_csv (str): Path to CSV with column barcodes.
|
2426
|
+
- grna_csv (str): Path to CSV with grna barcodes.
|
2427
|
+
- row_csv (str): Path to CSV with row barcodes.
|
2428
|
+
- save_h5 (bool): Whether to save output in HDF5 format.
|
2429
|
+
- comp_type (str): Compression type for HDF5 ('zlib', 'lzf', etc.).
|
2430
|
+
- comp_level (int): Compression level if using zlib (0–9).
|
2431
|
+
- chunk_size (int): Number of reads to process per chunk.
|
2432
|
+
- n_jobs (int or None): Number of parallel jobs to use.
|
2433
|
+
- mode (str): 'paired' for paired-end, 'single' for single-end.
|
2434
|
+
- single_direction (str): 'R1' or 'R2' for direction if mode is 'single'.
|
2435
|
+
- test (bool): Whether to run in test mode.
|
2436
|
+
- fill_na (bool): If True, fill missing barcodes with 'NA'.
|
2437
|
+
"""
|
1496
2438
|
settings.setdefault('src', 'path')
|
1497
2439
|
settings.setdefault('regex', '^(?P<column>.{8})TGCTG.*TAAAC(?P<grna>.{20,21})AACTT.*AGAAG(?P<row>.{8}).*'),
|
1498
2440
|
settings.setdefault('target_sequence', 'TGCTGTTTCCAGCATAGCTCTTAAAC')
|
@@ -1513,6 +2455,34 @@ def set_default_generate_barecode_mapping(settings={}):
|
|
1513
2455
|
return settings
|
1514
2456
|
|
1515
2457
|
def get_default_generate_activation_map_settings(settings):
|
2458
|
+
"""
|
2459
|
+
Sets default settings for generating activation maps (e.g., Grad-CAM) from a trained deep learning model.
|
2460
|
+
|
2461
|
+
Args:
|
2462
|
+
settings (dict): A dictionary to populate with default parameters if keys are missing.
|
2463
|
+
|
2464
|
+
Returns:
|
2465
|
+
dict: The updated settings dictionary with default values applied.
|
2466
|
+
|
2467
|
+
Default Settings:
|
2468
|
+
- dataset (str): Path to dataset directory containing images.
|
2469
|
+
- model_type (str): Type of model architecture used ('maxvit', 'resnet', etc.).
|
2470
|
+
- model_path (str): Path to the trained model checkpoint.
|
2471
|
+
- image_size (int): Size to which input images will be resized.
|
2472
|
+
- batch_size (int): Number of images processed per batch.
|
2473
|
+
- normalize (bool): Whether to normalize input images.
|
2474
|
+
- cam_type (str): Class activation map type ('gradcam', 'gradcam++', etc.).
|
2475
|
+
- target_layer (str or None): Specific layer to target for activation visualization.
|
2476
|
+
- plot (bool): If True, display the activation maps during processing.
|
2477
|
+
- save (bool): If True, save activation map outputs to disk.
|
2478
|
+
- normalize_input (bool): Whether to normalize input images before model inference.
|
2479
|
+
- channels (list): List of channel indices to include in model input.
|
2480
|
+
- overlay (bool): Whether to overlay activation maps on the original images.
|
2481
|
+
- shuffle (bool): If True, shuffle the dataset before processing.
|
2482
|
+
- correlation (bool): If True, compute correlation between channels and activation maps.
|
2483
|
+
- manders_thresholds (list): List of thresholds for Manders’ overlap coefficient.
|
2484
|
+
- n_jobs (int or None): Number of parallel workers to use for processing.
|
2485
|
+
"""
|
1516
2486
|
settings.setdefault('dataset', 'path')
|
1517
2487
|
settings.setdefault('model_type', 'maxvit')
|
1518
2488
|
settings.setdefault('model_path', 'path')
|
@@ -1533,6 +2503,33 @@ def get_default_generate_activation_map_settings(settings):
|
|
1533
2503
|
return settings
|
1534
2504
|
|
1535
2505
|
def get_analyze_plaque_settings(settings):
|
2506
|
+
"""
|
2507
|
+
Sets default settings for analyzing plaque formation using Cellpose segmentation and related image processing tools.
|
2508
|
+
|
2509
|
+
Args:
|
2510
|
+
settings (dict): A dictionary to populate with default parameters if keys are missing.
|
2511
|
+
|
2512
|
+
Returns:
|
2513
|
+
dict: The updated settings dictionary with default values applied.
|
2514
|
+
|
2515
|
+
Default Settings:
|
2516
|
+
- src (str): Path to the directory containing input images.
|
2517
|
+
- masks (bool): Whether to use precomputed masks or generate new ones.
|
2518
|
+
- background (int): Background intensity value to subtract during preprocessing.
|
2519
|
+
- Signal_to_noise (int): Minimum signal-to-noise ratio required for valid segmentation.
|
2520
|
+
- CP_prob (float): Minimum Cellpose probability threshold for mask acceptance.
|
2521
|
+
- diameter (int): Expected object diameter (in pixels) for Cellpose segmentation.
|
2522
|
+
- batch_size (int): Number of images to process per batch.
|
2523
|
+
- flow_threshold (float): Flow error threshold for accepting Cellpose masks.
|
2524
|
+
- save (bool): If True, save the segmentation and analysis outputs to disk.
|
2525
|
+
- verbose (bool): If True, print detailed processing logs.
|
2526
|
+
- resize (bool): Whether to resize images before processing.
|
2527
|
+
- target_height (int): Height to which images should be resized (if `resize` is True).
|
2528
|
+
- target_width (int): Width to which images should be resized (if `resize` is True).
|
2529
|
+
- rescale (bool): Whether to apply rescaling of image intensity values.
|
2530
|
+
- resample (bool): If True, resample images using interpolation methods.
|
2531
|
+
- fill_in (bool): Whether to fill in holes or small gaps in detected masks.
|
2532
|
+
"""
|
1536
2533
|
settings.setdefault('src', 'path')
|
1537
2534
|
settings.setdefault('masks', True)
|
1538
2535
|
settings.setdefault('background', 200)
|
@@ -1552,6 +2549,22 @@ def get_analyze_plaque_settings(settings):
|
|
1552
2549
|
return settings
|
1553
2550
|
|
1554
2551
|
def set_graph_importance_defaults(settings):
|
2552
|
+
"""
|
2553
|
+
Sets default parameters for plotting graph-based feature importance across groups.
|
2554
|
+
|
2555
|
+
Args:
|
2556
|
+
settings (dict): Dictionary to be populated with default values if keys are missing.
|
2557
|
+
|
2558
|
+
Returns:
|
2559
|
+
dict: Updated settings dictionary.
|
2560
|
+
|
2561
|
+
Default Settings:
|
2562
|
+
- csvs (str or list of str): Path(s) to CSV files containing importance scores.
|
2563
|
+
- grouping_column (str): Column name used to group features for plotting (e.g., 'compartment').
|
2564
|
+
- data_column (str): Column name containing the importance values to be plotted.
|
2565
|
+
- graph_type (str): Type of graph to plot. Options may include 'jitter_bar', 'violin', etc.
|
2566
|
+
- save (bool): Whether to save the plot to disk.
|
2567
|
+
"""
|
1555
2568
|
settings.setdefault('csvs','list of paths')
|
1556
2569
|
settings.setdefault('grouping_column','compartment')
|
1557
2570
|
settings.setdefault('data_column','compartment_importance_sum')
|
@@ -1560,6 +2573,31 @@ def set_graph_importance_defaults(settings):
|
|
1560
2573
|
return settings
|
1561
2574
|
|
1562
2575
|
def set_interperate_vision_model_defaults(settings):
|
2576
|
+
"""
|
2577
|
+
Sets default parameters for interpreting vision model outputs using feature importance methods.
|
2578
|
+
|
2579
|
+
Args:
|
2580
|
+
settings (dict): Dictionary to populate with default values for any missing keys.
|
2581
|
+
|
2582
|
+
Returns:
|
2583
|
+
dict: Updated settings dictionary with default interpretation parameters.
|
2584
|
+
|
2585
|
+
Default Settings:
|
2586
|
+
- src (str): Path to input data directory.
|
2587
|
+
- scores (str): Path to model output scores (e.g., predictions or classification results).
|
2588
|
+
- tables (list): List of tables to include in interpretation (e.g., ['cell', 'nucleus', ...]).
|
2589
|
+
- feature_importance (bool): Whether to compute standard feature importance.
|
2590
|
+
- permutation_importance (bool): Whether to compute permutation importance.
|
2591
|
+
- shap (bool): Whether to compute SHAP values for model interpretability.
|
2592
|
+
- save (bool): Whether to save the results to disk.
|
2593
|
+
- nuclei_limit (int): Maximum number of nuclei objects to use for interpretation.
|
2594
|
+
- pathogen_limit (int): Maximum number of pathogen objects to use.
|
2595
|
+
- top_features (int): Number of top features to include in interpretation output.
|
2596
|
+
- shap_sample (bool): Whether to subsample data for SHAP computation.
|
2597
|
+
- n_jobs (int): Number of parallel jobs to use (-1 means all cores).
|
2598
|
+
- shap_approximate (bool): Use approximate SHAP computations for speed.
|
2599
|
+
- score_column (str): Column name from the scores file to use for interpretation.
|
2600
|
+
"""
|
1563
2601
|
settings.setdefault('src','path')
|
1564
2602
|
settings.setdefault('scores','path')
|
1565
2603
|
settings.setdefault('tables',['cell', 'nucleus', 'pathogen','cytoplasm'])
|
@@ -1577,6 +2615,37 @@ def set_interperate_vision_model_defaults(settings):
|
|
1577
2615
|
return settings
|
1578
2616
|
|
1579
2617
|
def set_analyze_endodyogeny_defaults(settings):
|
2618
|
+
"""
|
2619
|
+
Sets default parameters for analyzing endodyogeny (intracellular replication) from segmented object tables.
|
2620
|
+
|
2621
|
+
Args:
|
2622
|
+
settings (dict): Dictionary to populate with default values for any missing keys.
|
2623
|
+
|
2624
|
+
Returns:
|
2625
|
+
dict: Updated settings dictionary with defaults for endodyogeny analysis.
|
2626
|
+
|
2627
|
+
Default Settings:
|
2628
|
+
- src (str): Path to the input directory containing segmentation tables.
|
2629
|
+
- tables (list): List of tables to analyze, typically ['cell', 'nucleus', 'pathogen', 'cytoplasm'].
|
2630
|
+
- cell_types (list): Cell types to include in the analysis, e.g., ['Hela'].
|
2631
|
+
- cell_plate_metadata (list or None): Metadata mapping for cell plates.
|
2632
|
+
- pathogen_types (list): Pathogen class labels, e.g., ['nc', 'pc'].
|
2633
|
+
- pathogen_plate_metadata (list): Metadata defining pathogen class plate layout.
|
2634
|
+
- treatments (list or None): List of treatments or conditions to group by.
|
2635
|
+
- treatment_plate_metadata (list or None): Metadata for treatment layout per plate.
|
2636
|
+
- min_area_bin (int): Minimum object area (in pixels) to consider in binning.
|
2637
|
+
- group_column (str): Column to use for grouping, e.g., 'pathogen'.
|
2638
|
+
- compartment (str): Compartment to analyze, typically 'pathogen'.
|
2639
|
+
- pathogen_limit (int): Max number of pathogens per group for subsampling.
|
2640
|
+
- nuclei_limit (int): Max number of nuclei per group for subsampling.
|
2641
|
+
- level (str): Aggregation level, either 'object' or 'well'.
|
2642
|
+
- um_per_px (float): Microns per pixel for conversion to physical units.
|
2643
|
+
- max_bins (int or None): Optional cap on number of histogram bins.
|
2644
|
+
- save (bool): Whether to save analysis results to file.
|
2645
|
+
- change_plate (bool): Whether to apply plate renaming or normalization.
|
2646
|
+
- cmap (str): Colormap to use for visualization.
|
2647
|
+
- verbose (bool): Whether to print additional processing info.
|
2648
|
+
"""
|
1580
2649
|
settings.setdefault('src','path')
|
1581
2650
|
settings.setdefault('tables',['cell', 'nucleus', 'pathogen', 'cytoplasm'])
|
1582
2651
|
settings.setdefault('cell_types',['Hela'])
|
@@ -1600,6 +2669,33 @@ def set_analyze_endodyogeny_defaults(settings):
|
|
1600
2669
|
return settings
|
1601
2670
|
|
1602
2671
|
def set_analyze_class_proportion_defaults(settings):
|
2672
|
+
"""
|
2673
|
+
Sets default parameters for analyzing the proportion of classification labels
|
2674
|
+
across experimental conditions or cell types.
|
2675
|
+
|
2676
|
+
Args:
|
2677
|
+
settings (dict): Dictionary to populate with default values for any missing keys.
|
2678
|
+
|
2679
|
+
Returns:
|
2680
|
+
dict: Updated settings dictionary with defaults for class proportion analysis.
|
2681
|
+
|
2682
|
+
Default Settings:
|
2683
|
+
- src (str): Path to the input directory containing measurement tables.
|
2684
|
+
- tables (list): List of object tables to analyze (e.g., ['cell', 'nucleus', 'pathogen', 'cytoplasm']).
|
2685
|
+
- cell_types (list): List of cell types to include, e.g., ['Hela'].
|
2686
|
+
- cell_plate_metadata (list or None): Metadata describing layout of cell types on plates.
|
2687
|
+
- pathogen_types (list): List of pathogen labels, typically ['nc', 'pc'].
|
2688
|
+
- pathogen_plate_metadata (list): Metadata describing layout of pathogen classes on plates.
|
2689
|
+
- treatments (list or None): Experimental treatments to group by.
|
2690
|
+
- treatment_plate_metadata (list or None): Metadata describing treatment layouts on plates.
|
2691
|
+
- group_column (str): Metadata column to group by, typically 'condition'.
|
2692
|
+
- class_column (str): Column containing predicted or manual class labels.
|
2693
|
+
- pathogen_limit (int): Max number of pathogen objects to include per group.
|
2694
|
+
- nuclei_limit (int): Max number of nuclei objects to include per group.
|
2695
|
+
- level (str): Aggregation level, e.g., 'well' or 'object'.
|
2696
|
+
- save (bool): Whether to save results to disk.
|
2697
|
+
- verbose (bool): Whether to print processing steps and warnings.
|
2698
|
+
"""
|
1603
2699
|
settings.setdefault('src','path')
|
1604
2700
|
settings.setdefault('tables',['cell', 'nucleus', 'pathogen', 'cytoplasm'])
|
1605
2701
|
settings.setdefault('cell_types',['Hela'])
|
@@ -1618,6 +2714,30 @@ def set_analyze_class_proportion_defaults(settings):
|
|
1618
2714
|
return settings
|
1619
2715
|
|
1620
2716
|
def get_plot_data_from_csv_default_settings(settings):
|
2717
|
+
"""
|
2718
|
+
Sets default parameters for plotting data from a CSV file.
|
2719
|
+
|
2720
|
+
Args:
|
2721
|
+
settings (dict): Dictionary to populate with default values for any missing keys.
|
2722
|
+
|
2723
|
+
Returns:
|
2724
|
+
dict: Updated settings dictionary with default plotting parameters.
|
2725
|
+
|
2726
|
+
Default Settings:
|
2727
|
+
- src (str): Path to the CSV file to be plotted.
|
2728
|
+
- data_column (str): Name of the column containing the data to plot.
|
2729
|
+
- grouping_column (str): Column to group the data by (e.g., experimental condition).
|
2730
|
+
- graph_type (str): Type of plot to generate, e.g., 'violin', 'box', 'bar', or 'strip'.
|
2731
|
+
- save (bool): Whether to save the plot to disk.
|
2732
|
+
- y_lim (tuple or None): Y-axis limits as (min, max), or None for automatic scaling.
|
2733
|
+
- log_y (bool): Whether to use a logarithmic scale on the Y-axis.
|
2734
|
+
- log_x (bool): Whether to use a logarithmic scale on the X-axis.
|
2735
|
+
- keep_groups (list or None): Specific groups to retain in the plot; others will be excluded.
|
2736
|
+
- representation (str): Level of data aggregation, typically 'well' or 'object'.
|
2737
|
+
- theme (str): Visual theme for the plot, e.g., 'dark' or 'light'.
|
2738
|
+
- remove_outliers (bool): Whether to exclude statistical outliers from the plot.
|
2739
|
+
- verbose (bool): Whether to print status messages during plotting.
|
2740
|
+
"""
|
1621
2741
|
settings.setdefault('src','path')
|
1622
2742
|
settings.setdefault('data_column','choose column')
|
1623
2743
|
settings.setdefault('grouping_column','choose column')
|