SURE-tools 2.1.11__tar.gz → 2.1.12__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.11 → sure_tools-2.1.12}/PKG-INFO +1 -1
  2. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/flow/plot_quiver.py +71 -37
  3. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE_tools.egg-info/PKG-INFO +1 -1
  4. {sure_tools-2.1.11 → sure_tools-2.1.12}/setup.py +1 -1
  5. {sure_tools-2.1.11 → sure_tools-2.1.12}/LICENSE +0 -0
  6. {sure_tools-2.1.11 → sure_tools-2.1.12}/README.md +0 -0
  7. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/PerturbFlow.py +0 -0
  8. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/SURE.py +0 -0
  9. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/__init__.py +0 -0
  10. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/assembly/__init__.py +0 -0
  11. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/assembly/assembly.py +0 -0
  12. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/assembly/atlas.py +0 -0
  13. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/atac/__init__.py +0 -0
  14. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/atac/utils.py +0 -0
  15. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/codebook/__init__.py +0 -0
  16. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/codebook/codebook.py +0 -0
  17. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/flow/__init__.py +0 -0
  18. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/flow/flow_stats.py +0 -0
  19. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/perturb/__init__.py +0 -0
  20. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/perturb/perturb.py +0 -0
  21. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/utils/__init__.py +0 -0
  22. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/utils/custom_mlp.py +0 -0
  23. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/utils/queue.py +0 -0
  24. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE/utils/utils.py +0 -0
  25. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE_tools.egg-info/SOURCES.txt +0 -0
  26. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE_tools.egg-info/dependency_links.txt +0 -0
  27. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE_tools.egg-info/entry_points.txt +0 -0
  28. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE_tools.egg-info/requires.txt +0 -0
  29. {sure_tools-2.1.11 → sure_tools-2.1.12}/SURE_tools.egg-info/top_level.txt +0 -0
  30. {sure_tools-2.1.11 → sure_tools-2.1.12}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SURE-tools
3
- Version: 2.1.11
3
+ Version: 2.1.12
4
4
  Summary: Succinct Representation of Single Cells
5
5
  Home-page: https://github.com/ZengFLab/SURE
6
6
  Author: Feng Zeng
@@ -4,6 +4,7 @@ from sklearn.decomposition import PCA
4
4
  import scanpy as sc
5
5
  from matplotlib.colors import ListedColormap
6
6
 
7
+
7
8
  def plot_quiver(z_points, delta_z, method='pca', figsize=(6,4), dpi=200,
8
9
  subsample=None, color_by=None, colormap='viridis',
9
10
  arrow_scale=1.0, arrow_width=0.005, alpha=0.8):
