sciv 0.0.101__tar.gz → 0.0.102__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.101 → sciv-0.0.102}/PKG-INFO +2 -1
  2. {sciv-0.0.101 → sciv-0.0.102}/pyproject.toml +3 -2
  3. {sciv-0.0.101 → sciv-0.0.102}/requirements.txt +2 -1
  4. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/model/_core_.py +4 -4
  5. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_pie_.py +2 -1
  6. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/preprocessing/_scanpy_.py +3 -2
  7. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/preprocessing/_scvi_.py +2 -2
  8. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/tool/_algorithm_.py +6 -6
  9. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/tool/_random_walk_.py +2 -2
  10. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/util/__init__.py +2 -0
  11. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/util/_core_.py +70 -1
  12. {sciv-0.0.101 → sciv-0.0.102}/.gitignore +0 -0
  13. {sciv-0.0.101 → sciv-0.0.102}/LICENSE +0 -0
  14. {sciv-0.0.101 → sciv-0.0.102}/MANIFEST.in +0 -0
  15. {sciv-0.0.101 → sciv-0.0.102}/README.en.md +0 -0
  16. {sciv-0.0.101 → sciv-0.0.102}/README.md +0 -0
  17. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/__init__.py +0 -0
  18. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/file/__init__.py +0 -0
  19. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/file/_read_.py +0 -0
  20. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/file/_write_.py +0 -0
  21. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/model/__init__.py +0 -0
  22. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/__init__.py +0 -0
  23. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_bar_.py +0 -0
  24. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_barcode_.py +0 -0
  25. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_box_.py +0 -0
  26. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_bubble_.py +0 -0
  27. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_core_.py +0 -0
  28. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_graph_.py +0 -0
  29. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_heat_map_.py +0 -0
  30. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_kde_.py +0 -0
  31. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_line_.py +0 -0
  32. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_radar_.py +0 -0
  33. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_scatter_.py +0 -0
  34. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_venn_.py +0 -0
  35. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/plot/_violin_.py +0 -0
  36. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/preprocessing/__init__.py +0 -0
  37. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/preprocessing/_anndata_.py +0 -0
  38. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/preprocessing/_gencode_.py +0 -0
  39. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/preprocessing/_gsea_.py +0 -0
  40. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/preprocessing/_snapatac_.py +0 -0
  41. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/tool/__init__.py +0 -0
  42. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/tool/_matrix_.py +0 -0
  43. {sciv-0.0.101 → sciv-0.0.102}/src/sciv/util/_constant_.py +0 -0
  44. {sciv-0.0.101 → sciv-0.0.102}/tests/scivTest/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sciv
3
- Version: 0.0.101
3
+ Version: 0.0.102
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>
@@ -48,6 +48,7 @@ Requires-Dist: numba==0.60.0
48
48
  Requires-Dist: numpy==1.26.4
49
49
  Requires-Dist: palettable==3.3.3
50
50
  Requires-Dist: pandas==1.5.3
51
+ Requires-Dist: psutil==7.2.1
51
52
  Requires-Dist: pycomplexheatmap==1.6.1
52
53
  Requires-Dist: pynndescent==0.5.13
53
54
  Requires-Dist: scanpy==1.11.5
@@ -3,7 +3,7 @@ requires = ["hatchling"]
3
3
  build-backend = "hatchling.build"
4
4
  [project]
5
5
  name = "sciv"
6
- version = "0.0.101"
6
+ version = "0.0.102"
7
7
  authors = [
8
8
  { name = "Zheng-Min Yu", email = "yuzmbio@163.com" },
9
9
  ]
@@ -48,7 +48,8 @@ dependencies = [
48
48
  "louvain==0.8.2",
49
49
  "numba==0.60.0",
50
50
  "pynndescent==0.5.13",
51
- "fa2-modified==0.4"
51
+ "fa2-modified==0.4",
52
+ "psutil==7.2.1"
52
53
  ]
