sciv 0.0.102__py3-none-any.whl → 0.0.103__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/model/_core_.py CHANGED
@@ -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,
sciv/plot/_scatter_.py CHANGED
@@ -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).")
sciv/tool/__init__.py CHANGED
@@ -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",
sciv/tool/_algorithm_.py CHANGED
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sciv
3
- Version: 0.0.102
3
+ Version: 0.0.103
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 @@ sciv/file/__init__.py,sha256=8cYLG0S0nilblmyX46CWFrbLr-rmLbO1EEO477pZ-gk,520
3
3
  sciv/file/_read_.py,sha256=UZJpN3_5hBiTjzEYO6YXORcE_dqA8HmLpV80nqTLNSo,30554
4
4
  sciv/file/_write_.py,sha256=W3M9CmPi7BuKAffz1fdi-vA5DzAFZ7wmcggp33N9Xtg,7848
5
5
  sciv/model/__init__.py,sha256=k8SO9FpJaGn2ANqJyaz3HXMas7jH9toPVtpw703kOqg,149
6
- sciv/model/_core_.py,sha256=UHJW6r5j54v_0-AJuqw-o_mumElvFMVUFfcrxNMjllU,33722
6
+ sciv/model/_core_.py,sha256=ELOhkkKYTPEx4mJ5bJ47Si53afJpJ4weSzW6EPAmvvQ,33723
7
7
  sciv/plot/__init__.py,sha256=2tRNT6TZNz9r38lnna712RGsH7OJ2QkGa37XKgzejHQ,1865
8
8
  sciv/plot/_bar_.py,sha256=iQoFsFFbPbFj3JX2BgG45dqG-hjOka90LDw0WfdYNY8,14823
9
9
  sciv/plot/_barcode_.py,sha256=RDOedQ8ZtXWFyJ2c772RDfqO4TMIpHMvcMZMAVqky90,5073
@@ -16,7 +16,7 @@ sciv/plot/_kde_.py,sha256=A7_NFoSD0ih9h0Hh_1Y8ZOOz06AyANfi3M6sdkz61ZE,2399
16
16
  sciv/plot/_line_.py,sha256=qOSf4MJSXCTh8WCcd_dFlTsqMp-MeR2fGqR9lzEVPwo,3834
17
17
  sciv/plot/_pie_.py,sha256=GDoHES4AfOtnFeK99gh0a1KdUXIs7ZCCs6YHzoBLpbk,6451
18
18
  sciv/plot/_radar_.py,sha256=g_abzmzibJIR6it59TendUI236inbzYl0IzzdoA3Uuc,6304
19
- sciv/plot/_scatter_.py,sha256=HPy1eFqDk4vksAiKjn_Qk00fYO4GyqRs1O3ZZh44Ezw,16998
19
+ sciv/plot/_scatter_.py,sha256=XoRl4I9L1bmTTnH-ByAXEf4q2P0VABCjvk4FoBw1sfU,17632
20
20
  sciv/plot/_venn_.py,sha256=TfNTuxog2pT7sicKBEEMtleoHXwnenbl3CMWJu9c2vs,2675
21
21
  sciv/plot/_violin_.py,sha256=IoeAv-ipGkBO0LouI2Y2huPP44u_-6O9CfBkgrPsK6s,6486
22
22
  sciv/preprocessing/__init__.py,sha256=56RgDai5I3sZ4hl3aaV80ogOeUscYsU3nJUWE80jZ-k,742
@@ -24,16 +24,16 @@ sciv/preprocessing/_anndata_.py,sha256=3d1cHFs1YA9UZkIPE089nZHFi-DjK-c1fRyi2shfS
24
24
  sciv/preprocessing/_gencode_.py,sha256=HKhRgK76khGepdv4FaKiOvTys1uJTbvIyrKUta5W0K8,2108
25
25
  sciv/preprocessing/_gsea_.py,sha256=AH_PpUNfMN7WkF0pqAuUhEC6qZwKrtQm6VaaYu6JLfI,3803
26
26
  sciv/preprocessing/_scanpy_.py,sha256=95kt6ylfqKmjLr8GZ1XH1khP9Q3uBYy4vqc4_2Zf1J4,11629
27
- sciv/preprocessing/_scvi_.py,sha256=MdiR0OWe1tc4HprK2RfwmHetsjRL1oQPjHYLqVm3MIA,10796
27
+ sciv/preprocessing/_scvi_.py,sha256=vtMzaAuy3LZXPmg92MNJfFw5jIZv71_tZdpeEyl3JHc,10782
28
28
  sciv/preprocessing/_snapatac_.py,sha256=Dq8CHF7Psl3CQszaEokQYO56Oe2uzyWOy_cGlaOywfc,27798
29
- sciv/tool/__init__.py,sha256=WXzHkWt6RgBC3qqD-98nR5wQmt6oC850ox_VpMrapSU,2468
30
- sciv/tool/_algorithm_.py,sha256=55G9fuMdH-QDxw8ngIHhYn9gFWGqKelILUfnHUxVioE,54060
29
+ sciv/tool/__init__.py,sha256=WgyiWuCvBadTZfNEB70VurbN1YfpNodnVCIcAABTYEA,2512
30
+ sciv/tool/_algorithm_.py,sha256=5H_LHGyRfx0ng9wm8pux0_dEXuJJJVdnGLM9MjD12Fo,53682
31
31
  sciv/tool/_matrix_.py,sha256=SnC3sXic_ufuEXStcD_HncvYH6apBdNK6nhG6jFLmjA,24324
32
32
  sciv/tool/_random_walk_.py,sha256=2DPBRtd4A2MadfYDhkTw33WOATriiCULozNsUPE6lsY,48912
33
33
  sciv/util/__init__.py,sha256=nER-hRRaBGl3CGgl2rLZAUOQ3uY6-m9wQ9VNrjO5EFE,2014
34
34
  sciv/util/_constant_.py,sha256=w0wKQd8guLd1ZTW24_5aECrWsIWDiNQmEpLsWlHar1A,3000
35
35
  sciv/util/_core_.py,sha256=3Z5r_ssFEYGc0ZHSaRPLz6Ur4LKKMyOBA76qX_Kmemw,16982
36
- sciv-0.0.102.dist-info/METADATA,sha256=N5KQ3-MTOHaQDFhMRtvFGJXCOrXA79EIRRWEQwG3aXQ,3495
37
- sciv-0.0.102.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
- sciv-0.0.102.dist-info/licenses/LICENSE,sha256=4UvHVf3qCOZjHLs4LkYz8u96XRpXnZrpTKrkUQPs5_A,1075
39
- sciv-0.0.102.dist-info/RECORD,,
36
+ sciv-0.0.103.dist-info/METADATA,sha256=sUdT4krE1mTLee_PvzQXg0syisUxPtNf-1DHXVGVFyE,3495
37
+ sciv-0.0.103.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
38
+ sciv-0.0.103.dist-info/licenses/LICENSE,sha256=4UvHVf3qCOZjHLs4LkYz8u96XRpXnZrpTKrkUQPs5_A,1075
39
+ sciv-0.0.103.dist-info/RECORD,,
File without changes