spacr 0.0.80__tar.gz → 0.0.82__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.0.80/spacr.egg-info → spacr-0.0.82}/PKG-INFO +2 -1
- {spacr-0.0.80 → spacr-0.0.82}/setup.py +3 -2
- {spacr-0.0.80 → spacr-0.0.82}/spacr/core.py +6 -7
- {spacr-0.0.80 → spacr-0.0.82}/spacr/io.py +108 -1
- {spacr-0.0.80 → spacr-0.0.82}/spacr/sequencing.py +795 -124
- {spacr-0.0.80 → spacr-0.0.82/spacr.egg-info}/PKG-INFO +2 -1
- {spacr-0.0.80 → spacr-0.0.82}/spacr.egg-info/requires.txt +1 -0
- {spacr-0.0.80 → spacr-0.0.82}/LICENSE +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/MANIFEST.in +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/README.rst +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/setup.cfg +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/__init__.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/__main__.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/annotate_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/chris.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/deep_spacr.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/graph_learning.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/gui.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/gui_2.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/gui_classify_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/gui_mask_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/gui_measure_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/gui_sim_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/gui_utils.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/logger.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/mask_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/measure.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/models/cp/toxo_pv_lumen.CP_model +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/plot.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/sim.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/timelapse.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/utils.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr/version.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr.egg-info/SOURCES.txt +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr.egg-info/dependency_links.txt +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr.egg-info/entry_points.txt +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/spacr.egg-info/top_level.txt +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_annotate_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_core.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_gui_classify_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_gui_mask_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_gui_measure_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_gui_sim_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_gui_utils.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_io.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_mask_app.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_measure.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_plot.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_sim.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_timelapse.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_train.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_umap.py +0 -0
- {spacr-0.0.80 → spacr-0.0.82}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: spacr
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.82
|
4
4
|
Summary: Spatial phenotype analysis of crisp screens (SpaCr)
|
5
5
|
Home-page: https://github.com/EinarOlafsson/spacr
|
6
6
|
Author: Einar Birnir Olafsson
|
@@ -38,6 +38,7 @@ Requires-Dist: PyWavelets<2.0,>=1.6.0
|
|
38
38
|
Requires-Dist: torchcam<1.0,>=0.4.0
|
39
39
|
Requires-Dist: ttf_opensans>=2020.10.30
|
40
40
|
Requires-Dist: customtkinter<6.0,>=5.2.2
|
41
|
+
Requires-Dist: biopython<2.0,>=1.80
|
41
42
|
Requires-Dist: lxml<6.0,>=5.1.0
|
42
43
|
Provides-Extra: dev
|
43
44
|
Requires-Dist: pytest>=3.9; extra == "dev"
|
@@ -50,13 +50,14 @@ dependencies = [
|
|
50
50
|
'PyWavelets>=1.6.0,<2.0',
|
51
51
|
'torchcam>=0.4.0,<1.0',
|
52
52
|
'ttf_opensans>=2020.10.30',
|
53
|
-
'customtkinter>=5.2.2,<6.0',
|
53
|
+
'customtkinter>=5.2.2,<6.0',
|
54
|
+
'biopython>=1.80,<2.0',
|
54
55
|
'lxml>=5.1.0,<6.0'
|
55
56
|
]
|
56
57
|
|
57
58
|
setup(
|
58
59
|
name="spacr",
|
59
|
-
version="0.0.
|
60
|
+
version="0.0.82",
|
60
61
|
author="Einar Birnir Olafsson",
|
61
62
|
author_email="olafsson@med.umich.com",
|
62
63
|
description="Spatial phenotype analysis of crisp screens (SpaCr)",
|
@@ -77,7 +77,7 @@ def analyze_plaques(folder):
|
|
77
77
|
def train_cellpose(settings):
|
78
78
|
|
79
79
|
from .io import _load_normalized_images_and_labels, _load_images_and_labels
|
80
|
-
from .utils import resize_images_and_labels
|
80
|
+
#from .utils import resize_images_and_labels
|
81
81
|
|
82
82
|
img_src = settings['img_src']
|
83
83
|
mask_src = os.path.join(img_src, 'masks')
|
@@ -99,7 +99,6 @@ def train_cellpose(settings):
|
|
99
99
|
Signal_to_noise = settings.setdefault( 'Signal_to_noise', 10)
|
100
100
|
verbose = settings.setdefault( 'verbose', False)
|
101
101
|
|
102
|
-
|
103
102
|
channels = settings.setdefault( 'channels', [0,0])
|
104
103
|
normalize = settings.setdefault( 'normalize', True)
|
105
104
|
percentiles = settings.setdefault( 'percentiles', None)
|
@@ -119,7 +118,7 @@ def train_cellpose(settings):
|
|
119
118
|
test_img_src = os.path.join(os.path.dirname(img_src), 'test')
|
120
119
|
test_mask_src = os.path.join(test_img_src, 'mask')
|
121
120
|
|
122
|
-
test_images, test_masks, test_image_names, test_mask_names = None,None,None,None
|
121
|
+
test_images, test_masks, test_image_names, test_mask_names = None,None,None,None
|
123
122
|
print(settings)
|
124
123
|
|
125
124
|
if from_scratch:
|
@@ -147,13 +146,13 @@ def train_cellpose(settings):
|
|
147
146
|
|
148
147
|
image_files = [os.path.join(img_src, f) for f in os.listdir(img_src) if f.endswith('.tif')]
|
149
148
|
label_files = [os.path.join(mask_src, f) for f in os.listdir(mask_src) if f.endswith('.tif')]
|
150
|
-
images, masks, image_names, mask_names = _load_normalized_images_and_labels(image_files, label_files, channels, percentiles, circular, invert, verbose, remove_background, background, Signal_to_noise)
|
149
|
+
images, masks, image_names, mask_names = _load_normalized_images_and_labels(image_files, label_files, channels, percentiles, circular, invert, verbose, remove_background, background, Signal_to_noise, target_height, target_width)
|
151
150
|
images = [np.squeeze(img) if img.shape[-1] == 1 else img for img in images]
|
152
151
|
|
153
152
|
if test:
|
154
153
|
test_image_files = [os.path.join(test_img_src, f) for f in os.listdir(test_img_src) if f.endswith('.tif')]
|
155
154
|
test_label_files = [os.path.join(test_mask_src, f) for f in os.listdir(test_mask_src) if f.endswith('.tif')]
|
156
|
-
test_images, test_masks, test_image_names, test_mask_names = _load_normalized_images_and_labels(test_image_files, test_label_files, channels, percentiles, circular, invert, verbose, remove_background, background, Signal_to_noise)
|
155
|
+
test_images, test_masks, test_image_names, test_mask_names = _load_normalized_images_and_labels(test_image_files, test_label_files, channels, percentiles, circular, invert, verbose, remove_background, background, Signal_to_noise, target_height, target_width)
|
157
156
|
test_images = [np.squeeze(img) if img.shape[-1] == 1 else img for img in test_images]
|
158
157
|
|
159
158
|
else:
|
@@ -164,8 +163,8 @@ def train_cellpose(settings):
|
|
164
163
|
test_images, test_masks, test_image_names, test_mask_names = _load_images_and_labels(img_src=test_img_src, mask_src=test_mask_src, circular=circular, invert=invert)
|
165
164
|
test_images = [np.squeeze(img) if img.shape[-1] == 1 else img for img in test_images]
|
166
165
|
|
167
|
-
if resize:
|
168
|
-
|
166
|
+
#if resize:
|
167
|
+
# images, masks = resize_images_and_labels(images, masks, target_height, target_width, show_example=True)
|
169
168
|
|
170
169
|
if model_type == 'cyto':
|
171
170
|
cp_channels = [0,1]
|
@@ -87,7 +87,7 @@ def _load_images_and_labels(image_files, label_files, circular=False, invert=Fal
|
|
87
87
|
print(f'image shape: {images[0].shape}, image type: images[0].shape mask shape: {labels[0].shape}, image type: labels[0].shape')
|
88
88
|
return images, labels, image_names, label_names
|
89
89
|
|
90
|
-
def
|
90
|
+
def _load_normalized_images_and_labels_v1(image_files, label_files, channels=None, percentiles=None, circular=False, invert=False, visualize=False, remove_background=False, background=0, Signal_to_noise=10):
|
91
91
|
|
92
92
|
from .plot import normalize_and_visualize
|
93
93
|
from .utils import invert_image, apply_mask
|
@@ -182,6 +182,113 @@ def _load_normalized_images_and_labels(image_files, label_files, channels=None,
|
|
182
182
|
|
183
183
|
return normalized_images, labels, image_names, label_names
|
184
184
|
|
185
|
+
def _load_normalized_images_and_labels(image_files, label_files, channels=None, percentiles=None, circular=False, invert=False, visualize=False, remove_background=False, background=0, Signal_to_noise=10, target_height=None, target_width=None):
|
186
|
+
|
187
|
+
from .plot import normalize_and_visualize, plot_resize
|
188
|
+
from .utils import invert_image, apply_mask
|
189
|
+
from skimage.transform import resize as resizescikit
|
190
|
+
|
191
|
+
signal_thresholds = background * Signal_to_noise
|
192
|
+
lower_percentile = 2
|
193
|
+
|
194
|
+
images = []
|
195
|
+
labels = []
|
196
|
+
|
197
|
+
num_channels = 4
|
198
|
+
percentiles_1 = [[] for _ in range(num_channels)]
|
199
|
+
percentiles_99 = [[] for _ in range(num_channels)]
|
200
|
+
|
201
|
+
image_names = [os.path.basename(f) for f in image_files]
|
202
|
+
image_dir = os.path.dirname(image_files[0])
|
203
|
+
|
204
|
+
if label_files is not None:
|
205
|
+
label_names = [os.path.basename(f) for f in label_files]
|
206
|
+
label_dir = os.path.dirname(label_files[0])
|
207
|
+
|
208
|
+
# Load, normalize, and resize images
|
209
|
+
for i, img_file in enumerate(image_files):
|
210
|
+
image = cellpose.io.imread(img_file)
|
211
|
+
if invert:
|
212
|
+
image = invert_image(image)
|
213
|
+
if circular:
|
214
|
+
image = apply_mask(image, output_value=0)
|
215
|
+
|
216
|
+
# If specific channels are specified, select them
|
217
|
+
if channels is not None and image.ndim == 3:
|
218
|
+
image = image[..., channels]
|
219
|
+
|
220
|
+
if remove_background:
|
221
|
+
image[image < background] = 0
|
222
|
+
|
223
|
+
if image.ndim < 3:
|
224
|
+
image = np.expand_dims(image, axis=-1)
|
225
|
+
|
226
|
+
if percentiles is None:
|
227
|
+
for c in range(image.shape[-1]):
|
228
|
+
p1 = np.percentile(image[..., c], lower_percentile)
|
229
|
+
percentiles_1[c].append(p1)
|
230
|
+
for percentile in [98, 99, 99.9, 99.99, 99.999]:
|
231
|
+
p = np.percentile(image[..., c], percentile)
|
232
|
+
if p > signal_thresholds:
|
233
|
+
percentiles_99[c].append(p)
|
234
|
+
break
|
235
|
+
|
236
|
+
# Resize image
|
237
|
+
if target_height is not None and target_width is not None:
|
238
|
+
if image.ndim == 2:
|
239
|
+
image_shape = (target_height, target_width)
|
240
|
+
elif image.ndim == 3:
|
241
|
+
image_shape = (target_height, target_width, image.shape[-1])
|
242
|
+
|
243
|
+
image = resizescikit(image, image_shape, preserve_range=True, anti_aliasing=True).astype(image.dtype)
|
244
|
+
|
245
|
+
images.append(image)
|
246
|
+
|
247
|
+
if percentiles is None:
|
248
|
+
# Calculate average percentiles for normalization
|
249
|
+
avg_p1 = [np.mean(p) for p in percentiles_1]
|
250
|
+
avg_p99 = [np.mean(p) if len(p) > 0 else np.mean(percentiles_1[i]) for i, p in enumerate(percentiles_99)]
|
251
|
+
|
252
|
+
print(f'Average 1st percentiles: {avg_p1}, Average 99th percentiles: {avg_p99}')
|
253
|
+
|
254
|
+
normalized_images = []
|
255
|
+
for image in images:
|
256
|
+
normalized_image = np.zeros_like(image, dtype=np.float32)
|
257
|
+
for c in range(image.shape[-1]):
|
258
|
+
normalized_image[..., c] = rescale_intensity(image[..., c], in_range=(avg_p1[c], avg_p99[c]), out_range=(0, 1))
|
259
|
+
normalized_images.append(normalized_image)
|
260
|
+
if visualize:
|
261
|
+
normalize_and_visualize(image, normalized_image, title=f"Channel {c+1} Normalized")
|
262
|
+
else:
|
263
|
+
normalized_images = []
|
264
|
+
for image in images:
|
265
|
+
normalized_image = np.zeros_like(image, dtype=np.float32)
|
266
|
+
for c in range(image.shape[-1]):
|
267
|
+
low_p = np.percentile(image[..., c], percentiles[0])
|
268
|
+
high_p = np.percentile(image[..., c], percentiles[1])
|
269
|
+
normalized_image[..., c] = rescale_intensity(image[..., c], in_range=(low_p, high_p), out_range=(0, 1))
|
270
|
+
normalized_images.append(normalized_image)
|
271
|
+
if visualize:
|
272
|
+
normalize_and_visualize(image, normalized_image, title=f"Channel {c+1} Normalized")
|
273
|
+
|
274
|
+
if label_files is not None:
|
275
|
+
for lbl_file in label_files:
|
276
|
+
label = cellpose.io.imread(lbl_file)
|
277
|
+
# Resize label
|
278
|
+
if target_height is not None and target_width is not None:
|
279
|
+
label = resizescikit(label, (target_height, target_width), order=0, preserve_range=True, anti_aliasing=False).astype(label.dtype)
|
280
|
+
labels.append(label)
|
281
|
+
else:
|
282
|
+
label_names = []
|
283
|
+
label_dir = None
|
284
|
+
|
285
|
+
print(f'Loaded and normalized {len(normalized_images)} images and {len(labels)} labels from {image_dir} and {label_dir}')
|
286
|
+
|
287
|
+
if visualize and images and labels:
|
288
|
+
plot_resize(images, normalized_images, labels, labels)
|
289
|
+
|
290
|
+
return normalized_images, labels, image_names, label_names
|
291
|
+
|
185
292
|
class CombineLoaders:
|
186
293
|
|
187
294
|
"""
|