53
54
  classifiers = [
54
55
  "Programming Language :: Python :: 3",
@@ -28,4 +28,5 @@ louvain==0.8.2
28
28
  snapatac2==2.7.1
29
29
  numba==0.60.0
30
30
  pynndescent==0.5.13
31
- fa2-modified==0.4
31
+ fa2-modified==0.4
32
+ psutil==7.2.1
@@ -21,7 +21,7 @@ __name__: str = "model_core"
21
21
 
22
22
 
23
23
  def _run_random_walk_(random_walk: RandomWalk, is_ablation: bool, is_simple: bool) -> AnnData:
24
- start_time = time.time()
24
+ start_time = time.perf_counter()
25
25
 
26
26
  if not random_walk.is_run_core:
27
27
  random_walk.run_core()
@@ -57,7 +57,7 @@ def _run_random_walk_(random_walk: RandomWalk, is_ablation: bool, is_simple: boo
57
57
  if not random_walk.is_run_en_ablation_m_knn:
58
58
  random_walk.run_en_ablation_m_knn()
59
59
 
60
- random_walk.elapsed_time += time.time() - start_time
60
+ random_walk.elapsed_time += time.perf_counter() - start_time
61
61
 
62
62
  return random_walk.trs_adata
63
63
 
@@ -181,7 +181,7 @@ def core(
181
181
  """
182
182
 
183
183
  # start time
184
- start_time = time.time()
184
+ start_time = time.perf_counter()
185
185
 
186
186
  if len(variants.keys()) == 0:
187
187
  ul.log(__name__).error("The number of mutations is empty.")
@@ -591,7 +591,7 @@ def core(
591
591
  random_walk_time = random_walk.elapsed_time
592
592
 
593
593
  # end time
594
- elapsed_time = time.time() - start_time
594
+ elapsed_time = time.perf_counter() - start_time
595
595
  step_time = poisson_vi_time + overlap_time + init_score_time + smknn_time + random_walk_time
596
596
 
597
597
  if elapsed_time < step_time:
@@ -115,6 +115,7 @@ def pie_label(
115
115
  startangle=90,
116
116
  labeldistance=label_distance,
117
117
  pctdistance=pct_distance,
118
+ wedgeprops=dict(linewidth=0),
118
119
  **kwargs
119
120
  )
120
121
  ax.pie(
@@ -122,7 +123,7 @@ def pie_label(
122
123
  colors=['white'],
123
124
  radius=radius,
124
125
  startangle=90,
125
- wedgeprops=dict(width=radius, edgecolor='w'),
126
+ wedgeprops=dict(width=radius, edgecolor='w', linewidth=0),
126
127
  **kwargs
127
128
  )
128
129
  ax.text(0, 0, "{:.2f}%".format(top_x[0] / top_sum * 100), ha='center', va='center', fontsize=fontsize)
@@ -1,4 +1,5 @@
1
1
  # -*- coding: UTF-8 -*-
2
+
2
3
  import time
3
4
  import warnings
4
5
  from typing import Optional, Literal
@@ -47,7 +48,7 @@ def filter_data(
47
48
  """
48
49
 
49
50
  # start time
50
- start_time = time.time()
51
+ start_time = time.perf_counter()
51
52
 
52
53
  import scanpy as sc
53
54
 
@@ -109,7 +110,7 @@ def filter_data(
109
110
  )
110
111
  ul.log(__name__).info(f"Size of filtered scATAC-seq data: {filter_adata.shape}")
111
112
  filter_adata.uns["step"] = 0
112
- filter_adata.uns["elapsed_time"] = time.time() - start_time
113
+ filter_adata.uns["elapsed_time"] = time.perf_counter() - start_time
113
114
 
114
115
  return filter_adata
115
116
 
@@ -50,7 +50,7 @@ def poisson_vi(
50
50
  """
51
51
  ul.log(__name__).info("Start PoissonVI")
52
52
 
53
- start_time = time.time()
53
+ start_time = time.perf_counter()
54
54
 
55
55
  import scvi
56
56
  import scanpy as sc
@@ -241,7 +241,7 @@ def poisson_vi(
241
241
  da_peaks_adata.layers["emp_prob1"] = matrix_ep1
242
242
  da_peaks_adata.uns["latent_name"] = latent_name
243
243
  da_peaks_adata.uns["dp_delta"] = dp_delta
244
- da_peaks_adata.uns["elapsed_time"] = time.time() - start_time
244
+ da_peaks_adata.uns["elapsed_time"] = time.perf_counter() - start_time
245
245
 
246
246
  adata.uns["step"] = 1
247
247
 
@@ -913,7 +913,7 @@ def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame, n_jobs:
913
913
  :return: overlap data
914
914
  """
915
915
 
916
- start_time = time.time()
916
+ start_time = time.perf_counter()
917
917
 
918
918
  # Unique feature set
919
919
  label_all = regions.var.index.tolist()
@@ -1025,7 +1025,7 @@ def overlap_sum(regions: AnnData, variants: dict, trait_info: DataFrame, n_jobs:
1025
1025
 
1026
1026
  overlap_adata = AnnData(overlap_sparse, var=trait_info, obs=regions.var)
1027
1027
  overlap_adata.uns["is_overlap"] = True
1028
- overlap_adata.uns["elapsed_time"] = time.time() - start_time
1028
+ overlap_adata.uns["elapsed_time"] = time.perf_counter() - start_time
1029
1029
 
1030
1030
  return overlap_adata
1031
1031
 
@@ -1129,7 +1129,7 @@ def calculate_init_score_weight(
1129
1129
  :return: Initial TRS with weight.
1130
1130
  """
1131
1131
 
1132
- start_time = time.time()
1132
+ start_time = time.perf_counter()
1133
1133
 
1134
1134
  if "is_overlap" not in overlap_adata.uns:
1135
1135
  ul.log(__name__).warning(
@@ -1258,7 +1258,7 @@ def calculate_init_score_weight(
1258
1258
  del _init_trs_ncw_, _cell_type_weight_
1259
1259
 
1260
1260
  init_trs_adata.uns["is_sample"] = is_simple
1261
- init_trs_adata.uns["elapsed_time"] = time.time() - start_time
1261
+ init_trs_adata.uns["elapsed_time"] = time.perf_counter() - start_time
1262
1262
  return init_trs_adata
1263
1263
 
1264
1264
 
@@ -1314,7 +1314,7 @@ def obtain_cell_cell_network(
1314
1314
  :return: Cell similarity data.
1315
1315
  """
1316
1316
 
1317
- start_time = time.time()
1317
+ start_time = time.perf_counter()
1318
1318
 
1319
1319
  from sklearn.metrics.pairwise import laplacian_kernel, rbf_kernel
1320
1320
 
@@ -1373,7 +1373,7 @@ def obtain_cell_cell_network(
1373
1373
  if not is_simple:
1374
1374
  cc_data.layers["cell_mutual_knn"] = to_sparse(cell_mutual_knn)
1375
1375
 
1376
- cc_data.uns["elapsed_time"] = time.time() - start_time
1376
+ cc_data.uns["elapsed_time"] = time.perf_counter() - start_time
1377
1377
 
1378
1378
  return cc_data
1379
1379
 
@@ -282,7 +282,7 @@ class RandomWalk:
282
282
  """
283
283
  ul.log(__name__).info("Random walk with weighted seed cells.")
284
284
 
285
- start_time = time.time()
285
+ start_time = time.perf_counter()
286
286
 
287
287
  # judge length
288
288
  if cc_adata.shape[0] != init_status.shape[0]:
@@ -459,7 +459,7 @@ class RandomWalk:
459
459
  del self.cell_affinity
460
460
  del init_status
461
461
 
462
- self.elapsed_time = time.time() - start_time
462
+ self.elapsed_time = time.perf_counter() - start_time
463
463
 
464
464
  def _random_walk_(
465
465
  self,
@@ -29,6 +29,7 @@ from ._constant_ import (
29
29
  from ._core_ import (
30
30
  file_method,
31
31
  log,
32
+ track_with_memory,
32
33
  to_dense,
33
34
  to_sparse,
34
35
  sum_min_max,
@@ -58,6 +59,7 @@ __all__ = [
58
59
  "log_file_path",
59
60
  "file_method",
60
61
  "log",
62
+ "track_with_memory",
61
63
  "path",
62
64
  "plot_color_types",
63
65
  "sparse_array",
@@ -4,7 +4,11 @@ import math
4
4
  import os
5
5
  import random
6
6
  import string
7
- from typing import Tuple, Union, Literal
7
+ import threading
8
+ import time
9
+ from functools import wraps
10
+ from typing import Tuple, Union, Literal, Callable, Any
11
+ import psutil
8
12
 
9
13
  import numpy as np
10
14
  import pandas as pd
@@ -35,6 +39,71 @@ def log(name: str = None) -> Logger:
35
39
  return Logger(name, log_path=os.path.join(ul.log_file_path, name), is_form_file=ul.is_form_log_file)
36
40
 
37
41
 
42
+ def track_with_memory(is_monitor: bool = False , interval: float = 60) -> Callable:
43
+ """
44
+ Decorator: Records memory usage at fixed intervals during function execution and returns the result, elapsed time, and memory list.
45
+
46
+ Parameters
47
+ ----------
48
+ is_monitor : bool, optional
49
+ Whether to enable memory monitoring, default is False.
50
+ interval : float, optional
51
+ Sampling interval (seconds), default is 60 seconds.
52
+
53
+ Returns
54
+ -------
55
+ Callable
56
+ Decorator function; when the wrapped function is called, it returns a dictionary containing:
57
+ - 'result': the original function's return value
58
+ - 'time': function execution time (seconds) if is_monitor is True, otherwise None.
59
+ - 'memory': list of sampled memory usage (bytes) if is_monitor is True, otherwise None.
60
+ """
61
+
62
+ def decorator(func) -> Callable:
63
+ @wraps(func)
64
+ def wrapper(*args, **kwargs) -> Union[Any, dict]:
65
+
66
+ if not is_monitor:
67
+ return func(*args, **kwargs)
68
+
69
+ process = psutil.Process(os.getpid())
70
+
71
+ stop_monitor = False
72
+
73
+ mem_list = []
74
+
75
+ def monitor():
76
+ nonlocal stop_monitor
77
+
78
+ while not stop_monitor:
79
+ current_mem = process.memory_info().rss
80
+ mem_list.append(current_mem)
81
+
82
+ time.sleep(interval)
83
+
84
+ t = threading.Thread(target=monitor, daemon=True)
85
+ t.start()
86
+
87
+ start_time = time.perf_counter()
88
+ _result_ = func(*args, **kwargs)
89
+ end_time = time.perf_counter()
90
+
91
+ stop_monitor = True
92
+ t.join()
93
+
94
+ exec_time = end_time - start_time
95
+
96
+ return {
97
+ 'result': _result_,
98
+ 'time': exec_time,
99
+ 'memory': mem_list
100
+ }
101
+
102
+ return wrapper
103
+
104
+ return decorator
105
+
106
+
38
107
  def to_dense(sm: matrix_data, is_array: bool = False) -> dense_data:
39
108
  """
40
109
  Convert sparse matrix to dense matrix
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