sciv 0.0.96__tar.gz → 0.0.97__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.
Files changed (44) hide show
  1. {sciv-0.0.96 → sciv-0.0.97}/PKG-INFO +1 -1
  2. {sciv-0.0.96 → sciv-0.0.97}/pyproject.toml +1 -1
  3. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/model/_core_.py +2 -2
  4. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/tool/_algorithm_.py +47 -18
  5. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/util/_core_.py +6 -4
  6. {sciv-0.0.96 → sciv-0.0.97}/.gitignore +0 -0
  7. {sciv-0.0.96 → sciv-0.0.97}/LICENSE +0 -0
  8. {sciv-0.0.96 → sciv-0.0.97}/MANIFEST.in +0 -0
  9. {sciv-0.0.96 → sciv-0.0.97}/README.en.md +0 -0
  10. {sciv-0.0.96 → sciv-0.0.97}/README.md +0 -0
  11. {sciv-0.0.96 → sciv-0.0.97}/requirements.txt +0 -0
  12. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/__init__.py +0 -0
  13. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/file/__init__.py +0 -0
  14. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/file/_read_.py +0 -0
  15. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/file/_write_.py +0 -0
  16. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/model/__init__.py +0 -0
  17. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/__init__.py +0 -0
  18. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_bar_.py +0 -0
  19. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_barcode_.py +0 -0
  20. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_box_.py +0 -0
  21. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_bubble_.py +0 -0
  22. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_core_.py +0 -0
  23. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_graph_.py +0 -0
  24. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_heat_map_.py +0 -0
  25. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_kde_.py +0 -0
  26. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_line_.py +0 -0
  27. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_pie_.py +0 -0
  28. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_radar_.py +0 -0
  29. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_scatter_.py +0 -0
  30. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_venn_.py +0 -0
  31. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/plot/_violin_.py +0 -0
  32. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/preprocessing/__init__.py +0 -0
  33. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/preprocessing/_anndata_.py +0 -0
  34. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/preprocessing/_gencode_.py +0 -0
  35. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/preprocessing/_gsea_.py +0 -0
  36. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/preprocessing/_scanpy_.py +0 -0
  37. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/preprocessing/_scvi_.py +0 -0
  38. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/preprocessing/_snapatac_.py +0 -0
  39. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/tool/__init__.py +0 -0
  40. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/tool/_matrix_.py +0 -0
  41. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/tool/_random_walk_.py +0 -0
  42. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/util/__init__.py +0 -0
  43. {sciv-0.0.96 → sciv-0.0.97}/src/sciv/util/_constant_.py +0 -0
  44. {sciv-0.0.96 → sciv-0.0.97}/tests/scivTest/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sciv
3
- Version: 0.0.96
3
+ Version: 0.0.97
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>
@@ -3,7 +3,7 @@ requires = ["hatchling"]
3
3
  build-backend = "hatchling.build"
4
4
  [project]
5
5
  name = "sciv"
6
- version = "0.0.96"
6
+ version = "0.0.97"
7
7
  authors = [
8
8
  { name = "Zheng-Min Yu", email = "yuzmbio@163.com" },
9
9
  ]
