SURE-tools 2.1.37__py3-none-any.whl → 2.1.38__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.
Potentially problematic release.
This version of SURE-tools might be problematic. Click here for more details.
- SURE/perturb/perturb.py +57 -0
- {sure_tools-2.1.37.dist-info → sure_tools-2.1.38.dist-info}/METADATA +1 -1
- {sure_tools-2.1.37.dist-info → sure_tools-2.1.38.dist-info}/RECORD +7 -7
- {sure_tools-2.1.37.dist-info → sure_tools-2.1.38.dist-info}/WHEEL +0 -0
- {sure_tools-2.1.37.dist-info → sure_tools-2.1.38.dist-info}/entry_points.txt +0 -0
- {sure_tools-2.1.37.dist-info → sure_tools-2.1.38.dist-info}/licenses/LICENSE +0 -0
- {sure_tools-2.1.37.dist-info → sure_tools-2.1.38.dist-info}/top_level.txt +0 -0
SURE/perturb/perturb.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import re
|
|
2
2
|
import numpy as np
|
|
3
|
+
from numba import njit
|
|
3
4
|
from itertools import chain
|
|
4
5
|
from joblib import Parallel, delayed
|
|
5
6
|
from typing import Literal
|
|
@@ -27,6 +28,20 @@ class LabelMatrix:
|
|
|
27
28
|
|
|
28
29
|
def inverse_transform(self, matrix):
|
|
29
30
|
return matrix_to_labels(matrix=matrix, unique_labels=self.labels_)
|
|
31
|
+
|
|
32
|
+
class DoseMatrix:
|
|
33
|
+
def __init__(self):
|
|
34
|
+
self.labels_ = None
|
|
35
|
+
|
|
36
|
+
def fit_transform(self, labels, label_dose, control_label=None):
|
|
37
|
+
mat, self.labels_ = dose_to_matrix(labels, label_dose)
|
|
38
|
+
|
|
39
|
+
if control_label is not None:
|
|
40
|
+
idx = np.where(self.labels_==control_label)[0]
|
|
41
|
+
mat = np.delete(mat, idx, axis=1)
|
|
42
|
+
self.labels_ = np.delete(self.labels_, idx)
|
|
43
|
+
|
|
44
|
+
return mat
|
|
30
45
|
|
|
31
46
|
def label_to_matrix(labels, sep_pattern=r'[;_\-\s]'):
|
|
32
47
|
"""
|
|
@@ -91,3 +106,45 @@ def parallel_label_to_matrix(labels, sep_pattern=r'[;_\-\s]', n_jobs=4):
|
|
|
91
106
|
def matrix_to_labels(matrix, unique_labels):
|
|
92
107
|
return [';'.join([unique_labels[i] for i in np.where(row)[0]])
|
|
93
108
|
for row in matrix]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@njit(parallel=True)
|
|
117
|
+
def _numba_fill_matrix(dose_matrix, label_indices, label_doses):
|
|
118
|
+
"""Numba 加速的矩阵填充函数"""
|
|
119
|
+
for i in range(len(label_indices)):
|
|
120
|
+
for j, dose in zip(label_indices[i], label_doses[i]):
|
|
121
|
+
dose_matrix[i, j] = dose
|
|
122
|
+
|
|
123
|
+
def dose_to_matrix(labels, label_dose, all_labels=None):
|
|
124
|
+
"""
|
|
125
|
+
使用 Numba 的终极加速版本(需预先安装 numba)
|
|
126
|
+
"""
|
|
127
|
+
if all_labels is None:
|
|
128
|
+
all_labels = sorted(set().union(*labels))
|
|
129
|
+
|
|
130
|
+
label_to_idx = {label: idx for idx, label in enumerate(all_labels)}
|
|
131
|
+
n_samples = len(labels)
|
|
132
|
+
n_labels = len(all_labels)
|
|
133
|
+
dose_matrix = np.zeros((n_samples, n_labels), dtype=np.float64)
|
|
134
|
+
|
|
135
|
+
# 预处理为 Numba 兼容格式
|
|
136
|
+
label_indices = []
|
|
137
|
+
label_doses = []
|
|
138
|
+
for sample_labels in labels:
|
|
139
|
+
indices = []
|
|
140
|
+
doses = []
|
|
141
|
+
if sample_labels:
|
|
142
|
+
for label in sample_labels:
|
|
143
|
+
indices.append(label_to_idx[label])
|
|
144
|
+
doses.append(label_dose[label])
|
|
145
|
+
label_indices.append(np.array(indices, dtype=np.int64))
|
|
146
|
+
label_doses.append(np.array(doses, dtype=np.float64))
|
|
147
|
+
|
|
148
|
+
# 调用 Numba 加速函数
|
|
149
|
+
_numba_fill_matrix(dose_matrix, label_indices, label_doses)
|
|
150
|
+
return dose_matrix,all_labels
|
|
@@ -12,14 +12,14 @@ SURE/flow/__init__.py,sha256=rsAjYsh1xVIrxBCuwOE0Q_6N5th1wBgjJceV0ABPG3c,183
|
|
|
12
12
|
SURE/flow/flow_stats.py,sha256=cBBsPEDpWNMpbzlyQ3f0385RSrX6_5RCH2caOyi4ihM,9908
|
|
13
13
|
SURE/flow/plot_quiver.py,sha256=UbmuScUcgbQHeMmjKmgqxjrIjHhiHx0VWct16UMMwuE,8110
|
|
14
14
|
SURE/perturb/__init__.py,sha256=ouxShhbxZM4r5Gf7GmKiutrsmtyq7QL8rHjhgF0BU08,32
|
|
15
|
-
SURE/perturb/perturb.py,sha256=
|
|
15
|
+
SURE/perturb/perturb.py,sha256=vuE5apV2tRgW6aVaPmGlVeEObNiig_punQET13QSUms,5304
|
|
16
16
|
SURE/utils/__init__.py,sha256=QJUOfrXzdWSmoM0P3LH8oKEHttzCWqpDy2UF0F0dtN4,673
|
|
17
17
|
SURE/utils/custom_mlp.py,sha256=rHnx9jEef02zfCUdbYVCmbuHcDdIBmRgt__wpdpZvYg,8104
|
|
18
18
|
SURE/utils/queue.py,sha256=E_5PA5EWcBoGAZj8BkKQnkCK0p4C-4-xcTPqdIXaPXU,1892
|
|
19
19
|
SURE/utils/utils.py,sha256=IUHjDDtYaAYllCWsZyIzqQwaLul6fJRvHRH4vIYcR-c,8462
|
|
20
|
-
sure_tools-2.1.
|
|
21
|
-
sure_tools-2.1.
|
|
22
|
-
sure_tools-2.1.
|
|
23
|
-
sure_tools-2.1.
|
|
24
|
-
sure_tools-2.1.
|
|
25
|
-
sure_tools-2.1.
|
|
20
|
+
sure_tools-2.1.38.dist-info/licenses/LICENSE,sha256=TFHKwmrAViXQbSX5W-NDItkWFjm45HWOeUniDrqmnu0,1065
|
|
21
|
+
sure_tools-2.1.38.dist-info/METADATA,sha256=sC9emzBRwPVin5Lmmb2a8EgDKZ0_orNky12KqISuzCM,2651
|
|
22
|
+
sure_tools-2.1.38.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
23
|
+
sure_tools-2.1.38.dist-info/entry_points.txt,sha256=-nJI8rVe_qqrR0HmfAODzj-JNfEqCcSsyVh6okSqyHk,83
|
|
24
|
+
sure_tools-2.1.38.dist-info/top_level.txt,sha256=BtFTebdiJeqra4r6mm-uEtwVRFLZ_IjYsQ7OnalrOvY,5
|
|
25
|
+
sure_tools-2.1.38.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|