@@ -23,96 +24,129 @@ def plot_quiver(z_points, delta_z, method='pca', figsize=(6,4), dpi=200,
23
24
  arrow_width: 箭头宽度
24
25
  alpha: 透明度
25
26
  """
26
- # 数据采样
27
+ # 保存原始数据用于散点图
28
+ original_z_points = z_points.copy()
29
+ original_delta_z = delta_z.copy()
30
+ original_color_by = color_by.copy() if color_by is not None else None
31
+
32
+ # 数据采样(仅用于quiver)
33
+ quiver_indices = None
27
34
  if subsample is not None and len(z_points) > subsample:
28
- idx = np.random.choice(len(z_points), subsample, replace=False)
29
- z_points = z_points[idx]
30
- delta_z = delta_z[idx]
35
+ quiver_indices = np.random.choice(len(z_points), subsample, replace=False)
36
+ z_points_quiver = z_points[quiver_indices]
37
+ delta_z_quiver = delta_z[quiver_indices]
31
38
  if color_by is not None:
32
- color_by = color_by[idx]
39
+ color_by_quiver = color_by[quiver_indices]
40
+ else:
41
+ color_by_quiver = None
42
+ else:
43
+ z_points_quiver = z_points
44
+ delta_z_quiver = delta_z
45
+ color_by_quiver = color_by
33
46
 
34
- # 降维投影
47
+ # 降维投影(使用所有数据)
35
48
  if method == 'variance':
36
- variances = np.var(z_points, axis=0)
49
+ variances = np.var(original_z_points, axis=0)
37
50
  dims = np.argsort(variances)[-2:]
38
- z_2d = z_points[:, dims]
39
- delta_z_2d = delta_z[:, dims]
51
+ z_2d_all = original_z_points[:, dims]
52
+ z_2d_quiver = z_points_quiver[:, dims]
53
+ delta_z_2d = delta_z_quiver[:, dims]
40
54
  dim_names = [f'z[{d}]' for d in dims]
41
55
 
42
56
  elif method == 'pca':
43
57
  pca = PCA(n_components=2)
44
- z_2d = pca.fit_transform(z_points)
45
- delta_z_2d = pca.transform(z_points + delta_z) - z_2d
58
+ z_2d_all = pca.fit_transform(original_z_points)
59
+ z_2d_quiver = pca.transform(z_points_quiver)
60
+ delta_z_2d = pca.transform(z_points_quiver + delta_z_quiver) - z_2d_quiver
46
61
  dim_names = ['PC1', 'PC2']
47
62
 
48
63
  elif method == 'manual':
49
64
  dims = [0, 1]
50
- z_2d = z_points[:, dims]
51
- delta_z_2d = delta_z[:, dims]
65
+ z_2d_all = original_z_points[:, dims]
66
+ z_2d_quiver = z_points_quiver[:, dims]
67
+ delta_z_2d = delta_z_quiver[:, dims]
52
68
  dim_names = [f'z[{d}]' for d in dims]
53
69
 
54
70
  elif method == 'umap':
55
- ad = sc.AnnData(np.vstack([z_points, z_points+delta_z]))
71
+ # 使用所有数据进行UMAP降维
72
+ ad = sc.AnnData(np.vstack([original_z_points, original_z_points+original_delta_z]))
56
73
  sc.pp.neighbors(ad)
57
74
  sc.tl.umap(ad)
58
- z_2d = ad[:z_points.shape[0]].obsm['X_umap']
59
- delta_z_2d = ad[z_points.shape[0]:].obsm['X_umap'] - z_2d
75
+ z_2d_all = ad[:len(original_z_points)].obsm['X_umap']
76
+ z_2d_quiver = z_2d_all[quiver_indices] if quiver_indices is not None else z_2d_all
77
+ delta_z_2d = ad[len(original_z_points):].obsm['X_umap'][quiver_indices] - z_2d_quiver if quiver_indices is not None else ad[len(original_z_points):].obsm['X_umap'] - z_2d_all
60
78
  dim_names = ['UMAP1', 'UMAP2']
61
79
 
62
- # 颜色处理
63
- if color_by is not None:
80
+ # 颜色处理(散点图使用所有数据,quiver使用采样数据)
81
+ if original_color_by is not None:
64
82
  if isinstance(colormap, str):
65
83
  cmap = plt.get_cmap(colormap)
66
84
  else:
67
85
  cmap = colormap
68
86
 
69
- if color_by.dtype.kind in ['i', 'f']: # 数值型标签
70
- colors = cmap(color_by / max(color_by.max(), 1e-8))
87
+ if original_color_by.dtype.kind in ['i', 'f']: # 数值型标签
88
+ # 所有数据的颜色
89
+ colors_all = cmap(original_color_by / max(original_color_by.max(), 1e-8))
90
+ # quiver数据的颜色
91
+ if color_by_quiver is not None:
92
+ colors_quiver = cmap(color_by_quiver / max(color_by_quiver.max(), 1e-8))
93
+ else:
94
+ colors_quiver = 'blue'
71
95
  cbar_label = 'Numeric Label'
72
96
  else: # 类别型标签
73
- unique_labels = np.unique(color_by)
97
+ unique_labels = np.unique(original_color_by)
74
98
  color_map = {label: cmap(i/len(unique_labels))
75
99
  for i, label in enumerate(unique_labels)}
76
- colors = [color_map[label] for label in color_by]
100
+ colors_all = [color_map[label] for label in original_color_by]
101
+ if color_by_quiver is not None:
102
+ colors_quiver = [color_map[label] for label in color_by_quiver]
103
+ else:
104
+ colors_quiver = 'blue'
77
105
  cbar_label = 'Class Label'
78
106
  else:
79
- colors = 'blue'
107
+ colors_all = 'gray'
108
+ colors_quiver = 'blue'
80
109
 
81
110
  # 绘制
82
111
  plt.figure(figsize=figsize, dpi=dpi)
83
112
 
84
- # 绘制quiver(分颜色组绘制以获得正确图例)
85
- if color_by is not None and isinstance(color_by[0], str):
86
- for label in np.unique(color_by):
87
- mask = color_by == label
88
- plt.quiver(z_2d[mask, 0], z_2d[mask, 1],
113
+ # 1. 首先绘制所有数据点的散点图
114
+ plt.scatter(z_2d_all[:, 0], z_2d_all[:, 1],
115
+ c=colors_all, alpha=0.3, s=5, label='All data points')
116
+
117
+ # 2. 绘制quiver(仅采样数据)
118
+ if color_by_quiver is not None and isinstance(color_by_quiver[0], str):
119
+ for label in np.unique(color_by_quiver):
120
+ mask = color_by_quiver == label
121
+ plt.quiver(z_2d_quiver[mask, 0], z_2d_quiver[mask, 1],
89
122
  delta_z_2d[mask, 0], delta_z_2d[mask, 1],
90
123
  angles='xy', scale_units='xy', scale=1.0/arrow_scale,
91
- color=colors[mask], width=arrow_width, alpha=alpha,
92
- label=str(label))
124
+ color=colors_quiver[mask], width=arrow_width, alpha=alpha,
125
+ label=f'{label} (movement)')
93
126
  plt.legend()
94
127
  else:
95
- q = plt.quiver(z_2d[:, 0], z_2d[:, 1],
128
+ q = plt.quiver(z_2d_quiver[:, 0], z_2d_quiver[:, 1],
96
129
  delta_z_2d[:, 0], delta_z_2d[:, 1],
97
130
  angles='xy', scale_units='xy', scale=1.0/arrow_scale,
98
- color=colors, width=arrow_width, alpha=alpha)
131
+ color=colors_quiver, width=arrow_width, alpha=alpha,
132
+ label='Movement vectors')
99
133
 
100
134
  # 添加颜色条(数值型标签)
101
- if color_by is not None and color_by.dtype.kind in ['i', 'f']:
135
+ if original_color_by is not None and original_color_by.dtype.kind in ['i', 'f']:
102
136
  plt.colorbar(plt.cm.ScalarMappable(
103
- norm=plt.Normalize(color_by.min(), color_by.max()),
137
+ norm=plt.Normalize(original_color_by.min(), original_color_by.max()),
104
138
  cmap=cmap), label=cbar_label)
105
139
 
106
140
  # 美化图形
107
- plt.scatter(z_2d[:, 0], z_2d[:, 1], c='gray', alpha=0.3, s=5)
108
141
  plt.xlabel(dim_names[0])
109
142
  plt.ylabel(dim_names[1])
110
- plt.title(f"Latent Space Movement ({method} projection)")
143
+ plt.title(f"Latent Space Movement ({method} projection)\n{len(z_points_quiver)}/{len(original_z_points)} points with vectors")
111
144
  plt.grid(alpha=0.2)
145
+ plt.legend()
112
146
  plt.tight_layout()
113
147
  plt.show()
114
148
 
115
- return z_2d, delta_z_2d
149
+ return z_2d_all, z_2d_quiver, delta_z_2d
116
150
 
117
151
  def plot_quiver_old(z_points, delta_z, method='pca', figsize=(6,4), dpi=200):
118
152
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SURE-tools
3
- Version: 2.1.11
3
+ Version: 2.1.12
4
4
  Summary: Succinct Representation of Single Cells
5
5
  Home-page: https://github.com/ZengFLab/SURE
6
6
  Author: Feng Zeng
@@ -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.11',
8
+ version='2.1.12',
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