SURE-tools 2.1.1__py3-none-any.whl → 2.1.3__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/PerturbFlow.py CHANGED
@@ -702,11 +702,11 @@ class PerturbFlow(nn.Module):
702
702
  cb = tensor_to_numpy(cb)
703
703
  return cb
704
704
 
705
- def _get_cell_embedding(self, xs):
705
+ def _get_basis_embedding(self, xs):
706
706
  zns, _ = self.encoder_zn(xs)
707
707
  return zns
708
708
 
709
- def get_cell_embedding(self,
709
+ def get_basis_embedding(self,
710
710
  xs,
711
711
  batch_size: int = 1024):
712
712
  """
SURE/flow/__init__.py CHANGED
@@ -1 +1,2 @@
1
- from .plot_quiver import plot_quiver
1
+ from .plot_quiver import plot_quiver
2
+ from .flow_stats import calculate_direction_stats,calculate_movement_stats,calculate_movement_energy,calculate_movement_divergence
@@ -0,0 +1,78 @@
1
+ import numpy as np
2
+ from scipy.spatial.distance import pdist, squareform
3
+
4
+ def calculate_movement_stats(vectors):
5
+ """
6
+ 计算移动矢量的基本统计量
7
+ """
8
+ # 计算每个矢量的模长(移动距离)
9
+ distances = np.linalg.norm(vectors, axis=1)
10
+
11
+ stats = {
12
+ 'total_movement': np.sum(distances),
13
+ 'mean_distance': np.mean(distances),
14
+ 'median_distance': np.median(distances),
15
+ 'std_distance': np.std(distances),
16
+ 'max_distance': np.max(distances),
17
+ 'min_distance': np.min(distances),
18
+ 'total_points': len(vectors)
19
+ }
20
+
21
+ return stats, distances
22
+
23
+ def calculate_direction_stats(vectors):
24
+ """
25
+ 计算移动方向的一致性
26
+ """
27
+ # 单位向量
28
+ unit_vectors = vectors / np.linalg.norm(vectors, axis=1, keepdims=True)
29
+
30
+ # 平均方向向量
31
+ mean_direction = np.mean(unit_vectors, axis=0)
32
+ mean_direction_norm = np.linalg.norm(mean_direction)
33
+
34
+ # 方向一致性(0-1,1表示完全一致)
35
+ direction_consistency = mean_direction_norm
36
+
37
+ return {
38
+ 'direction_consistency': direction_consistency,
39
+ 'mean_direction': mean_direction,
40
+ 'direction_variance': 1 - direction_consistency # 方向分散度
41
+ }
42
+
43
+ def calculate_movement_energy(vectors, masses=None):
44
+ """
45
+ 计算移动的能量(假设每个点有质量)
46
+ """
47
+ if masses is None:
48
+ masses = np.ones(len(vectors)) # 默认单位质量
49
+
50
+ # 动能 = 0.5 * mass * velocity^2
51
+ speeds_squared = np.sum(vectors**2, axis=1)
52
+ kinetic_energy = 0.5 * masses * speeds_squared
53
+
54
+ return {
55
+ 'total_energy': np.sum(kinetic_energy),
56
+ 'mean_energy': np.mean(kinetic_energy),
57
+ 'energy_std': np.std(kinetic_energy)
58
+ }
59
+
60
+ def calculate_movement_divergence(positions, vectors):
61
+ """
62
+ 计算移动的散度(衡量扩张/收缩)
63
+ """
64
+
65
+ # 计算移动前后的位置
66
+ new_positions = positions + vectors
67
+
68
+ # 计算位置变化的协方差
69
+ orig_cov = np.cov(positions.T)
70
+ new_cov = np.cov(new_positions.T)
71
+
72
+ # 体积变化(行列式比值)
73
+ volume_ratio = np.linalg.det(new_cov) / np.linalg.det(orig_cov)
74
+
75
+ return {
76
+ 'volume_expansion': volume_ratio, # >1扩张, <1收缩
77
+ 'expansion_factor': volume_ratio**(1/positions.shape[1])
78
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SURE-tools
3
- Version: 2.1.1
3
+ Version: 2.1.3
4
4
  Summary: Succinct Representation of Single Cells
5
5
  Home-page: https://github.com/ZengFLab/SURE
6
6
  Author: Feng Zeng
@@ -1,4 +1,4 @@
1
- SURE/PerturbFlow.py,sha256=RQoIhYQJdQpHdY_sMeDuqurbwvm6IX1XH7SVWG6SmS0,51658
1
+ SURE/PerturbFlow.py,sha256=1vnReRD16B5Yq2Qb9d_9-znuGyWBq6pa5iKfKhaxzK4,51660
2
2
  SURE/SURE.py,sha256=_ZOymj24DLQju0Lb90lKspHPmqIUDDzjIEr9t4qgqCI,48364
3
3
  SURE/SURE2.py,sha256=8wlnMwb1xuf9QUksNkWdWx5ZWq-xIy9NLx8RdUnE82o,48501
4
4
  SURE/__init__.py,sha256=xV10iBbh69g4mjBMb1cQxjuHe8e3Aq7pDzkZmx5G754,260
@@ -9,16 +9,17 @@ SURE/atac/__init__.py,sha256=3smP8IKHfwNCd1G_sZH3pKHXuLkLpFuLtjUTUSy7_As,34
9
9
  SURE/atac/utils.py,sha256=m4NYwpy9O5T1pXTzgCOCcmlwrC6GTi-cQ5sm2wZu2O8,4354
10
10
  SURE/codebook/__init__.py,sha256=2T5gjp8JIaBayrXAnOJYSebQHsWprOs87difpR1OPNw,243
11
11
  SURE/codebook/codebook.py,sha256=ZlN6gRX9Gj2D2u3P5KeOsbZri0MoMAiJo9lNeL-MK-I,17117
12
- SURE/flow/__init__.py,sha256=uiF9eyo6sz5qw7fRFiKipaXHboAakeIqVWo8yjkq0B0,36
12
+ SURE/flow/__init__.py,sha256=eIcHeeISEOXEB0zRW-uiRlDz5IEUbA7rZZ1htUxhLVU,167
13
+ SURE/flow/flow_stats.py,sha256=wpIxmOpYPU7YcgxqXKS8EDmnZ3oGh-YdBjiBiEmHcoU,2360
13
14
  SURE/flow/plot_quiver.py,sha256=spcPC0BDpvC-FBk9XIu6rcJI64bS-U-IVmmKLYHHXgs,1865
14
15
  SURE/flow/quiver.py,sha256=_euFqSaRrDoZ_oOabOx20LOoUTJ__XPhLW-vzLNQfAo,1859
15
16
  SURE/utils/__init__.py,sha256=Htqv4KqVKcRiaaTBsR-6yZ4LSlbhbzutjNKXGD9-uds,660
16
17
  SURE/utils/custom_mlp.py,sha256=07TYX1HgxfEjb_3i5MpiZfNhOhx3dKntuwGkrpteWiM,7036
17
18
  SURE/utils/queue.py,sha256=E_5PA5EWcBoGAZj8BkKQnkCK0p4C-4-xcTPqdIXaPXU,1892
18
19
  SURE/utils/utils.py,sha256=IUHjDDtYaAYllCWsZyIzqQwaLul6fJRvHRH4vIYcR-c,8462
19
- sure_tools-2.1.1.dist-info/licenses/LICENSE,sha256=TFHKwmrAViXQbSX5W-NDItkWFjm45HWOeUniDrqmnu0,1065
20
- sure_tools-2.1.1.dist-info/METADATA,sha256=ET1LmoMzkRak6WiRpuGf2dcoY7cLgGoZtNmMkcqi6DU,2650
21
- sure_tools-2.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
- sure_tools-2.1.1.dist-info/entry_points.txt,sha256=-nJI8rVe_qqrR0HmfAODzj-JNfEqCcSsyVh6okSqyHk,83
23
- sure_tools-2.1.1.dist-info/top_level.txt,sha256=BtFTebdiJeqra4r6mm-uEtwVRFLZ_IjYsQ7OnalrOvY,5
24
- sure_tools-2.1.1.dist-info/RECORD,,
20
+ sure_tools-2.1.3.dist-info/licenses/LICENSE,sha256=TFHKwmrAViXQbSX5W-NDItkWFjm45HWOeUniDrqmnu0,1065
21
+ sure_tools-2.1.3.dist-info/METADATA,sha256=FTE9yLoT-6l4LETpjpjlnzA201z3vflub-zDxo_VH_o,2650
22
+ sure_tools-2.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ sure_tools-2.1.3.dist-info/entry_points.txt,sha256=-nJI8rVe_qqrR0HmfAODzj-JNfEqCcSsyVh6okSqyHk,83
24
+ sure_tools-2.1.3.dist-info/top_level.txt,sha256=BtFTebdiJeqra4r6mm-uEtwVRFLZ_IjYsQ7OnalrOvY,5
25
+ sure_tools-2.1.3.dist-info/RECORD,,