@@ -81,7 +81,7 @@ def core(
81
81
  weight: float = 0.1,
82
82
  kernel: Literal["laplacian", "gaussian"] = "gaussian",
83
83
  local_k: int = 10,
84
- kernel_gamma: Optional[float, collection] = None,
84
+ kernel_gamma: Optional[Union[float, collection]] = None,
85
85
  epsilon: float = 1e-05,
86
86
  gamma: float = 0.05,
87
87
  enrichment_gamma: float = 0.05,
@@ -481,7 +481,7 @@ def core(
481
481
  )
482
482
 
483
483
  else:
484
- overlap_adata: AnnData = overlap_sum(adata, variants, trait_info)
484
+ overlap_adata: AnnData = overlap_sum(adata, variants, trait_info, n_jobs=n_jobs)
485
485
 
486
486
  del variants, trait_info
487
487
 
@@ -7,6 +7,8 @@ from typing import Union, Tuple, Literal, Optional
7
7
  from scipy import sparse
8
8
  from scipy.stats import norm
9
9
  from tqdm import tqdm
10
+ from joblib import Parallel, delayed
11
+ import multiprocessing
10
12
 
11
13
  import numpy as np
12
14
  from anndata import AnnData
@@ -516,7 +518,7 @@ def semi_mutual_knn_weight(
516
518
  adj_weight = (1 - weight) * adj_and.astype(np.float32) + weight * adj_or.astype(np.float32)
517
519
 
518
520
  # Ensure full connectivity if required
519
- if is_mknn_fully_connected and (or_neighbors == 0 or weight == 0):
521
+ if is_mknn_fully_connected:
520
522
  adj_1nn = _knn(new_data, 1)
521
523
 
522
524
  if sparse.issparse(adj_and):
@@ -824,16 +826,17 @@ def _overlap_(regions_sort: DataFrame, variants: DataFrame) -> DataFrame:
824
826
  if chr_a in chr_keys:
825
827
  # get chr variant
826
828
  variants_chr_type_position_list = variants_position_list[chr_a]
829
+
827
830
  # judge start and end position
828
831
  if start <= variants_chr_type_position_list[-1] and end >= variants_chr_type_position_list[0]:
829
832
  # get index
830
- start_index = get_index(start, variants_chr_type_position_list)
831
- end_index = get_index(end, variants_chr_type_position_list)
833
+ start_index = get_index(start, variants_chr_type_position_list, False)
834
+ end_index = get_index(end, variants_chr_type_position_list, False)
832
835
 
833
836
  # Determine whether it is equal, Equality means there is no overlap
834
837
  if start_index != end_index:
835
- start_index = start_index if isinstance(start_index, number) else start_index[1]
836
- end_index = end_index + 1 if isinstance(end_index, number) else end_index[1]
838
+ start_index = start_index if isinstance(start_index, int) else start_index[1]
839
+ end_index = end_index + 1 if isinstance(end_index, int) else end_index[1]
837
840
 
838
841
  if start_index > end_index:
839
842
  ul.log(__name__).error("The end index in the region is greater than the start index.")
@@ -894,13 +897,14 @@ def overlap(regions: DataFrame, variants: DataFrame) -> DataFrame:
894
897
  return _overlap_(regions_sort, variants)
895
898
 
896
899
 
897
- def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame) -> AnnData:
900
+ def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame, n_jobs: int = -1) -> AnnData:
898
901
  """
899
902
  Overlap regional data and mutation data and sum the PP values of all mutations in a region as the values for that
900
903
  region.
901
904
  :param regions: peaks data
902
905
  :param variants: variants data
903
906
  :param trait_info: traits information
907
+ :param n_jobs: The maximum number of concurrently running jobs
904
908
  :return: overlap data
905
909
  """
906
910
 
@@ -916,8 +920,6 @@ def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame) -> AnnD
916
920
 
917
921
  trait_names = trait_info["id"].tolist()
918
922
  n_trait = len(trait_names)
919
- # Pre-allocate sparse matrix, fill column by column, then convert to csc and then csr for efficiency
920
- row_indices, col_indices, data_vals = [], [], []
921
923
 
922
924
  # Check column existence once
923
925
  required = {"chr", "start", "end"}
@@ -941,13 +943,18 @@ def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame) -> AnnD
941
943
 
942
944
  ul.log(__name__).info("Obtain peak-trait/disease matrix. (overlap variant information)")
943
945
 
944
- # The outer loop can be further accelerated by parallelizing over traits; here we keep it single-threaded for now.
945
- for col_idx, trait_name in enumerate(tqdm(trait_names)):
946
+ # Function to process a single trait
947
+ def _process_trait_(trait_name, col_idx):
948
+
949
+ local_data_vals = []
950
+ local_row_indices = []
951
+ local_col_indices = []
952
+
946
953
  variant: AnnData = variants[trait_name]
947
954
  overlap_df: DataFrame = _overlap_(regions_df, variant.obs)
