SURE-tools 2.1.6__tar.gz → 2.1.7__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.

Potentially problematic release.


This version of SURE-tools might be problematic. Click here for more details.

Files changed (30) hide show
  1. {sure_tools-2.1.6 → sure_tools-2.1.7}/PKG-INFO +1 -1
  2. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/__init__.py +2 -1
  3. sure_tools-2.1.7/SURE/perturb/__init__.py +1 -0
  4. sure_tools-2.1.7/SURE/perturb/perturb.py +68 -0
  5. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE_tools.egg-info/PKG-INFO +1 -1
  6. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE_tools.egg-info/SOURCES.txt +2 -0
  7. {sure_tools-2.1.6 → sure_tools-2.1.7}/setup.py +1 -1
  8. {sure_tools-2.1.6 → sure_tools-2.1.7}/LICENSE +0 -0
  9. {sure_tools-2.1.6 → sure_tools-2.1.7}/README.md +0 -0
  10. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/PerturbFlow.py +0 -0
  11. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/SURE.py +0 -0
  12. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/assembly/__init__.py +0 -0
  13. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/assembly/assembly.py +0 -0
  14. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/assembly/atlas.py +0 -0
  15. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/atac/__init__.py +0 -0
  16. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/atac/utils.py +0 -0
  17. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/codebook/__init__.py +0 -0
  18. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/codebook/codebook.py +0 -0
  19. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/flow/__init__.py +0 -0
  20. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/flow/flow_stats.py +0 -0
  21. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/flow/plot_quiver.py +0 -0
  22. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/utils/__init__.py +0 -0
  23. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/utils/custom_mlp.py +0 -0
  24. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/utils/queue.py +0 -0
  25. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE/utils/utils.py +0 -0
  26. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE_tools.egg-info/dependency_links.txt +0 -0
  27. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE_tools.egg-info/entry_points.txt +0 -0
  28. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE_tools.egg-info/requires.txt +0 -0
  29. {sure_tools-2.1.6 → sure_tools-2.1.7}/SURE_tools.egg-info/top_level.txt +0 -0
  30. {sure_tools-2.1.6 → sure_tools-2.1.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SURE-tools
3
- Version: 2.1.6
3
+ Version: 2.1.7
4
4
  Summary: Succinct Representation of Single Cells
5
5
  Home-page: https://github.com/ZengFLab/SURE
6
6
  Author: Feng Zeng
@@ -7,5 +7,6 @@ from . import SURE
7
7
  from . import PerturbFlow
8
8
  from . import atac
9
9
  from . import flow
10
+ from . import perturb
10
11
 
11
- __all__ = ['SURE', 'PerturbFlow', 'flow', 'atac', 'utils', 'codebook']
12
+ __all__ = ['SURE', 'PerturbFlow', 'flow', 'perturb', 'atac', 'utils', 'codebook']
@@ -0,0 +1 @@
1
+ from .perturb import label_to_matrix, matrix_to_labels, vectorized_label_to_matrix, parallel_label_to_matrix
@@ -0,0 +1,68 @@
1
+ import re
2
+ import numpy as np
3
+ from itertools import chain
4
+ from joblib import Parallel, delayed
5
+
6
+ def label_to_matrix(labels, sep_pattern=r'[;_\-\s]'):
7
+ """
8
+ 将混合分隔符的多标签数据转换为 0-1 矩阵
9
+
10
+ Args:
11
+ labels: 原始标签列表,如 ["cat", "dog", "cat;dog", "bird_dog"]
12
+ sep_pattern: 多标签分隔符的正则模式(默认匹配 ; _ - 和空格)
13
+
14
+ Returns:
15
+ one_hot_matrix: 0-1 矩阵
16
+ unique_labels: 唯一标签列表
17
+ """
18
+ # 统一分隔符
19
+ labels_unified = [re.sub(sep_pattern, ';', label) for label in labels]
20
+
21
+ # 获取所有唯一标签
22
+ all_unique_labels = sorted(set(chain(*[label.split(';') for label in labels_unified])))
23
+
24
+ # 生成 0-1 矩阵
25
+ matrix = np.zeros((len(labels), len(all_unique_labels)), dtype=int)
26
+ label_to_idx = {label: i for i, label in enumerate(all_unique_labels)}
27
+
28
+ for i, label in enumerate(labels_unified):
29
+ for sub_label in label.split(';'):
30
+ if sub_label in label_to_idx:
31
+ matrix[i, label_to_idx[sub_label]] = 1
32
+
33
+ return matrix, all_unique_labels
34
+
35
+
36
+ def vectorized_label_to_matrix(labels, sep_pattern=r'[;_\-\s]'):
37
+ labels_unified = [re.sub(sep_pattern, ';', label) for label in labels]
38
+ unique_labels = sorted(set(chain(*[label.split(';') for label in labels_unified])))
39
+
40
+ # 向量化操作
41
+ label_matrix = np.array([label.split(';') for label in labels_unified], dtype=object)
42
+ matrix = np.zeros((len(labels), len(unique_labels)), dtype=int)
43
+
44
+ for i, label in enumerate(unique_labels):
45
+ matrix[:, i] = np.array([label in lst for lst in label_matrix], dtype=int)
46
+
47
+ return matrix, unique_labels
48
+
49
+
50
+
51
+ def parallel_label_to_matrix(labels, n_jobs=4):
52
+ labels_unified = [re.sub(r'[;_\-\s]', ';', label) for label in labels]
53
+ unique_labels = sorted(set(chain(*[label.split(';') for label in labels_unified])))
54
+
55
+ def process_row(row_labels, unique_labels):
56
+ return [1 if label in row_labels else 0 for label in unique_labels]
57
+
58
+ label_lists = [label.split(';') for label in labels_unified]
59
+ matrix = Parallel(n_jobs=n_jobs)(
60
+ delayed(process_row)(row, unique_labels) for row in label_lists
61
+ )
62
+
63
+ return np.array(matrix, dtype=int), unique_labels
64
+
65
+
66
+ def matrix_to_labels(matrix, unique_labels):
67
+ return [';'.join([unique_labels[i] for i in np.where(row)[0]])
68
+ for row in matrix]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SURE-tools
3
- Version: 2.1.6
3
+ Version: 2.1.7
4
4
  Summary: Succinct Representation of Single Cells
5
5
  Home-page: https://github.com/ZengFLab/SURE
6
6
  Author: Feng Zeng
@@ -14,6 +14,8 @@ SURE/codebook/codebook.py
14
14
  SURE/flow/__init__.py
15
15
  SURE/flow/flow_stats.py
16
16
  SURE/flow/plot_quiver.py
17
+ SURE/perturb/__init__.py
18
+ SURE/perturb/perturb.py
17
19
  SURE/utils/__init__.py
18
20
  SURE/utils/custom_mlp.py
19
21
  SURE/utils/queue.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name='SURE-tools',
8
- version='2.1.6',
8
+ version='2.1.7',
9
9
  description='Succinct Representation of Single Cells',
10
10
  long_description=long_description,
11
11
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes