spacr 0.2.5__py3-none-any.whl → 0.2.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spacr/__init__.py +1 -11
- spacr/core.py +226 -287
- spacr/deep_spacr.py +248 -269
- spacr/gui.py +41 -19
- spacr/gui_core.py +404 -151
- spacr/gui_elements.py +778 -179
- spacr/gui_utils.py +163 -106
- spacr/io.py +116 -45
- spacr/measure.py +1 -0
- spacr/plot.py +51 -5
- spacr/sequencing.py +477 -587
- spacr/settings.py +211 -66
- spacr/utils.py +34 -14
- {spacr-0.2.5.dist-info → spacr-0.2.8.dist-info}/METADATA +46 -39
- {spacr-0.2.5.dist-info → spacr-0.2.8.dist-info}/RECORD +19 -19
- {spacr-0.2.5.dist-info → spacr-0.2.8.dist-info}/WHEEL +1 -1
- {spacr-0.2.5.dist-info → spacr-0.2.8.dist-info}/LICENSE +0 -0
- {spacr-0.2.5.dist-info → spacr-0.2.8.dist-info}/entry_points.txt +0 -0
- {spacr-0.2.5.dist-info → spacr-0.2.8.dist-info}/top_level.txt +0 -0
spacr/utils.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import sys, os, re, sqlite3, torch, torchvision, random, string, shutil, cv2, tarfile, glob, psutil, platform
|
1
|
+
import sys, os, re, sqlite3, torch, torchvision, random, string, shutil, cv2, tarfile, glob, psutil, platform, gzip, subprocess
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
from cellpose import models as cp_models
|
@@ -87,6 +87,12 @@ from scipy.stats import f_oneway, kruskal
|
|
87
87
|
from sklearn.cluster import KMeans
|
88
88
|
from scipy import stats
|
89
89
|
|
90
|
+
def save_settings(settings, name='settings'):
|
91
|
+
|
92
|
+
settings_df = pd.DataFrame(list(settings.items()), columns=['Key', 'Value'])
|
93
|
+
settings_csv = os.path.join(settings['src'],'settings',f'{name}.csv')
|
94
|
+
os.makedirs(os.path.join(settings['src'],'settings'), exist_ok=True)
|
95
|
+
settings_df.to_csv(settings_csv, index=False)
|
90
96
|
|
91
97
|
def print_progress(files_processed, files_to_process, n_jobs, time_ls=None, batch_size=None, operation_type=""):
|
92
98
|
if isinstance(files_processed, list):
|
@@ -116,10 +122,9 @@ def print_progress(files_processed, files_to_process, n_jobs, time_ls=None, batc
|
|
116
122
|
else:
|
117
123
|
average_time_img = average_time / batch_size
|
118
124
|
time_info = f'Time/batch: {average_time:.3f}sec, Time/image: {average_time_img:.3f}sec, Time_left: {time_left:.3f} min.'
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
125
|
+
else:
|
126
|
+
time_info = None
|
127
|
+
print(f'Progress: {files_processed}/{files_to_process}, operation_type: {operation_type}, {time_info}')
|
123
128
|
|
124
129
|
def reset_mp():
|
125
130
|
current_method = get_start_method()
|
@@ -1649,7 +1654,7 @@ def split_my_dataset(dataset, split_ratio=0.1):
|
|
1649
1654
|
val_dataset = Subset(dataset, val_indices)
|
1650
1655
|
return train_dataset, val_dataset
|
1651
1656
|
|
1652
|
-
def classification_metrics(all_labels, prediction_pos_probs,
|
1657
|
+
def classification_metrics(all_labels, prediction_pos_probs, loss, epoch):
|
1653
1658
|
"""
|
1654
1659
|
Calculate classification metrics for binary classification.
|
1655
1660
|
|
@@ -1698,11 +1703,9 @@ def classification_metrics(all_labels, prediction_pos_probs, loader_name, loss,
|
|
1698
1703
|
else:
|
1699
1704
|
acc_nc = np.nan
|
1700
1705
|
data_dict = {'accuracy': acc_all, 'neg_accuracy': acc_nc, 'pos_accuracy': acc_pc, 'loss':loss.item(),'prauc':pr_auc, 'optimal_threshold':optimal_threshold}
|
1701
|
-
data_df = pd.DataFrame(data_dict, index=[str(epoch)
|
1706
|
+
data_df = pd.DataFrame(data_dict, index=[str(epoch)])
|
1702
1707
|
return data_df
|
1703
1708
|
|
1704
|
-
|
1705
|
-
|
1706
1709
|
def compute_irm_penalty(losses, dummy_w, device):
|
1707
1710
|
"""
|
1708
1711
|
Computes the Invariant Risk Minimization (IRM) penalty.
|
@@ -1740,7 +1743,7 @@ def compute_irm_penalty(losses, dummy_w, device):
|
|
1740
1743
|
# summary(base_model, (channels, height, width))
|
1741
1744
|
# return
|
1742
1745
|
|
1743
|
-
def choose_model(model_type, device, init_weights=True, dropout_rate=0, use_checkpoint=False, channels=3, height=224, width=224, chan_dict=None, num_classes=2):
|
1746
|
+
def choose_model(model_type, device, init_weights=True, dropout_rate=0, use_checkpoint=False, channels=3, height=224, width=224, chan_dict=None, num_classes=2, verbose=False):
|
1744
1747
|
"""
|
1745
1748
|
Choose a model for classification.
|
1746
1749
|
|
@@ -1772,7 +1775,7 @@ def choose_model(model_type, device, init_weights=True, dropout_rate=0, use_chec
|
|
1772
1775
|
print(f'Invalid model_type: {model_type}. Compatible model_types: {model_types}')
|
1773
1776
|
return
|
1774
1777
|
|
1775
|
-
print(f'
|
1778
|
+
print(f'Model parameters: Architecture: {model_type} init_weights: {init_weights} dropout_rate: {dropout_rate} use_checkpoint: {use_checkpoint}', end='\r', flush=True)
|
1776
1779
|
|
1777
1780
|
if model_type == 'custom':
|
1778
1781
|
|
@@ -1783,8 +1786,8 @@ def choose_model(model_type, device, init_weights=True, dropout_rate=0, use_chec
|
|
1783
1786
|
else:
|
1784
1787
|
print(f'Compatible model_types: {model_types}')
|
1785
1788
|
raise ValueError(f"Invalid model_type: {model_type}")
|
1786
|
-
|
1787
|
-
|
1789
|
+
if verbose:
|
1790
|
+
print(base_model)
|
1788
1791
|
|
1789
1792
|
return base_model
|
1790
1793
|
|
@@ -3449,7 +3452,7 @@ def setup_plot(figuresize, black_background):
|
|
3449
3452
|
fig, ax = plt.subplots(1, 1, figsize=(figuresize, figuresize))
|
3450
3453
|
return fig, ax
|
3451
3454
|
|
3452
|
-
def plot_clusters(ax, embedding, labels, colors, cluster_centers, plot_outlines, plot_points, smooth_lines, figuresize=
|
3455
|
+
def plot_clusters(ax, embedding, labels, colors, cluster_centers, plot_outlines, plot_points, smooth_lines, figuresize=10, dot_size=50, verbose=False):
|
3453
3456
|
unique_labels = np.unique(labels)
|
3454
3457
|
for cluster_label, color, center in zip(unique_labels, colors, cluster_centers):
|
3455
3458
|
cluster_data = embedding[labels == cluster_label]
|
@@ -4424,3 +4427,20 @@ def correct_masks(src):
|
|
4424
4427
|
cell_path = os.path.join(src,'norm_channel_stack', 'cell_mask_stack')
|
4425
4428
|
convert_and_relabel_masks(cell_path)
|
4426
4429
|
_load_and_concatenate_arrays(src, [0,1,2,3], 1, 0, 2)
|
4430
|
+
|
4431
|
+
def count_reads_in_fastq(fastq_file):
|
4432
|
+
count = 0
|
4433
|
+
with gzip.open(fastq_file, "rt") as f:
|
4434
|
+
for _ in f:
|
4435
|
+
count += 1
|
4436
|
+
return count // 4
|
4437
|
+
|
4438
|
+
|
4439
|
+
# Function to determine the CUDA version
|
4440
|
+
def get_cuda_version():
|
4441
|
+
try:
|
4442
|
+
output = subprocess.check_output(['nvcc', '--version'], stderr=subprocess.STDOUT).decode('utf-8')
|
4443
|
+
if 'release' in output:
|
4444
|
+
return output.split('release ')[1].split(',')[0].replace('.', '')
|
4445
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
4446
|
+
return None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: spacr
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.8
|
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
|
@@ -9,47 +9,54 @@ Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
10
10
|
Classifier: Operating System :: OS Independent
|
11
11
|
License-File: LICENSE
|
12
|
-
Requires-Dist: torch
|
13
|
-
Requires-Dist: torchvision
|
14
|
-
Requires-Dist: torch-geometric
|
15
|
-
Requires-Dist: numpy
|
16
|
-
Requires-Dist:
|
17
|
-
Requires-Dist:
|
18
|
-
Requires-Dist:
|
19
|
-
Requires-Dist:
|
20
|
-
Requires-Dist:
|
21
|
-
Requires-Dist:
|
22
|
-
Requires-Dist:
|
23
|
-
Requires-Dist:
|
24
|
-
Requires-Dist:
|
25
|
-
Requires-Dist:
|
26
|
-
Requires-Dist:
|
27
|
-
Requires-Dist:
|
28
|
-
Requires-Dist:
|
29
|
-
Requires-Dist:
|
30
|
-
Requires-Dist:
|
31
|
-
Requires-Dist:
|
32
|
-
Requires-Dist:
|
33
|
-
Requires-Dist:
|
34
|
-
Requires-Dist:
|
35
|
-
Requires-Dist:
|
36
|
-
Requires-Dist:
|
37
|
-
Requires-Dist:
|
38
|
-
Requires-Dist:
|
39
|
-
Requires-Dist:
|
40
|
-
Requires-Dist:
|
41
|
-
Requires-Dist:
|
42
|
-
Requires-Dist:
|
43
|
-
Requires-Dist:
|
44
|
-
Requires-Dist:
|
45
|
-
Requires-Dist:
|
46
|
-
Requires-Dist:
|
12
|
+
Requires-Dist: torch<3.0,>=2.0
|
13
|
+
Requires-Dist: torchvision<1.0,>=0.1
|
14
|
+
Requires-Dist: torch-geometric<3.0,>=2.5
|
15
|
+
Requires-Dist: numpy<2.0,>=1.26.4
|
16
|
+
Requires-Dist: bottleneck<2.0,>=1.3.6
|
17
|
+
Requires-Dist: numexpr<3.0,>=2.8.4
|
18
|
+
Requires-Dist: pandas<3.0,>=2.2.1
|
19
|
+
Requires-Dist: statsmodels<1.0,>=0.14.1
|
20
|
+
Requires-Dist: scikit-image<1.0,>=0.22.0
|
21
|
+
Requires-Dist: scikit-learn<2.0,>=1.4.1
|
22
|
+
Requires-Dist: seaborn<1.0,>=0.13.2
|
23
|
+
Requires-Dist: matplotlib<4.0,>=3.8.3
|
24
|
+
Requires-Dist: shap<1.0,>=0.45.0
|
25
|
+
Requires-Dist: pillow<11.0,>=10.2.0
|
26
|
+
Requires-Dist: imageio<3.0,>=2.34.0
|
27
|
+
Requires-Dist: scipy<2.0,>=1.12.0
|
28
|
+
Requires-Dist: ipywidgets<9.0,>=8.1.2
|
29
|
+
Requires-Dist: mahotas<2.0,>=1.4.13
|
30
|
+
Requires-Dist: btrack<1.0,>=0.6.5
|
31
|
+
Requires-Dist: trackpy<1.0,>=0.6.2
|
32
|
+
Requires-Dist: cellpose<4.0,>=3.0.6
|
33
|
+
Requires-Dist: IPython<9.0,>=8.18.1
|
34
|
+
Requires-Dist: opencv-python-headless<5.0,>=4.9.0.80
|
35
|
+
Requires-Dist: umap-learn<1.0,>=0.5.6
|
36
|
+
Requires-Dist: ttkthemes<4.0,>=3.2.2
|
37
|
+
Requires-Dist: xgboost<3.0,>=2.0.3
|
38
|
+
Requires-Dist: PyWavelets<2.0,>=1.6.0
|
39
|
+
Requires-Dist: torchcam<1.0,>=0.4.0
|
40
|
+
Requires-Dist: ttf-opensans>=2020.10.30
|
41
|
+
Requires-Dist: customtkinter<6.0,>=5.2.2
|
42
|
+
Requires-Dist: biopython<2.0,>=1.80
|
43
|
+
Requires-Dist: lxml<6.0,>=5.1.0
|
44
|
+
Requires-Dist: psutil<6.0,>=5.9.8
|
45
|
+
Requires-Dist: gputil<2.0,>=1.4.0
|
46
|
+
Requires-Dist: gpustat<2.0,>=1.1.1
|
47
|
+
Requires-Dist: pyautogui<1.0,>=0.9.54
|
48
|
+
Requires-Dist: tables<4.0,>=3.8.0
|
49
|
+
Requires-Dist: rapidfuzz<4.0,>=3.9
|
50
|
+
Requires-Dist: keyring<16.0,>=15.1
|
51
|
+
Requires-Dist: screeninfo<1.0,>=0.8.1
|
52
|
+
Requires-Dist: ipykernel
|
53
|
+
Requires-Dist: huggingface-hub<0.25,>=0.24.0
|
47
54
|
Provides-Extra: dev
|
48
|
-
Requires-Dist: pytest
|
55
|
+
Requires-Dist: pytest<3.11,>=3.9; extra == "dev"
|
49
56
|
Provides-Extra: full
|
50
|
-
Requires-Dist: opencv-python
|
57
|
+
Requires-Dist: opencv-python; extra == "full"
|
51
58
|
Provides-Extra: headless
|
52
|
-
Requires-Dist: opencv-python-headless
|
59
|
+
Requires-Dist: opencv-python-headless; extra == "headless"
|
53
60
|
|
54
61
|
.. |Documentation Status| image:: https://readthedocs.org/projects/spacr/badge/?version=latest
|
55
62
|
:target: https://spacr.readthedocs.io/en/latest/?badge=latest
|
@@ -1,4 +1,4 @@
|
|
1
|
-
spacr/__init__.py,sha256=
|
1
|
+
spacr/__init__.py,sha256=8NZIlJOY2OzRCFjXvqusFL7BfyEJwNqB2lL8QNB-Kgo,1141
|
2
2
|
spacr/__main__.py,sha256=bkAJJD2kjIqOP-u1kLvct9jQQCeUXzlEjdgitwi1Lm8,75
|
3
3
|
spacr/app_annotate.py,sha256=nEIL7Fle9CDKGo3sucG_03DgjUQt5W1M1IHBIpVBr08,2171
|
4
4
|
spacr/app_classify.py,sha256=urTP_wlZ58hSyM5a19slYlBxN0PdC-9-ga0hvq8CGWc,165
|
@@ -8,23 +8,23 @@ spacr/app_measure.py,sha256=_K7APYIeOKpV6e_LcqabBjvEi7mfq9Fch8175x1x0k8,162
|
|
8
8
|
spacr/app_sequencing.py,sha256=DjG26jy4cpddnV8WOOAIiExtOe9MleVMY4MFa5uTo5w,157
|
9
9
|
spacr/app_umap.py,sha256=ZWAmf_OsIKbYvolYuWPMYhdlVe-n2CADoJulAizMiEo,153
|
10
10
|
spacr/chris.py,sha256=YlBjSgeZaY8HPy6jkrT_ISAnCMAKVfvCxF0I9eAZLFM,2418
|
11
|
-
spacr/core.py,sha256=
|
12
|
-
spacr/deep_spacr.py,sha256=
|
11
|
+
spacr/core.py,sha256=B2KMyG6IrVtV9d4XQkXVblbvfFhgcMY2o-mtmqDVDic,146519
|
12
|
+
spacr/deep_spacr.py,sha256=a2YewgkQvLV-95NYJAutnojvJmX4S8z_wv6Tb-XIgUI,34484
|
13
13
|
spacr/graph_learning.py,sha256=1tR-ZxvXE3dBz1Saw7BeVFcrsUFu9OlUZeZVifih9eo,13070
|
14
|
-
spacr/gui.py,sha256=
|
15
|
-
spacr/gui_core.py,sha256=
|
16
|
-
spacr/gui_elements.py,sha256=
|
17
|
-
spacr/gui_utils.py,sha256=
|
18
|
-
spacr/io.py,sha256=
|
14
|
+
spacr/gui.py,sha256=RMg0bgbUpO6JwaWuNVMwuVZ18j4WlER3nW0Eaa0YZ30,7883
|
15
|
+
spacr/gui_core.py,sha256=gTgsBzhZ5Q4vl6fT8VwrHWZ6BXWW5FNli8CE3WNMfv0,39986
|
16
|
+
spacr/gui_elements.py,sha256=OA514FUVRKAcdu9CFVOt7UEzn1vztakQ-rDyKqV0b9A,129771
|
17
|
+
spacr/gui_utils.py,sha256=pq_bmZ527S1j2s6McvqMhHNI05hJycBhHM8GY_jH9Ng,30597
|
18
|
+
spacr/io.py,sha256=ZtVNbEom8X8p_KfsuWw0glGwLg6S0CfwwevDPGdfiSc,117342
|
19
19
|
spacr/logger.py,sha256=7Zqr3TuuOQLWT32gYr2q1qvv7x0a2JhLANmZcnBXAW8,670
|
20
|
-
spacr/measure.py,sha256=
|
21
|
-
spacr/plot.py,sha256=
|
22
|
-
spacr/sequencing.py,sha256=
|
23
|
-
spacr/settings.py,sha256=
|
20
|
+
spacr/measure.py,sha256=4rmzH_a5Y0s1qALVi6YRut3xpnkJXs5vzeTPCEf3QS8,54871
|
21
|
+
spacr/plot.py,sha256=xVnbML7WpAEzdJdrLeYRk6aPinZSiV2dLAeu4mh7n0k,73963
|
22
|
+
spacr/sequencing.py,sha256=y7EB8226B0b0gnGXt6jqBaFVATrM1Y89v3rtHb8XR_k,75746
|
23
|
+
spacr/settings.py,sha256=1PE6rQi0JoxbPSwEdEEWlJvrFW-dBkdY0WP461X-4FA,67839
|
24
24
|
spacr/sim.py,sha256=FveaVgBi3eypO2oVB5Dx-v0CC1Ny7UPfXkJiiRRodAk,71212
|
25
25
|
spacr/sim_app.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
26
26
|
spacr/timelapse.py,sha256=KMYCgHzf9LTZe-lWl5mvH2EjbKRE6OhpwdY13wEumGc,39504
|
27
|
-
spacr/utils.py,sha256=
|
27
|
+
spacr/utils.py,sha256=2v0N1GJPqGyhxLJGSl9cGaaLQr04ehzqcOxiD-zQ1WI,189142
|
28
28
|
spacr/version.py,sha256=axH5tnGwtgSnJHb5IDhiu4Zjk5GhLyAEDRe-rnaoFOA,409
|
29
29
|
spacr/resources/font/open_sans/OFL.txt,sha256=bGMoWBRrE2RcdzDiuYiB8A9OVFlJ0sA2imWwce2DAdo,4484
|
30
30
|
"spacr/resources/font/open_sans/OpenSans-Italic-VariableFont_wdth,wght.ttf",sha256=QSoWv9h46CRX_fdlqFM3O2d3-PF3R1srnb4zUezcLm0,580280
|
@@ -92,9 +92,9 @@ spacr/resources/icons/umap.png,sha256=dOLF3DeLYy9k0nkUybiZMe1wzHQwLJFRmgccppw-8b
|
|
92
92
|
spacr/resources/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model,sha256=z8BbHWZPRnE9D_BHO0fBREE85c1vkltDs-incs2ytXQ,26566572
|
93
93
|
spacr/resources/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model_settings.csv,sha256=fBAGuL_B8ERVdVizO3BHozTDSbZUh1yFzsYK3wkQN68,420
|
94
94
|
spacr/resources/models/cp/toxo_pv_lumen.CP_model,sha256=2y_CindYhmTvVwBH39SNILF3rI3x9SsRn6qrMxHy3l0,26562451
|
95
|
-
spacr-0.2.
|
96
|
-
spacr-0.2.
|
97
|
-
spacr-0.2.
|
98
|
-
spacr-0.2.
|
99
|
-
spacr-0.2.
|
100
|
-
spacr-0.2.
|
95
|
+
spacr-0.2.8.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
|
96
|
+
spacr-0.2.8.dist-info/METADATA,sha256=6FX9b07eeM3Ogd2aSrRfgA3qKVW3d321cvsSEonD2Yk,5388
|
97
|
+
spacr-0.2.8.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
|
98
|
+
spacr-0.2.8.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
|
99
|
+
spacr-0.2.8.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
|
100
|
+
spacr-0.2.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|