948
955
 
949
956
  if overlap_df.empty:
950
- continue
957
+ return local_data_vals, local_row_indices, local_col_indices
951
958
 
952
959
  # Sum at once: first group by label and collect variant_id into a list
953
960
  label_var_ids = (
@@ -972,15 +979,37 @@ def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame) -> AnnD
972
979
  if matrix_sum.size == 1:
973
980
  val = float(matrix_sum)
974
981
  if val != 0:
975
- row_indices.append(row_idx)
976
- col_indices.append(col_idx)
977
- data_vals.append(val)
982
+ local_row_indices.append(row_idx)
983
+ local_col_indices.append(col_idx)
984
+ local_data_vals.append(val)
978
985
  else:
979
986
  for t_idx, v in enumerate(matrix_sum):
980
987
  if v != 0:
981
- row_indices.append(row_idx)
982
- col_indices.append(col_idx + t_idx)
983
- data_vals.append(float(v))
988
+ local_row_indices.append(row_idx)
989
+ local_col_indices.append(col_idx + t_idx)
990
+ local_data_vals.append(float(v))
991
+
992
+ return local_data_vals, local_row_indices, local_col_indices
993
+
994
+ # Use Parallel to process traits in parallel
995
+ results = Parallel(n_jobs=n_jobs)(
996
+ delayed(_process_trait_)(trait_name, col_idx) for col_idx, trait_name in enumerate(trait_names)
997
+ )
998
+
999
+ # Preallocate length to avoid list dynamic expansion
1000
+ total = sum(len(ld) for ld, _, _ in results)
1001
+ row_indices = np.empty(total, dtype=np.int32)
1002
+ col_indices = np.empty(total, dtype=np.int32)
1003
+ data_vals = np.empty(total, dtype=np.float32)
1004
+
1005
+ ptr = 0
1006
+
1007
+ for local_data, local_rows, local_cols in results:
1008
+ n = len(local_data)
1009
+ row_indices[ptr:ptr+n] = local_rows
1010
+ col_indices[ptr:ptr+n] = local_cols
1011
+ data_vals[ptr:ptr+n] = local_data
1012
+ ptr += n
984
1013
 
985
1014
  # Build sparse matrix, then convert to csr format
986
1015
  overlap_sparse = sparse.csc_matrix(
@@ -1253,7 +1282,7 @@ def obtain_cell_cell_network(
1253
1282
  weight: float = 0.1,
1254
1283
  kernel: Literal["laplacian", "gaussian"] = "gaussian",
1255
1284
  local_k: int = 10,
1256
- gamma: Optional[float, collection] = None,
1285
+ gamma: Optional[Union[float, collection]] = None,
1257
1286
  is_simple: bool = True
1258
1287
  ) -> AnnData:
1259
1288
  """
@@ -90,17 +90,20 @@ def sum_min_max(data: matrix_data, axis: int = 1) -> Tuple[number, number]:
90
90
  return min(rows_sum), max(rows_sum)
91
91
 
92
92
 
93
- def get_index(position: number, positions_list: list) -> Union[number, Tuple[number, number]]:
93
+ def get_index(position: number, positions_list: list, is_sort: bool = True) -> Union[int, Tuple[int, int]]:
94
94
  """
95
95
  Search for position information. Similar to half search.
96
96
  If the position exists in the list, return the index.
97
97
  If it does not exist, return the index located between the two indexes
98
98
  :param position: position
99
99
  :param positions_list: position list
100
+ :param is_sort: True
100
101
  :return: position index
101
102
  """
102
- # sort
103
- positions_list.sort()
103
+
104
+ if is_sort:
105
+ positions_list.sort()
106
+
104
107
  # search
105
108
  position_size: int = len(positions_list)
106
109
  left, right = 0, position_size - 1
@@ -441,7 +444,6 @@ def plot_end(
441
444
  close: bool = False,
442
445
  dpi: float = 300
443
446
  ):
444
-
445
447
  if title is not None:
446
448
  plt.title(title)
447
449
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes