sciv 0.0.102__tar.gz → 0.0.104__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.102 → sciv-0.0.104}/PKG-INFO +1 -1
  2. {sciv-0.0.102 → sciv-0.0.104}/pyproject.toml +1 -1
  3. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/model/_core_.py +2 -2
  4. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_scatter_.py +24 -3
  5. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/preprocessing/_scvi_.py +1 -1
  6. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/tool/__init__.py +2 -2
  7. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/tool/_algorithm_.py +31 -35
  8. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/util/_core_.py +1 -6
  9. {sciv-0.0.102 → sciv-0.0.104}/.gitignore +0 -0
  10. {sciv-0.0.102 → sciv-0.0.104}/LICENSE +0 -0
  11. {sciv-0.0.102 → sciv-0.0.104}/MANIFEST.in +0 -0
  12. {sciv-0.0.102 → sciv-0.0.104}/README.en.md +0 -0
  13. {sciv-0.0.102 → sciv-0.0.104}/README.md +0 -0
  14. {sciv-0.0.102 → sciv-0.0.104}/requirements.txt +0 -0
  15. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/__init__.py +0 -0
  16. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/file/__init__.py +0 -0
  17. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/file/_read_.py +0 -0
  18. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/file/_write_.py +0 -0
  19. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/model/__init__.py +0 -0
  20. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/__init__.py +0 -0
  21. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_bar_.py +0 -0
  22. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_barcode_.py +0 -0
  23. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_box_.py +0 -0
  24. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_bubble_.py +0 -0
  25. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_core_.py +0 -0
  26. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_graph_.py +0 -0
  27. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_heat_map_.py +0 -0
  28. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_kde_.py +0 -0
  29. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_line_.py +0 -0
  30. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_pie_.py +0 -0
  31. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_radar_.py +0 -0
  32. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_venn_.py +0 -0
  33. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/plot/_violin_.py +0 -0
  34. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/preprocessing/__init__.py +0 -0
  35. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/preprocessing/_anndata_.py +0 -0
  36. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/preprocessing/_gencode_.py +0 -0
  37. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/preprocessing/_gsea_.py +0 -0
  38. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/preprocessing/_scanpy_.py +0 -0
  39. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/preprocessing/_snapatac_.py +0 -0
  40. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/tool/_matrix_.py +0 -0
  41. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/tool/_random_walk_.py +0 -0
  42. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/util/__init__.py +0 -0
  43. {sciv-0.0.102 → sciv-0.0.104}/src/sciv/util/_constant_.py +0 -0
  44. {sciv-0.0.102 → sciv-0.0.104}/tests/scivTest/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sciv
3
- Version: 0.0.102
3
+ Version: 0.0.104
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.102"
6
+ version = "0.0.104"
7
7
  authors = [
8
8
  { name = "Zheng-Min Yu", email = "yuzmbio@163.com" },
9
9
  ]
