sciv 0.0.83__py3-none-any.whl → 0.0.85__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
@@ -14,7 +14,6 @@ from pandas import DataFrame
14
14
 
15
15
  from ._matrix_ import (
16
16
  matrix_dot_block_storage,
17
- matrix_operation_memory_efficient,
18
17
  vector_multiply_block_storage
19
18
  )
20
19
 
@@ -8,6 +8,7 @@ import torch.nn as nn
8
8
 
9
9
  from torch import Tensor
10
10
  from tqdm import tqdm
11
+ from joblib import Parallel, delayed
11
12
 
12
13
  import numpy as np
13
14
  from anndata import AnnData
@@ -24,7 +25,6 @@ from ..util import (
24
25
  check_adata_get,
25
26
  enrichment_optional,
26
27
  check_gpu_availability,
27
- dense_data,
28
28
  sparse_data
29
29
  )
30
30
 
@@ -600,72 +600,80 @@ class RandomWalk:
600
600
  if init_data is None:
601
601
  init_data = self.init_status
602
602
 
603
- # seed cell threshold
604
- seed_cell_count: collection = np.zeros(len(self.trait_list)).astype(int)
605
- seed_cell_threshold: collection = np.zeros(len(self.trait_list))
606
- seed_cell_weight: matrix_data = np.zeros(self.trs_adata.shape)
607
- seed_cell_index: matrix_data = np.zeros(self.trs_adata.shape)
608
- seed_cell_weight_en: matrix_data = np.zeros(self.trs_adata.shape)
603
+ n_traits = len(self.trait_list)
604
+ n_cells = self.cell_size
605
+
606
+ seed_cell_count = np.zeros(n_traits, dtype=int)
607
+ seed_cell_threshold = np.zeros(n_traits)
608
+ seed_cell_weight = np.zeros((n_cells, n_traits))
609
+ seed_cell_index = np.zeros((n_cells, n_traits), dtype=int)
610
+ seed_cell_weight_en = np.zeros((n_cells, n_traits))
609
611
 
610
612
  if not self.is_simple:
611
- seed_cell_matrix: matrix_data = np.zeros(self.trs_adata.shape)
612
- seed_cell_matrix_en: matrix_data = np.zeros(self.trs_adata.shape)
613
+ seed_cell_matrix = np.zeros((n_cells, n_traits))
614
+ seed_cell_matrix_en = np.zeros((n_cells, n_traits))
613
615
  else:
614
- seed_cell_matrix: matrix_data = np.zeros((1, 1))
615
- seed_cell_matrix_en: matrix_data = np.zeros((1, 1))
616
+ seed_cell_matrix = np.zeros((1, 1))
617
+ seed_cell_matrix_en = np.zeros((1, 1))
616
618
 
617
- ul.log(__name__).info(f"Calculate {len(self.trait_list)} traits/diseases for seed cells information.{f' ({info})' if info is not None else ''}")
618
- for i in tqdm(self.trait_range):
619
+ ul.log(__name__).info(f"Calculate {n_traits} traits/diseases for seed cells information.{f' ({info})' if info else ''}")
620
+
621
+ trait_values_all = to_dense(init_data.X, is_array=True)
622
+
623
+ def _process_single_trait(i: int) -> None:
624
+ trait_value = trait_values_all[:, i]
625
+ trait_value_max = trait_value.max()
626
+ trait_value_min = trait_value.min()
627
+
628
+ if trait_value_min == trait_value_max:
629
+ return
630
+
631
+ # Directly obtain descending index
632
+ trait_value_sort_index = np.argpartition(trait_value, -trait_value.size)[::-1]
633
+
634
+ # Calculate the number of cells with>0
635
+ _gt0_cell_size = (trait_value > 0).sum()
636
+
637
+ _seed_cell_size = self._get_seed_cell_size_(_gt0_cell_size)
638
+
639
+ seed_cell_count[i] = _seed_cell_size
640
+ seed_cell_threshold[i] = trait_value[trait_value_sort_index[_seed_cell_size]]
619
641
 
620
- # Obtain all cell score values in a trait
621
- trait_adata: AnnData = init_data[:, i]
622
- trait_value: collection = to_dense(trait_adata.X, is_array=True).flatten()
623
-
624
- # Obtain the maximum initial score
625
- trait_value_max = np.max(trait_value)
626
- trait_value_min = np.min(trait_value)
627
-
628
- if trait_value_min != trait_value_max:
629
-
630
- # Obtain a cell count greater than zero
631
- trait_value_sort_index = np.argsort(trait_value).astype(int)
632
- trait_value_sort_index = trait_value_sort_index[::-1]
633
- _gto_cell_index_ = trait_value > 0
634
- _gt0_cell_size_ = trait_value[_gto_cell_index_].size
635
-
636
- _seed_cell_size_ = self._get_seed_cell_size_(_gt0_cell_size_)
637
-
638
- seed_cell_count[i] = _seed_cell_size_
639
- seed_cell_threshold[i] = trait_value[trait_value_sort_index[_seed_cell_size_]]
640
-
641
- # Set seed cell weights (reduce noise seed cell weights)
642
- _seed_cell_index_ = trait_value_sort_index[0:_seed_cell_size_]
643
- seed_cell_index[:, i][_seed_cell_index_] = 1
644
- seed_cell_weight[:, i][_seed_cell_index_] = self._get_seed_cell_weight_(seed_cell_index=_seed_cell_index_, value=trait_value)
645
-
646
- _enrichment_start_index_: int = _seed_cell_size_
647
- _enrichment_end_index_: int = 2 * _seed_cell_size_ if self.cell_size > 2 * _seed_cell_size_ else _seed_cell_size_ - 1
648
-
649
- if _gt0_cell_size_ == _seed_cell_size_:
650
- _enrichment_start_index_ = int(_seed_cell_size_ - self._enrichment_seed_cell_min_count_) if _seed_cell_size_ > self._enrichment_seed_cell_min_count_ else (
651
- (_seed_cell_size_ - 1) if _seed_cell_size_ > 2 else 0)
652
- _enrichment_end_index_ = _seed_cell_size_
653
-
654
- _seed_cell_en_index_ = trait_value_sort_index[_enrichment_start_index_:_enrichment_end_index_]
655
- _seed_cell_en_weight_ = self._get_seed_cell_weight_(
656
- seed_cell_index=_seed_cell_index_ if len(_seed_cell_en_index_) == len(_seed_cell_index_) else _seed_cell_en_index_, value=trait_value,
657
- seed_cell_index_enrichment=_seed_cell_en_index_
658
- )
659
- seed_cell_weight_en[:, i][_seed_cell_en_index_] = _seed_cell_en_weight_
660
-
661
- if not self.is_simple and self.is_ablation:
662
- # Without weight
663
- seed_cell_value = np.zeros(self.cell_size)
664
- seed_cell_value[_seed_cell_index_] = 1
665
- seed_cell_matrix[:, i] = seed_cell_value / (1 if seed_cell_value.sum() == 0 else seed_cell_value.sum())
666
- seed_cell_en_value = np.zeros(self.cell_size)
667
- seed_cell_en_value[_seed_cell_en_index_] = 1
668
- seed_cell_matrix_en[:, i] = seed_cell_en_value / (1 if seed_cell_en_value.sum() == 0 else seed_cell_en_value.sum())
642
+ # Set seed cell index and weight
643
+ _seed_cell_index = trait_value_sort_index[:_seed_cell_size]
644
+ seed_cell_index[_seed_cell_index, i] = 1
645
+ seed_cell_weight[_seed_cell_index, i] = self._get_seed_cell_weight_(
646
+ seed_cell_index=_seed_cell_index, value=trait_value
647
+ )
648
+
649
+ # Enrichment interval index
650
+ _enrichment_start = _seed_cell_size
651
+ _enrichment_end = min(2 * _seed_cell_size, self.cell_size - 1)
652
+
653
+ if _gt0_cell_size == _seed_cell_size:
654
+ _enrichment_start = max(_seed_cell_size - self._enrichment_seed_cell_min_count_, 0)
655
+ _enrichment_end = _seed_cell_size
656
+
657
+ _seed_cell_en_index = trait_value_sort_index[_enrichment_start:_enrichment_end]
658
+ seed_cell_weight_en[_seed_cell_en_index, i] = self._get_seed_cell_weight_(
659
+ seed_cell_index=_seed_cell_index if len(_seed_cell_en_index) == len(_seed_cell_index) else _seed_cell_en_index,
660
+ value=trait_value,
661
+ seed_cell_index_enrichment=_seed_cell_en_index
662
+ )
663
+
664
+ if not self.is_simple and self.is_ablation:
665
+ seed_cell_value = np.zeros(n_cells)
666
+ seed_cell_value[_seed_cell_index] = 1
667
+ seed_cell_matrix[:, i] = seed_cell_value / (1 if seed_cell_value.sum() == 0 else seed_cell_value.sum())
668
+
669
+ seed_cell_en_value = np.zeros(n_cells)
670
+ seed_cell_en_value[_seed_cell_en_index] = 1
671
+ seed_cell_matrix_en[:, i] = seed_cell_en_value / (1 if seed_cell_en_value.sum() == 0 else seed_cell_en_value.sum())
672
+
673
+ # Parallel processing of all traits and real-time display of progress
674
+ Parallel(n_jobs=-1, backend="threading")(
675
+ delayed(_process_single_trait)(i) for i in tqdm(self.trait_range, desc="Obtain progress of seed cells with weights")
676
+ )
669
677
 
670
678
  return seed_cell_count, seed_cell_threshold, seed_cell_matrix, seed_cell_weight, seed_cell_index, seed_cell_matrix_en, seed_cell_weight_en
671
679
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sciv
3
- Version: 0.0.83
3
+ Version: 0.0.85
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=6xLGB1-FRfRiHSCVb_tHvzY_N-RoMZ79p0O2fEio688,48030
30
+ sciv/tool/_algorithm_.py,sha256=okGpH2OrBTO59LkyznT4gRi5S45oAcnO10Kxo5Xzy4I,47991
31
31
  sciv/tool/_matrix_.py,sha256=O1EAhA9wxh06P_eOxEBesK7kO7IExKlhH6uJzGh1HBM,24322
32
- sciv/tool/_random_walk_.py,sha256=E6QxZWXc1FY6rr0EiBNzX7TA5h9NFjt9YjpI_M4wN34,47567
32
+ sciv/tool/_random_walk_.py,sha256=PyVz11dA0rfbYyGYw3WE9BH9KiTUSRHsNDf1J-wfIn0,47156
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.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,,
36
+ sciv-0.0.85.dist-info/METADATA,sha256=wJDwU4Oks-klm0j2Lg0TyoV7gqF_Gn0JwKa7_c3iCGA,3465
37
+ sciv-0.0.85.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
+ sciv-0.0.85.dist-info/licenses/LICENSE,sha256=4UvHVf3qCOZjHLs4LkYz8u96XRpXnZrpTKrkUQPs5_A,1075
39
+ sciv-0.0.85.dist-info/RECORD,,
File without changes