spacr 0.1.1__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
spacr/gui_wrappers.py ADDED
@@ -0,0 +1,149 @@
1
+ import traceback, matplotlib, spacr
2
+ import matplotlib.pyplot as plt
3
+ matplotlib.use('Agg')
4
+
5
+ fig_queue = None
6
+
7
+ def spacrFigShow_v1():
8
+ """
9
+ Replacement for plt.show() that queues figures instead of displaying them.
10
+ """
11
+ global fig_queue
12
+ fig = plt.gcf()
13
+ fig_queue.put(fig)
14
+ plt.close(fig)
15
+
16
+ def spacrFigShow(fig_queue=None):
17
+ """
18
+ Replacement for plt.show() that queues figures instead of displaying them.
19
+ """
20
+ fig = plt.gcf()
21
+ if fig_queue:
22
+ fig_queue.put(fig)
23
+ else:
24
+ fig.show()
25
+ plt.close(fig)
26
+
27
+ def preprocess_generate_masks_wrapper(settings, q, fig_queue):
28
+ """
29
+ Wraps the measure_crop function to integrate with GUI processes.
30
+
31
+ Parameters:
32
+ - settings: dict, The settings for the measure_crop function.
33
+ - q: multiprocessing.Queue, Queue for logging messages to the GUI.
34
+ - fig_queue: multiprocessing.Queue, Queue for sending figures to the GUI.
35
+ """
36
+
37
+ # Temporarily override plt.show
38
+ original_show = plt.show
39
+ plt.show = lambda: spacrFigShow(fig_queue)
40
+
41
+ try:
42
+ spacr.core.preprocess_generate_masks(src=settings['src'], settings=settings)
43
+ except Exception as e:
44
+ errorMessage = f"Error during processing: {e}"
45
+ q.put(errorMessage)
46
+ traceback.print_exc()
47
+ finally:
48
+ plt.show = original_show
49
+
50
+ def measure_crop_wrapper(settings, q, fig_queue):
51
+ """
52
+ Wraps the measure_crop function to integrate with GUI processes.
53
+
54
+ Parameters:
55
+ - settings: dict, The settings for the measure_crop function.
56
+ - q: multiprocessing.Queue, Queue for logging messages to the GUI.
57
+ - fig_queue: multiprocessing.Queue, Queue for sending figures to the GUI.
58
+ """
59
+
60
+ # Temporarily override plt.show
61
+ original_show = plt.show
62
+ plt.show = lambda: spacrFigShow(fig_queue)
63
+
64
+ try:
65
+ print('start')
66
+ spacr.measure.measure_crop(settings=settings)
67
+ except Exception as e:
68
+ errorMessage = f"Error during processing: {e}"
69
+ q.put(errorMessage)
70
+ traceback.print_exc()
71
+ finally:
72
+ plt.show = original_show
73
+
74
+ def sequencing_wrapper(settings, q, fig_queue):
75
+
76
+ # Temporarily override plt.show
77
+ original_show = plt.show
78
+ plt.show = lambda: spacrFigShow(fig_queue)
79
+
80
+ try:
81
+ spacr.sequencing.analyze_reads(settings=settings)
82
+ except Exception as e:
83
+ errorMessage = f"Error during processing: {e}"
84
+ q.put(errorMessage)
85
+ traceback.print_exc()
86
+ finally:
87
+ plt.show = original_show
88
+
89
+ def umap_wrapper(settings, q, fig_queue):
90
+
91
+ # Temporarily override plt.show
92
+ original_show = plt.show
93
+ plt.show = lambda: spacrFigShow(fig_queue)
94
+
95
+ try:
96
+ spacr.core.generate_image_umap(settings=settings)
97
+ except Exception as e:
98
+ errorMessage = f"Error during processing: {e}"
99
+ q.put(errorMessage)
100
+ traceback.print_exc()
101
+ finally:
102
+ plt.show = original_show
103
+
104
+ def train_test_model_wrapper(settings, q, fig_queue):
105
+ """
106
+ Wraps the measure_crop function to integrate with GUI processes.
107
+
108
+ Parameters:
109
+ - settings: dict, The settings for the measure_crop function.
110
+ - q: multiprocessing.Queue, Queue for logging messages to the GUI.
111
+ - fig_queue: multiprocessing.Queue, Queue for sending figures to the GUI.
112
+ """
113
+
114
+ # Temporarily override plt.show
115
+ original_show = plt.show
116
+ plt.show = lambda: spacrFigShow(fig_queue)
117
+
118
+ try:
119
+ spacr.core.train_test_model(settings['src'], settings=settings)
120
+ except Exception as e:
121
+ errorMessage = f"Error during processing: {e}"
122
+ q.put(errorMessage) # Send the error message to the GUI via the queue
123
+ traceback.print_exc()
124
+ finally:
125
+ plt.show = original_show # Restore the original plt.show function
126
+
127
+
128
+ def run_multiple_simulations_wrapper(settings, q, fig_queue):
129
+ """
130
+ Wraps the run_multiple_simulations function to integrate with GUI processes.
131
+
132
+ Parameters:
133
+ - settings: dict, The settings for the run_multiple_simulations function.
134
+ - q: multiprocessing.Queue, Queue for logging messages to the GUI.
135
+ - fig_queue: multiprocessing.Queue, Queue for sending figures to the GUI.
136
+ """
137
+
138
+ # Temporarily override plt.show
139
+ original_show = plt.show
140
+ plt.show = lambda: spacrFigShow(fig_queue)
141
+
142
+ try:
143
+ spacr.sim.run_multiple_simulations(settings=settings)
144
+ except Exception as e:
145
+ errorMessage = f"Error during processing: {e}"
146
+ q.put(errorMessage) # Send the error message to the GUI via the queue
147
+ traceback.print_exc()
148
+ finally:
149
+ plt.show = original_show # Restore the original plt.show function