spacr 0.1.77__tar.gz → 0.1.81__tar.gz
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-0.1.77/spacr.egg-info → spacr-0.1.81}/PKG-INFO +1 -1
- {spacr-0.1.77 → spacr-0.1.81}/setup.py +1 -1
- {spacr-0.1.77 → spacr-0.1.81}/spacr/gui.py +36 -8
- {spacr-0.1.77 → spacr-0.1.81}/spacr/gui_core.py +147 -42
- {spacr-0.1.77 → spacr-0.1.81}/spacr/gui_elements.py +9 -1
- {spacr-0.1.77 → spacr-0.1.81}/spacr/io.py +1 -1
- {spacr-0.1.77 → spacr-0.1.81}/spacr/measure.py +14 -14
- {spacr-0.1.77 → spacr-0.1.81}/spacr/settings.py +258 -97
- {spacr-0.1.77 → spacr-0.1.81/spacr.egg-info}/PKG-INFO +1 -1
- {spacr-0.1.77 → spacr-0.1.81}/spacr.egg-info/SOURCES.txt +0 -2
- spacr-0.1.77/spacr/gui_run.py +0 -58
- spacr-0.1.77/spacr/gui_wrappers.py +0 -149
- {spacr-0.1.77 → spacr-0.1.81}/LICENSE +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/MANIFEST.in +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/README.rst +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/setup.cfg +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/__init__.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/__main__.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/app_annotate.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/app_classify.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/app_make_masks.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/app_mask.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/app_measure.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/app_sequencing.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/app_umap.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/chris.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/core.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/deep_spacr.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/graph_learning.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/gui_utils.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/logger.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model_settings.csv +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/models/cp/toxo_pv_lumen.CP_model +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/plot.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/sequencing.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/sim.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/sim_app.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/timelapse.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/utils.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr/version.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr.egg-info/dependency_links.txt +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr.egg-info/entry_points.txt +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr.egg-info/requires.txt +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/spacr.egg-info/top_level.txt +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_annotate_app.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_core.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_gui_classify_app.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_gui_mask_app.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_gui_measure_app.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_gui_sim_app.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_gui_utils.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_io.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_mask_app.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_measure.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_plot.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_sim.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_timelapse.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_train.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_umap.py +0 -0
- {spacr-0.1.77 → spacr-0.1.81}/tests/test_utils.py +0 -0
@@ -17,21 +17,33 @@ class MainApp(tk.Tk):
|
|
17
17
|
style = ttk.Style()
|
18
18
|
set_dark_style(style)
|
19
19
|
|
20
|
-
self.
|
20
|
+
self.main_gui_apps = {
|
21
21
|
"Mask": (lambda frame: initiate_root(frame, 'mask'), "Generate cellpose masks for cells, nuclei and pathogen images."),
|
22
22
|
"Measure": (lambda frame: initiate_root(frame, 'measure'), "Measure single object intensity and morphological feature. Crop and save single object image"),
|
23
23
|
"Annotate": (lambda frame: initiate_root(frame, 'annotate'), "Annotation single object images on a grid. Annotations are saved to database."),
|
24
|
-
"Make Masks": (lambda frame: initiate_root(frame, 'make_masks'),"Adjust pre-existing Cellpose models to your specific dataset for improved performance"),
|
24
|
+
"Make Masks": (lambda frame: initiate_root(frame, 'make_masks'), "Adjust pre-existing Cellpose models to your specific dataset for improved performance"),
|
25
25
|
"Classify": (lambda frame: initiate_root(frame, 'classify'), "Train Torch Convolutional Neural Networks (CNNs) or Transformers to classify single object images."),
|
26
|
-
|
27
|
-
|
26
|
+
}
|
27
|
+
|
28
|
+
self.additional_gui_apps = {
|
29
|
+
"Sequencing": (lambda frame: initiate_root(frame, 'sequencing'), "Analyze sequencing data."),
|
30
|
+
"Umap": (lambda frame: initiate_root(frame, 'umap'), "Generate UMAP embeddings with datapoints represented as images."),
|
31
|
+
"Train Cellpose": (lambda frame: initiate_root(frame, 'train_cellpose'), "Train custom Cellpose models."),
|
32
|
+
"ML Analyze": (lambda frame: initiate_root(frame, 'ml_analyze'), "Machine learning analysis of data."),
|
33
|
+
"Cellpose Masks": (lambda frame: initiate_root(frame, 'cellpose_masks'), "Generate Cellpose masks."),
|
34
|
+
"Cellpose All": (lambda frame: initiate_root(frame, 'cellpose_all'), "Run Cellpose on all images."),
|
35
|
+
"Map Barcodes": (lambda frame: initiate_root(frame, 'map_barcodes'), "Map barcodes to data."),
|
36
|
+
"Regression": (lambda frame: initiate_root(frame, 'regression'), "Perform regression analysis."),
|
37
|
+
"Recruitment": (lambda frame: initiate_root(frame, 'recruitment'), "Analyze recruitment data.")
|
28
38
|
}
|
29
39
|
|
30
40
|
self.selected_app = tk.StringVar()
|
31
41
|
self.create_widgets()
|
32
42
|
|
33
|
-
if default_app in self.
|
34
|
-
self.load_app(default_app, self.
|
43
|
+
if default_app in self.main_gui_apps:
|
44
|
+
self.load_app(default_app, self.main_gui_apps[default_app][0])
|
45
|
+
elif default_app in self.additional_gui_apps:
|
46
|
+
self.load_app(default_app, self.additional_gui_apps[default_app][0])
|
35
47
|
|
36
48
|
def create_widgets(self):
|
37
49
|
# Create the menu bar
|
@@ -47,7 +59,7 @@ class MainApp(tk.Tk):
|
|
47
59
|
self.content_frame = tk.Frame(self.canvas, bg="black")
|
48
60
|
self.content_frame.pack(fill=tk.BOTH, expand=True)
|
49
61
|
|
50
|
-
# Create startup screen with buttons for each GUI app
|
62
|
+
# Create startup screen with buttons for each main GUI app and drop-down for additional apps
|
51
63
|
self.create_startup_screen()
|
52
64
|
|
53
65
|
def create_startup_screen(self):
|
@@ -68,7 +80,7 @@ class MainApp(tk.Tk):
|
|
68
80
|
buttons_frame = tk.Frame(self.content_frame, bg="black")
|
69
81
|
buttons_frame.pack(pady=10, expand=True, padx=10)
|
70
82
|
|
71
|
-
for i, (app_name, app_data) in enumerate(self.
|
83
|
+
for i, (app_name, app_data) in enumerate(self.main_gui_apps.items()):
|
72
84
|
app_func, app_desc = app_data
|
73
85
|
|
74
86
|
# Create custom button with text
|
@@ -78,6 +90,17 @@ class MainApp(tk.Tk):
|
|
78
90
|
description_label = tk.Label(buttons_frame, text=app_desc, bg="black", fg="white", wraplength=800, justify="left", font=('Helvetica', 12))
|
79
91
|
description_label.grid(row=i, column=1, pady=10, padx=10, sticky="w")
|
80
92
|
|
93
|
+
# Add drop-down menu for additional apps
|
94
|
+
dropdown_frame = tk.Frame(buttons_frame, bg="black")
|
95
|
+
dropdown_frame.grid(row=len(self.main_gui_apps), column=0, columnspan=2, pady=20)
|
96
|
+
|
97
|
+
tk.Label(dropdown_frame, text="Additional Apps", bg="black", fg="white", font=('Helvetica', 12)).pack(side=tk.LEFT, padx=5)
|
98
|
+
self.additional_apps_var = tk.StringVar(value="Select an app")
|
99
|
+
dropdown = ttk.Combobox(dropdown_frame, textvariable=self.additional_apps_var, values=list(self.additional_gui_apps.keys()))
|
100
|
+
dropdown.pack(side=tk.LEFT, padx=5)
|
101
|
+
load_button = spacrButton(dropdown_frame, text="Load", command=self.load_additional_app, font=('Helvetica', 12))
|
102
|
+
load_button.pack(side=tk.LEFT, padx=5)
|
103
|
+
|
81
104
|
# Ensure buttons have a fixed width
|
82
105
|
buttons_frame.grid_columnconfigure(0, minsize=150)
|
83
106
|
# Ensure descriptions expand as needed
|
@@ -135,6 +158,11 @@ class MainApp(tk.Tk):
|
|
135
158
|
app_frame.pack(fill=tk.BOTH, expand=True)
|
136
159
|
app_func(app_frame)
|
137
160
|
|
161
|
+
def load_additional_app(self):
|
162
|
+
selected_app = self.additional_apps_var.get()
|
163
|
+
if selected_app in self.additional_gui_apps:
|
164
|
+
self.load_app(selected_app, self.additional_gui_apps[selected_app][0])
|
165
|
+
|
138
166
|
def clear_frame(self, frame):
|
139
167
|
for widget in frame.winfo_children():
|
140
168
|
widget.destroy()
|
@@ -1,27 +1,24 @@
|
|
1
|
-
import os, traceback, ctypes, matplotlib, requests, csv
|
1
|
+
import os, traceback, ctypes, matplotlib, requests, csv, matplotlib, time, requests
|
2
|
+
import matplotlib.pyplot as plt
|
2
3
|
matplotlib.use('Agg')
|
3
4
|
import tkinter as tk
|
4
5
|
from tkinter import ttk
|
5
6
|
from tkinter import filedialog
|
6
|
-
from multiprocessing import Process, Value, Queue
|
7
|
+
from multiprocessing import Process, Value, Queue, set_start_method
|
7
8
|
from multiprocessing.sharedctypes import Synchronized
|
8
|
-
from multiprocessing import set_start_method
|
9
9
|
from tkinter import ttk, scrolledtext
|
10
10
|
from matplotlib.figure import Figure
|
11
11
|
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
12
|
-
import time
|
13
|
-
import requests
|
14
12
|
from huggingface_hub import list_repo_files
|
15
13
|
|
16
|
-
from .settings import set_default_train_test_model, get_measure_crop_settings, set_default_settings_preprocess_generate_masks, get_analyze_reads_default_settings, set_default_umap_image_settings
|
17
|
-
from .gui_elements import create_menu_bar, spacrButton, spacrLabel, spacrFrame, spacrDropdownMenu ,set_dark_style, set_default_font
|
18
|
-
from . gui_run import run_mask_gui, run_measure_gui, run_classify_gui, run_sequencing_gui, run_umap_gui
|
19
|
-
|
20
14
|
try:
|
21
15
|
ctypes.windll.shcore.SetProcessDpiAwareness(True)
|
22
16
|
except AttributeError:
|
23
17
|
pass
|
24
18
|
|
19
|
+
from .settings import set_default_train_test_model, get_measure_crop_settings, set_default_settings_preprocess_generate_masks, get_analyze_reads_default_settings, set_default_umap_image_settings
|
20
|
+
from .gui_elements import create_menu_bar, spacrButton, spacrLabel, spacrFrame, spacrDropdownMenu ,set_dark_style, set_default_font
|
21
|
+
|
25
22
|
# Define global variables
|
26
23
|
q = None
|
27
24
|
console_output = None
|
@@ -44,26 +41,116 @@ def initiate_abort():
|
|
44
41
|
thread_control["run_thread"].join()
|
45
42
|
thread_control["run_thread"] = None
|
46
43
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
44
|
+
def spacrFigShow(fig_queue=None):
|
45
|
+
"""
|
46
|
+
Replacement for plt.show() that queues figures instead of displaying them.
|
47
|
+
"""
|
48
|
+
fig = plt.gcf()
|
49
|
+
if fig_queue:
|
50
|
+
fig_queue.put(fig)
|
51
|
+
else:
|
52
|
+
fig.show()
|
53
|
+
plt.close(fig)
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
def function_gui_wrapper(function=None, settings={}, q=None, fig_queue=None, imports=1):
|
56
|
+
|
57
|
+
"""
|
58
|
+
Wraps the run_multiple_simulations function to integrate with GUI processes.
|
59
|
+
|
60
|
+
Parameters:
|
61
|
+
- settings: dict, The settings for the run_multiple_simulations function.
|
62
|
+
- q: multiprocessing.Queue, Queue for logging messages to the GUI.
|
63
|
+
- fig_queue: multiprocessing.Queue, Queue for sending figures to the GUI.
|
64
|
+
"""
|
65
|
+
|
66
|
+
# Temporarily override plt.show
|
67
|
+
original_show = plt.show
|
68
|
+
plt.show = lambda: spacrFigShow(fig_queue)
|
69
|
+
|
70
|
+
try:
|
71
|
+
if imports == 1:
|
72
|
+
function(settings=settings)
|
73
|
+
elif imports == 2:
|
74
|
+
function(src=settings['src'], settings=settings)
|
75
|
+
except Exception as e:
|
76
|
+
# Send the error message to the GUI via the queue
|
77
|
+
errorMessage = f"Error during processing: {e}"
|
78
|
+
q.put(errorMessage)
|
79
|
+
traceback.print_exc()
|
80
|
+
finally:
|
81
|
+
# Restore the original plt.show function
|
82
|
+
plt.show = original_show
|
83
|
+
|
84
|
+
def run_function_gui(settings_type, settings, q, fig_queue, stop_requested):
|
85
|
+
from .gui_utils import process_stdout_stderr
|
86
|
+
from .core import preprocess_generate_masks, generate_ml_scores, identify_masks_finetune, check_cellpose_models, analyze_recruitment, train_cellpose, compare_cellpose_masks, analyze_plaques, generate_dataset, apply_model_to_tar
|
87
|
+
from .io import generate_cellpose_train_test
|
88
|
+
from .measure import measure_crop
|
89
|
+
from .sim import run_multiple_simulations
|
90
|
+
from .deep_spacr import train_test_model
|
91
|
+
from .sequencing import analyze_reads, map_barcodes_folder, perform_regression
|
92
|
+
process_stdout_stderr(q)
|
93
|
+
|
56
94
|
if settings_type == 'mask':
|
57
|
-
|
95
|
+
function = preprocess_generate_masks
|
96
|
+
imports = 2
|
58
97
|
elif settings_type == 'measure':
|
59
|
-
|
60
|
-
|
61
|
-
|
98
|
+
function = measure_crop
|
99
|
+
imports = 1
|
100
|
+
elif settings_type == 'simulation':
|
101
|
+
function = run_multiple_simulations
|
102
|
+
imports = 1
|
62
103
|
elif settings_type == 'sequencing':
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
104
|
+
function = analyze_reads
|
105
|
+
imports = 1
|
106
|
+
elif settings_type == 'classify':
|
107
|
+
function = train_test_model
|
108
|
+
imports = 2
|
109
|
+
elif settings_type == 'train_cellpose':
|
110
|
+
function = train_cellpose
|
111
|
+
imports = 1
|
112
|
+
elif settings_type == 'ml_analyze':
|
113
|
+
function = generate_ml_scores
|
114
|
+
imports = 2
|
115
|
+
elif settings_type == 'cellpose_masks':
|
116
|
+
function = identify_masks_finetune
|
117
|
+
imports = 1
|
118
|
+
elif settings_type == 'cellpose_all':
|
119
|
+
function = check_cellpose_models
|
120
|
+
imports = 1
|
121
|
+
elif settings_type == 'map_barcodes':
|
122
|
+
function = map_barcodes_folder
|
123
|
+
imports = 2
|
124
|
+
elif settings_type == 'regression':
|
125
|
+
function = perform_regression
|
126
|
+
imports = 2
|
127
|
+
elif settings_type == 'recruitment':
|
128
|
+
function = analyze_recruitment
|
129
|
+
imports = 2
|
130
|
+
#elif settings_type == 'cellpose_dataset':
|
131
|
+
# function = generate_cellpose_train_test
|
132
|
+
# imports = 1
|
133
|
+
#elif settings_type == 'plaques':
|
134
|
+
# function = analyze_plaques
|
135
|
+
# imports = 1
|
136
|
+
#elif settings_type == 'cellpose_compare':
|
137
|
+
# function = compare_cellpose_masks
|
138
|
+
# imports = 1
|
139
|
+
#elif settings_type == 'vision_scores':
|
140
|
+
# function = apply_model_to_tar
|
141
|
+
# imports = 1
|
142
|
+
#elif settings_type == 'vision_dataset':
|
143
|
+
# function = generate_dataset
|
144
|
+
# imports = 1
|
145
|
+
else:
|
146
|
+
raise ValueError(f"Invalid settings type: {settings_type}")
|
147
|
+
try:
|
148
|
+
function_gui_wrapper(function, settings, q, fig_queue, imports)
|
149
|
+
except Exception as e:
|
150
|
+
q.put(f"Error during processing: {e}")
|
151
|
+
traceback.print_exc()
|
152
|
+
finally:
|
153
|
+
stop_requested.value = 1
|
67
154
|
|
68
155
|
def start_process(q=None, fig_queue=None, settings_type='mask'):
|
69
156
|
global thread_control, vars_dict
|
@@ -83,25 +170,15 @@ def start_process(q=None, fig_queue=None, settings_type='mask'):
|
|
83
170
|
if thread_control.get("run_thread") is not None:
|
84
171
|
initiate_abort()
|
85
172
|
|
86
|
-
stop_requested = Value('i', 0)
|
173
|
+
stop_requested = Value('i', 0)
|
87
174
|
thread_control["stop_requested"] = stop_requested
|
88
175
|
|
89
|
-
process_args = (settings, q, fig_queue, stop_requested)
|
90
|
-
|
91
|
-
|
92
|
-
thread_control["run_thread"] = Process(target=run_mask_gui, args=process_args)
|
93
|
-
elif settings_type == 'measure':
|
94
|
-
thread_control["run_thread"] = Process(target=run_measure_gui, args=process_args)
|
95
|
-
elif settings_type == 'classify':
|
96
|
-
thread_control["run_thread"] = Process(target=run_classify_gui, args=process_args)
|
97
|
-
elif settings_type == 'sequencing':
|
98
|
-
thread_control["run_thread"] = Process(target=run_sequencing_gui, args=process_args)
|
99
|
-
elif settings_type == 'umap':
|
100
|
-
thread_control["run_thread"] = Process(target=run_umap_gui, args=process_args)
|
176
|
+
process_args = (settings_type, settings, q, fig_queue, stop_requested)
|
177
|
+
if settings_type in ['mask','measure','simulation','sequencing','classify','cellpose_dataset','train_cellpose','ml_analyze','cellpose_masks','cellpose_all','map_barcodes','regression','recruitment','plaques','cellpose_compare','vision_scores','vision_dataset']:
|
178
|
+
thread_control["run_thread"] = Process(target=run_function_gui, args=process_args)
|
101
179
|
else:
|
102
180
|
q.put(f"Error: Unknown settings type '{settings_type}'")
|
103
181
|
return
|
104
|
-
|
105
182
|
thread_control["run_thread"].start()
|
106
183
|
|
107
184
|
def import_settings(settings_type='mask'):
|
@@ -194,7 +271,7 @@ def convert_settings_dict_for_gui(settings):
|
|
194
271
|
|
195
272
|
def setup_settings_panel(vertical_container, settings_type='mask', window_dimensions=[500, 1000]):
|
196
273
|
global vars_dict, scrollable_frame
|
197
|
-
from .settings import set_default_settings_preprocess_generate_masks, get_measure_crop_settings, set_default_train_test_model, get_analyze_reads_default_settings, set_default_umap_image_settings, generate_fields,
|
274
|
+
from .settings import descriptions, get_identify_masks_finetune_default_settings, set_default_analyze_screen, set_default_settings_preprocess_generate_masks, get_measure_crop_settings, set_default_train_test_model, get_analyze_reads_default_settings, set_default_umap_image_settings, generate_fields, get_perform_regression_default_settings, get_train_cellpose_default_settings, get_map_barcodes_default_settings, get_analyze_recruitment_default_settings, get_check_cellpose_models_default_settings
|
198
275
|
|
199
276
|
width = (window_dimensions[0])//6
|
200
277
|
height = window_dimensions[1]
|
@@ -219,9 +296,36 @@ def setup_settings_panel(vertical_container, settings_type='mask', window_dimens
|
|
219
296
|
settings = get_analyze_reads_default_settings(settings={})
|
220
297
|
elif settings_type == 'umap':
|
221
298
|
settings = set_default_umap_image_settings(settings={})
|
299
|
+
elif settings_type == 'train_cellpose':
|
300
|
+
settings = get_train_cellpose_default_settings(settings={})
|
301
|
+
elif settings_type == 'ml_analyze':
|
302
|
+
settings = set_default_analyze_screen(settings={})
|
303
|
+
elif settings_type == 'cellpose_masks':
|
304
|
+
settings = get_identify_masks_finetune_default_settings(settings={})
|
305
|
+
elif settings_type == 'cellpose_all':
|
306
|
+
settings = get_check_cellpose_models_default_settings(settings={})
|
307
|
+
elif settings_type == 'map_barcodes':
|
308
|
+
settings = get_map_barcodes_default_settings(settings={})
|
309
|
+
elif settings_type == 'regression':
|
310
|
+
settings = get_perform_regression_default_settings(settings={})
|
311
|
+
elif settings_type == 'recruitment':
|
312
|
+
settings = get_analyze_recruitment_default_settings(settings={})
|
313
|
+
#elif settings_type == 'simulation':
|
314
|
+
# settings = set_default_
|
315
|
+
#elif settings_type == 'cellpose_dataset':
|
316
|
+
# settings = set_default_
|
317
|
+
#elif settings_type == 'plaques':
|
318
|
+
# settings = set_default_
|
319
|
+
#elif settings_type == 'cellpose_compare':
|
320
|
+
# settings = set_default_
|
321
|
+
#elif settings_type == 'vision_scores':
|
322
|
+
# settings = set_default_
|
323
|
+
#elif settings_type == 'vision_dataset':
|
324
|
+
# settings = set_default_
|
222
325
|
else:
|
223
326
|
raise ValueError(f"Invalid settings type: {settings_type}")
|
224
327
|
|
328
|
+
|
225
329
|
variables = convert_settings_dict_for_gui(settings)
|
226
330
|
vars_dict = generate_fields(variables, scrollable_frame)
|
227
331
|
print("Settings panel setup complete")
|
@@ -402,8 +506,9 @@ def setup_button_section(horizontal_container, settings_type='mask', window_dim
|
|
402
506
|
# Description frame
|
403
507
|
description_frame = tk.Frame(horizontal_container, bg='black', height=height, width=width)
|
404
508
|
horizontal_container.add(description_frame, stretch="always", sticky="nsew")
|
405
|
-
|
406
|
-
description_label.
|
509
|
+
description_frame.grid_columnconfigure(0, weight=1) # Make the column stretch
|
510
|
+
description_label = tk.Label(description_frame, text="Module Description", bg='black', fg='white', anchor='nw', justify='left', wraplength=width-50)
|
511
|
+
description_label.grid(row=0, column=0, pady=50, padx=20, sticky='nsew') # Use sticky='nsew' to stretch the label
|
407
512
|
description_text = descriptions.get(settings_type, "No description available for this module.")
|
408
513
|
description_label.config(text=description_text)
|
409
514
|
|
@@ -1439,7 +1439,14 @@ def create_menu_bar(root):
|
|
1439
1439
|
"Make Masks": (lambda frame: initiate_root(frame, 'make_masks'), "Adjust pre-existing Cellpose models to your specific dataset for improved performance"),
|
1440
1440
|
"Classify": (lambda frame: initiate_root(frame, 'classify'), "Train Torch Convolutional Neural Networks (CNNs) or Transformers to classify single object images."),
|
1441
1441
|
"Sequencing": (lambda frame: initiate_root(frame, 'sequencing'), "Analyze sequencing data."),
|
1442
|
-
"Umap": (lambda frame: initiate_root(frame, 'umap'), "Generate UMAP embeddings with datapoints represented as images.")
|
1442
|
+
"Umap": (lambda frame: initiate_root(frame, 'umap'), "Generate UMAP embeddings with datapoints represented as images."),
|
1443
|
+
"Train Cellpose": (lambda frame: initiate_root(frame, 'train_cellpose'), "Train custom Cellpose models."),
|
1444
|
+
"ML Analyze": (lambda frame: initiate_root(frame, 'ml_analyze'), "Machine learning analysis of data."),
|
1445
|
+
"Cellpose Masks": (lambda frame: initiate_root(frame, 'cellpose_masks'), "Generate Cellpose masks."),
|
1446
|
+
"Cellpose All": (lambda frame: initiate_root(frame, 'cellpose_all'), "Run Cellpose on all images."),
|
1447
|
+
"Map Barcodes": (lambda frame: initiate_root(frame, 'map_barcodes'), "Map barcodes to data."),
|
1448
|
+
"Regression": (lambda frame: initiate_root(frame, 'regression'), "Perform regression analysis."),
|
1449
|
+
"Recruitment": (lambda frame: initiate_root(frame, 'recruitment'), "Analyze recruitment data.")
|
1443
1450
|
}
|
1444
1451
|
|
1445
1452
|
def load_app_wrapper(app_name, app_func):
|
@@ -1460,6 +1467,7 @@ def create_menu_bar(root):
|
|
1460
1467
|
# Configure the menu for the root window
|
1461
1468
|
root.config(menu=menu_bar)
|
1462
1469
|
|
1470
|
+
|
1463
1471
|
def set_dark_style(style):
|
1464
1472
|
font_style = tkFont.Font(family="Helvetica", size=24)
|
1465
1473
|
style.configure('TEntry', padding='5 5 5 5', borderwidth=1, relief='solid', fieldbackground='black', foreground='#ffffff', font=font_style)
|
@@ -1693,7 +1693,7 @@ def _save_settings_to_db(settings):
|
|
1693
1693
|
settings_df['setting_value'] = settings_df['setting_value'].apply(str)
|
1694
1694
|
display(settings_df)
|
1695
1695
|
# Determine the directory path
|
1696
|
-
src = os.path.dirname(settings['
|
1696
|
+
src = os.path.dirname(settings['src'])
|
1697
1697
|
directory = f'{src}/measurements'
|
1698
1698
|
# Create the directory if it doesn't exist
|
1699
1699
|
os.makedirs(directory, exist_ok=True)
|
@@ -610,7 +610,7 @@ def _measure_crop_core(index, time_ls, file, settings):
|
|
610
610
|
|
611
611
|
start = time.time()
|
612
612
|
try:
|
613
|
-
source_folder = os.path.dirname(settings['
|
613
|
+
source_folder = os.path.dirname(settings['src'])
|
614
614
|
#if not os.path.basename(source_folder).endswith('merged'):
|
615
615
|
# source_folder = os.path.join(source_folder, 'merged')
|
616
616
|
# print(f'changed source_folder to {source_folder}')
|
@@ -619,7 +619,7 @@ def _measure_crop_core(index, time_ls, file, settings):
|
|
619
619
|
# return
|
620
620
|
|
621
621
|
file_name = os.path.splitext(file)[0]
|
622
|
-
data = np.load(os.path.join(settings['
|
622
|
+
data = np.load(os.path.join(settings['src'], file))
|
623
623
|
data_type = data.dtype
|
624
624
|
if data_type not in ['uint8','uint16']:
|
625
625
|
data_type_before = data_type
|
@@ -663,7 +663,7 @@ def _measure_crop_core(index, time_ls, file, settings):
|
|
663
663
|
cell_mask, nucleus_mask = _relabel_parent_with_child_labels(cell_mask, nucleus_mask)
|
664
664
|
data[:, :, settings['cell_mask_dim']] = cell_mask
|
665
665
|
data[:, :, settings['nucleus_mask_dim']] = nucleus_mask
|
666
|
-
save_folder = settings['
|
666
|
+
save_folder = settings['src']
|
667
667
|
np.save(os.path.join(save_folder, file), data)
|
668
668
|
else:
|
669
669
|
nucleus_mask = np.zeros_like(data[:, :, 0])
|
@@ -941,13 +941,13 @@ def measure_crop(settings):
|
|
941
941
|
settings = get_measure_crop_settings(settings)
|
942
942
|
settings = measure_test_mode(settings)
|
943
943
|
|
944
|
-
#src_fldr = settings['
|
944
|
+
#src_fldr = settings['src']
|
945
945
|
#if not os.path.basename(src_fldr).endswith('merged'):
|
946
|
-
# settings['
|
947
|
-
# print(f"changed
|
946
|
+
# settings['src'] = os.path.join(src_fldr, 'merged')
|
947
|
+
# print(f"changed src to {src_fldr}")
|
948
948
|
|
949
|
-
#if not os.path.exists(settings['
|
950
|
-
# print(f'
|
949
|
+
#if not os.path.exists(settings['src']):
|
950
|
+
# print(f'src: {settings["src"]} does not exist')
|
951
951
|
# return
|
952
952
|
|
953
953
|
if settings['cell_mask_dim'] is None:
|
@@ -961,7 +961,7 @@ def measure_crop(settings):
|
|
961
961
|
else:
|
962
962
|
settings['cytoplasm'] = False
|
963
963
|
|
964
|
-
dirname = os.path.dirname(settings['
|
964
|
+
dirname = os.path.dirname(settings['src'])
|
965
965
|
settings_df = pd.DataFrame(list(settings.items()), columns=['Key', 'Value'])
|
966
966
|
settings_csv = os.path.join(dirname,'settings','measure_crop_settings.csv')
|
967
967
|
os.makedirs(os.path.join(dirname,'settings'), exist_ok=True)
|
@@ -997,7 +997,7 @@ def measure_crop(settings):
|
|
997
997
|
|
998
998
|
_save_settings_to_db(settings)
|
999
999
|
|
1000
|
-
files = [f for f in os.listdir(settings['
|
1000
|
+
files = [f for f in os.listdir(settings['src']) if f.endswith('.npy')]
|
1001
1001
|
n_jobs = settings['n_jobs'] or mp.cpu_count()-4
|
1002
1002
|
print(f'using {n_jobs} cpu cores')
|
1003
1003
|
|
@@ -1018,7 +1018,7 @@ def measure_crop(settings):
|
|
1018
1018
|
|
1019
1019
|
if settings['representative_images']:
|
1020
1020
|
if settings['save_png']:
|
1021
|
-
img_fldr = os.path.join(os.path.dirname(settings['
|
1021
|
+
img_fldr = os.path.join(os.path.dirname(settings['src']), 'data')
|
1022
1022
|
sc_img_fldrs = _list_endpoint_subdirectories(img_fldr)
|
1023
1023
|
|
1024
1024
|
for i, well_src in enumerate(sc_img_fldrs):
|
@@ -1037,7 +1037,7 @@ def measure_crop(settings):
|
|
1037
1037
|
#traceback.print_exc()
|
1038
1038
|
|
1039
1039
|
if settings['save_measurements']:
|
1040
|
-
db_path = os.path.join(os.path.dirname(settings['
|
1040
|
+
db_path = os.path.join(os.path.dirname(settings['src']), 'measurements', 'measurements.db')
|
1041
1041
|
channel_indices = settings['png_dims']
|
1042
1042
|
channel_indices = [min(value, 2) for value in channel_indices]
|
1043
1043
|
_generate_representative_images(db_path,
|
@@ -1061,13 +1061,13 @@ def measure_crop(settings):
|
|
1061
1061
|
|
1062
1062
|
if settings['timelapse']:
|
1063
1063
|
if settings['timelapse_objects'] == 'nucleus':
|
1064
|
-
folder_path = settings['
|
1064
|
+
folder_path = settings['src']
|
1065
1065
|
mask_channels = [settings['nucleus_mask_dim'], settings['pathogen_mask_dim'],settings['cell_mask_dim']]
|
1066
1066
|
object_types = ['nucleus','pathogen','cell']
|
1067
1067
|
_timelapse_masks_to_gif(folder_path, mask_channels, object_types)
|
1068
1068
|
|
1069
1069
|
#if settings['save_png']:
|
1070
|
-
img_fldr = os.path.join(os.path.dirname(settings['
|
1070
|
+
img_fldr = os.path.join(os.path.dirname(settings['src']), 'data')
|
1071
1071
|
sc_img_fldrs = _list_endpoint_subdirectories(img_fldr)
|
1072
1072
|
_scmovie(sc_img_fldrs)
|
1073
1073
|
print("Successfully completed run")
|