@@ -76,8 +76,8 @@ def core(
76
76
  early_stopping_patience: int = 50,
77
77
  batch_key: Optional[str] = None,
78
78
  resolution: float = 0.5,
79
- k: int = 30,
80
- or_k: int = 1,
79
+ k: int = 50,
80
+ or_k: int = 25,
81
81
  weight: float = 0.1,
82
82
  kernel: Literal["laplacian", "gaussian"] = "gaussian",
83
83
  local_k: int = 10,
@@ -174,6 +174,8 @@ def scatter_3d(
174
174
  edge_color: str = None,
175
175
  size: Union[float, collection] = 0.1,
176
176
  legend_name: str = None,
177
+ is_add_max_label: bool = False,
178
+ text_left_offset: float = 0.5,
177
179
  output: path = None,
178
180
  show: bool = True,
179
181
  close: bool = False,
@@ -186,13 +188,14 @@ def scatter_3d(
186
188
  fig = plt.figure(figsize=(width, height))
187
189
  ax = fig.add_subplot(projection='3d')
188
190
 
189
- hue_cat = pd.Categorical(df[hue])
191
+ if hue is not None:
192
+ hue_cat = pd.Categorical(df[hue])
190
193
 
191
194
  scatter = ax.scatter(
192
195
  df[x],
193
196
  df[y],
194
197
  df[z],
195
- c=hue_cat.codes,
198
+ c=hue_cat.codes if hue is not None else None,
196
199
  cmap=cmap,
197
200
  s=size,
198
201
  edgecolors=edge_color,
@@ -214,7 +217,7 @@ def scatter_3d(
214
217
  if title is not None:
215
218
  ax.set_title(title, fontsize=font_size)
216
219
 
217
- if is_add_legend:
220
+ if is_add_legend and hue is not None:
218
221
  unique_types = hue_cat.categories
219
222
  legend_elements = [
220
223
  plt.Line2D(
@@ -226,6 +229,24 @@ def scatter_3d(
226
229
 
227
230
  ax.legend(handles=legend_elements, title=legend_name, loc='upper left')
228
231
 
232
+ if is_add_max_label:
233
+
234
+ max_idx = df[z].idxmax()
235
+ max_x = df.loc[max_idx, x]
236
+ max_y = df.loc[max_idx, y]
237
+ max_value = df.loc[max_idx, z]
238
+
239
+ # 在最大值点的位置添加文本标签
240
+ ax.text(
241
+ max_x - text_left_offset,
242
+ max_y,
243
+ max_value,
244
+ f'({max_x}, {max_y}): {max_value:.3f}',
245
+ fontsize=font_size - 2,
246
+ color='red',
247
+ ha='left'
248
+ )
249
+
229
250
  plot_end(fig, None, None, None, output, show, close)
230
251
 
231
252
 
@@ -137,7 +137,7 @@ def poisson_vi(
137
137
  ul.log(__name__).warning(f"GPU failed to run, try to switch to CPU running.\n {ome}")
138
138
 
139
139
  try:
140
- model = scvi.external.POISSONVI.load(model_dir, adata=adata, accelerator="cpu", device="cpu")
140
+ model = scvi.external.POISSONVI.load(model_dir, adata=adata, accelerator="cpu")
141
141
  except Exception as e:
142
142
  ul.log(__name__).error(f"File `model.pt` failed to load, you can execute `Poisson VI` again by deleting file `model.pt` ({model_dir}/model.pt).\n {e}")
143
143
  raise ValueError(f"File `model.pt` failed to load, you can execute `Poisson VI` again by deleting file `model.pt` ({model_dir}/model.pt).")
@@ -36,7 +36,7 @@ from ._algorithm_ import (
36
36
  calculate_init_score_weight,
37
37
  obtain_cell_cell_network,
38
38
  perturb_data,
39
- add_noise
39
+ add_bernoulli_fluctuation_noise
40
40
  )
41
41
 
42
42
  from ._random_walk_ import (
@@ -98,7 +98,7 @@ __all__ = [
98
98
  "calculate_init_score_weight",
99
99
  "obtain_cell_cell_network",
100
100
  "perturb_data",
101
- "add_noise",
101
+ "add_bernoulli_fluctuation_noise",
102
102
  "split_matrix",
103
103
  "merge_matrix",
104
104
  "down_sampling_data",
@@ -8,7 +8,6 @@ from scipy import sparse
8
8
  from scipy.stats import norm
9
9
  from tqdm import tqdm
10
10
  from joblib import Parallel, delayed
11
- import multiprocessing
12
11
 
13
12
  import numpy as np
14
13
  from anndata import AnnData
@@ -1005,15 +1004,15 @@ def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame, n_jobs:
1005
1004
  total = sum(len(ld) for ld, _, _ in results)
1006
1005
  row_indices = np.empty(total, dtype=np.int32)
1007
1006
  col_indices = np.empty(total, dtype=np.int32)
1008
- data_vals = np.empty(total, dtype=np.float32)
1007
+ data_vals = np.empty(total, dtype=np.float32)
1009
1008
 
1010
1009
  ptr = 0
1011
1010
 
1012
1011
  for local_data, local_rows, local_cols in results:
1013
1012
  n = len(local_data)
1014
- row_indices[ptr:ptr+n] = local_rows
1015
- col_indices[ptr:ptr+n] = local_cols
1016
- data_vals[ptr:ptr+n] = local_data
1013
+ row_indices[ptr:ptr + n] = local_rows
1014
+ col_indices[ptr:ptr + n] = local_cols
1015
+ data_vals[ptr:ptr + n] = local_data
1017
1016
  ptr += n
1018
1017
 
1019
1018
  # Build sparse matrix, then convert to csr format
@@ -1404,39 +1403,36 @@ def perturb_data(data: collection, percentage: float) -> collection:
1404
1403
  return new_data
1405
1404
 
1406
1405
 
1407
- def add_noise(data: matrix_data, rate: float) -> matrix_data:
1408
- """
1409
- Add peak percentage noise to each cell
1406
+ def add_bernoulli_fluctuation_noise(
1407
+ counts_matrix: matrix_data,
1408
+ noise_level: float = 0.1
1409
+ ) -> matrix_data:
1410
1410
  """
1411
+ Add Bernoulli fluctuation noise to the counts matrix (add 1 with probability noise_level)
1411
1412
 
1412
- if rate <= 0 or rate >= 1:
1413
- raise ValueError("The value of the `rate` parameter must be greater than 0 and less than 1.")
1413
+ Parameters
1414
+ ----------
1415
+ counts_matrix : matrix_data
1416
+ Input counts matrix
1417
+ noise_level : float, default 0.1
1418
+ Noise level, i.e., the probability of randomly adding 1 (range: 0.0 - 1.0)
1414
1419
 
1415
- shape = data.shape
1416
- noise = to_dense(data.copy())
1417
-
1418
- for i in tqdm(range(shape[0])):
1419
- count_i = np.array(noise[i, :]).flatten()
1420
- # Add noise to the accessibility of unopened chromatin
1421
- count0_i = count_i[count_i == 0]
1422
- max_i = np.max(count_i)
1423
- count0 = int(count0_i.size * rate)
1424
- noise0_i = np.random.randint(low=1, high=2 if max_i < 2 else max_i, size=count0)
1425
- random_index0 = np.random.choice(np.arange(0, count0_i.size), size=count0, replace=False)
1426
- count0_i[random_index0] = noise0_i
1427
- count_i_value = count_i.copy()
1428
- count_i_value[count_i_value == 0] = count0_i
1429
- noise[i, :] = count_i_value
1420
+ Returns
1421
+ -------
1422
+ matrix_data
1423
+ Matrix after adding noise
1424
+ """
1425
+ if noise_level < 0 or noise_level > 1:
1426
+ ul.log(__name__).error("The value of the `noise_level` parameter must be greater than 0 and less than 1.")
1427
+ raise ValueError("The value of the `noise_level` parameter must be greater than 0 and less than 1.")
1430
1428
 
1431
- # Close open chromatin accessibility
1432
- count1_i = count_i[count_i == 1]
1433
- count1 = int(count1_i.size * rate)
1434
- random_index1 = np.random.choice(np.arange(0, count1_i.size), size=count1, replace=False)
1435
- count1_i[random_index1] = 0
1436
- count_i[count_i == 1] = count1_i
1437
- noise[i, :] = count_i
1429
+ if noise_level == 0:
1430
+ return counts_matrix.copy()
1438
1431
 
1439
- # disturbance
1440
- noise[i, :] = perturb_data(noise[i, :], rate)
1432
+ noise = np.random.binomial(
1433
+ n=1,
1434
+ p=noise_level,
1435
+ size=counts_matrix.shape
1436
+ ).astype(counts_matrix.dtype)
1441
1437
 
1442
- return noise
1438
+ return counts_matrix + noise
@@ -39,14 +39,12 @@ def log(name: str = None) -> Logger:
39
39
  return Logger(name, log_path=os.path.join(ul.log_file_path, name), is_form_file=ul.is_form_log_file)
40
40
 
41
41
 
42
- def track_with_memory(is_monitor: bool = False , interval: float = 60) -> Callable:
42
+ def track_with_memory(interval: float = 60) -> Callable:
43
43
  """
44
44
  Decorator: Records memory usage at fixed intervals during function execution and returns the result, elapsed time, and memory list.
45
45
 
46
46
  Parameters
47
47
  ----------
48
- is_monitor : bool, optional
49
- Whether to enable memory monitoring, default is False.
50
48
  interval : float, optional
51
49
  Sampling interval (seconds), default is 60 seconds.
52
50
 
@@ -63,9 +61,6 @@ def track_with_memory(is_monitor: bool = False , interval: float = 60) -> Callab
63
61
  @wraps(func)
64
62
  def wrapper(*args, **kwargs) -> Union[Any, dict]:
65
63
 
66
- if not is_monitor:
67
- return func(*args, **kwargs)
68
-
69
64
  process = psutil.Process(os.getpid())
70
65
 
71
66
  stop_monitor = False
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