sciv 0.0.81__py3-none-any.whl → 0.0.83__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.
sciv/tool/_algorithm_.py CHANGED
@@ -1153,7 +1153,7 @@ def calculate_init_score_weight(
1153
1153
 
1154
1154
  del global_scale_data
1155
1155
 
1156
- da_peaks_adata.obsm["cluster_weight"] = to_sparse(_cluster_weight_)
1156
+ da_peaks_adata.obsm["cluster_weight"] = to_dense(_cluster_weight_, is_array=True)
1157
1157
  del _cluster_weight_
1158
1158
 
1159
1159
  ul.log(__name__).info("Broadcasting the weight factor to the cellular level")
@@ -1163,9 +1163,7 @@ def calculate_init_score_weight(
1163
1163
 
1164
1164
  for cluster in da_peaks_adata.obs_names:
1165
1165
  mask = cluster_series == cluster
1166
- _cell_type_weight_[mask, :] = to_dense(
1167
- da_peaks_adata[cluster, :].obsm["cluster_weight"], is_array=True
1168
- ).flatten().astype(np.float32)
1166
+ _cell_type_weight_[mask, :] = da_peaks_adata[cluster, :].obsm["cluster_weight"].flatten().astype(np.float32)
1169
1167
 
1170
1168
  ul.log(__name__).info("Calculate initial trait relevance scores")
1171
1169
  _init_trs_weight_ = np.multiply(_init_trs_ncw_, _cell_type_weight_)
sciv/tool/_matrix_.py CHANGED
@@ -449,10 +449,10 @@ def matrix_operation_memory_efficient(
449
449
  result_chunk = chunk1.multiply(chunk2)
450
450
  elif operation == '/':
451
451
  # Sparse matrix division: convert to dense, perform element-wise division, then convert back to sparse
452
- dense_chunk1 = chunk1.todense()
452
+ dense_chunk1 = chunk1 if isinstance(chunk1, dense_data) else chunk1.todense()
453
453
 
454
454
  if isinstance(data2, matrix_data):
455
- dense_chunk2 = chunk2.todense()
455
+ dense_chunk2 = chunk2 if isinstance(chunk2, dense_data) else chunk2.todense()
456
456
  dense_chunk2[dense_chunk2 == 0] = default
457
457
  else:
458
458
  dense_chunk2 = data2
@@ -23,14 +23,16 @@ from ..util import (
23
23
  collection,
24
24
  check_adata_get,
25
25
  enrichment_optional,
26
- check_gpu_availability
26
+ check_gpu_availability,
27
+ dense_data,
28
+ sparse_data
27
29
  )
28
30
 
29
31
  __name__: str = "tool_random_walk"
30
32
 
31
33
 
32
34
  def _random_walk_cpu_(
33
- seed_cell_vector: collection,
35
+ seed_cell_vector: Union[list, np.ndarray, np.matrix],
34
36
  weight: matrix_data = None,
35
37
  gamma: float = 0.05,
36
38
  epsilon: float = 1e-5,
@@ -46,17 +48,19 @@ def _random_walk_cpu_(
46
48
  :return: The value after random walk.
47
49
  """
48
50
 
49
- w = to_dense(weight)
50
-
51
51
  # Random walk
52
- p0 = seed_cell_vector.copy()[:, np.newaxis]
52
+ p0 = np.asarray(seed_cell_vector, dtype=float).ravel()[:, np.newaxis]
53
53
  pt: matrix_data = p0.copy()
54
54
  k = 0
55
55
  delta = 1
56
56
 
57
57
  # iteration
58
58
  while delta > epsilon:
59
- p1 = (1 - gamma) * np.dot(w, pt) + gamma * p0
59
+
60
+ if hasattr(weight, "dot"):
61
+ p1 = (1 - gamma) * weight.dot(pt) + gamma * p0
62
+ else:
63
+ p1 = (1 - gamma) * np.dot(weight, pt) + gamma * p0
60
64
 
61
65
  # 1 and 2, It would be faster alone
62
66
  if p == 1:
@@ -297,7 +301,6 @@ class RandomWalk:
297
301
 
298
302
  init_status.obs["clusters"] = init_status.obs["clusters"].astype(str)
299
303
 
300
- self.cc_adata = cc_adata
301
304
  self.epsilon = epsilon
302
305
  self.gamma = gamma
303
306
  self.enrichment_gamma = enrichment_gamma
@@ -390,10 +393,12 @@ class RandomWalk:
390
393
  self.random_seed_cell = np.zeros(init_status.shape)
391
394
 
392
395
  # Transition Probability Matrix
393
- self.weight = self._get_weight_(self.cc_adata.X)
396
+ self.weight = self._get_weight_(cc_adata.X)
394
397
 
395
398
  if not is_simple and self.is_ablation:
396
- self.weight_m_knn = self._get_weight_(self.cc_adata.layers["cell_mutual_knn"])
399
+ self.weight_m_knn = self._get_weight_(cc_adata.layers["cell_mutual_knn"])
400
+
401
+ del cc_adata
397
402
 
398
403
  self.cluster_types, self.init_seed_cell_size = self._get_cluster_info_()
399
404
 
@@ -419,6 +424,9 @@ class RandomWalk:
419
424
  self.seed_cell_weight_en_ncw
420
425
  ) = self._get_seed_cell_(init_data=init_status_no_weight, info="ablation")
421
426
 
427
+ del self.cell_affinity
428
+ del init_status
429
+
422
430
  def _random_walk_(
423
431
  self,
424
432
  seed_cell_data: matrix_data,
@@ -461,7 +469,7 @@ class RandomWalk:
461
469
  return self._random_walk_(seed_cell_data, weight, self.gamma)
462
470
 
463
471
  @staticmethod
464
- def _get_weight_(cell_cell_matrix: matrix_data) -> matrix_data:
472
+ def _get_weight_(cell_cell_matrix: matrix_data) -> sparse_data:
465
473
  """
466
474
  Obtain weights in random walk
467
475
  :param cell_cell_matrix: Cell to cell connectivity matrix
@@ -472,7 +480,7 @@ class RandomWalk:
472
480
  data_weight = to_dense(cell_cell_matrix, is_array=True)
473
481
  cell_sum_weight = data_weight.sum(axis=1)[:, np.newaxis]
474
482
  cell_sum_weight[cell_sum_weight == 0] = 1
475
- return data_weight / cell_sum_weight
483
+ return to_sparse(data_weight / cell_sum_weight)
476
484
 
477
485
  def _get_cell_weight_(self, seed_cell_size: int) -> matrix_data:
478
486
  _cell_cell_knn_: matrix_data = self.cell_affinity.copy()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sciv
3
- Version: 0.0.81
3
+ Version: 0.0.83
4
4
  Summary: Unveiling the pivotal cell types involved in variant function regulation at a single-cell resolution
5
5
  Project-URL: github, https://github.com/YuZhengM/sciv
6
6
  Author-email: Zheng-Min Yu <yuzmbio@163.com>
@@ -27,13 +27,13 @@ sciv/preprocessing/_scanpy_.py,sha256=mmkk4cMCzJCziF49RnOuXBiF4frS6aSiwZdUmfDAg4
27
27
  sciv/preprocessing/_scvi_.py,sha256=ZIDkQ_4deYmzSMiAbu5C3j_jMMl7hBTFLCBXHCNj3B4,10332
28
28
  sciv/preprocessing/_snapatac_.py,sha256=Dq8CHF7Psl3CQszaEokQYO56Oe2uzyWOy_cGlaOywfc,27798
29
29
  sciv/tool/__init__.py,sha256=WXzHkWt6RgBC3qqD-98nR5wQmt6oC850ox_VpMrapSU,2468
30
- sciv/tool/_algorithm_.py,sha256=ab6-fRdAkNzawGBNqER481X5PWUjYPO701ehe1sayEc,48063
31
- sciv/tool/_matrix_.py,sha256=NDQf7yTuN4_GaKL7jK5i1BGYCIOGFQHcmpWgQkuquK8,24230
32
- sciv/tool/_random_walk_.py,sha256=98HLa9X2xx3Tj7VKKwQ2oS-CWL7HbOURAXiYKky2OYs,47338
30
+ sciv/tool/_algorithm_.py,sha256=6xLGB1-FRfRiHSCVb_tHvzY_N-RoMZ79p0O2fEio688,48030
31
+ sciv/tool/_matrix_.py,sha256=O1EAhA9wxh06P_eOxEBesK7kO7IExKlhH6uJzGh1HBM,24322
32
+ sciv/tool/_random_walk_.py,sha256=E6QxZWXc1FY6rr0EiBNzX7TA5h9NFjt9YjpI_M4wN34,47567
33
33
  sciv/util/__init__.py,sha256=nOxZ8if27X7AUJ6hZwTwxOJwIBJb0obWlHjqCzjg_Gc,1964
34
34
  sciv/util/_constant_.py,sha256=w0wKQd8guLd1ZTW24_5aECrWsIWDiNQmEpLsWlHar1A,3000
35
35
  sciv/util/_core_.py,sha256=ZD2uSnEBHVu0i9TmXWzri_3bXZzYKnIZk818gW3zadE,14751
36
- sciv-0.0.81.dist-info/METADATA,sha256=CorsYrplOzaSS5QtIMxMKxXysUkNbRQODcrtLIKp5BE,3465
37
- sciv-0.0.81.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
- sciv-0.0.81.dist-info/licenses/LICENSE,sha256=4UvHVf3qCOZjHLs4LkYz8u96XRpXnZrpTKrkUQPs5_A,1075
39
- sciv-0.0.81.dist-info/RECORD,,
36
+ sciv-0.0.83.dist-info/METADATA,sha256=M5efcCSMDCUU4-8C8CVEQ2fpJw__3ltHPDU2LyYxj9Q,3465
37
+ sciv-0.0.83.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
+ sciv-0.0.83.dist-info/licenses/LICENSE,sha256=4UvHVf3qCOZjHLs4LkYz8u96XRpXnZrpTKrkUQPs5_A,1075
39
+ sciv-0.0.83.dist-info/RECORD,,
File without changes