maradoner 0.14.1__tar.gz → 0.14.3__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.

Potentially problematic release.


This version of maradoner might be problematic. Click here for more details.

Files changed (26) hide show
  1. {maradoner-0.14.1 → maradoner-0.14.3}/PKG-INFO +5 -5
  2. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/__init__.py +3 -2
  3. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/create.py +1 -1
  4. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/grn.py +60 -8
  5. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/main.py +2 -2
  6. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner.egg-info/PKG-INFO +5 -5
  7. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner.egg-info/requires.txt +1 -0
  8. {maradoner-0.14.1 → maradoner-0.14.3}/setup.py +3 -4
  9. {maradoner-0.14.1 → maradoner-0.14.3}/README.md +0 -0
  10. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/dataset_filter.py +0 -0
  11. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/export.py +0 -0
  12. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/fit.py +0 -0
  13. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/mara/__init__.py +0 -0
  14. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/mara/export.py +0 -0
  15. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/mara/fit.py +0 -0
  16. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/mara/main.py +0 -0
  17. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/mara.py +0 -0
  18. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/meta_optimizer.py +0 -0
  19. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/select.py +0 -0
  20. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/synthetic_data.py +0 -0
  21. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner/utils.py +0 -0
  22. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner.egg-info/SOURCES.txt +0 -0
  23. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner.egg-info/dependency_links.txt +0 -0
  24. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner.egg-info/entry_points.txt +0 -0
  25. {maradoner-0.14.1 → maradoner-0.14.3}/maradoner.egg-info/top_level.txt +0 -0
  26. {maradoner-0.14.1 → maradoner-0.14.3}/setup.cfg +0 -0
@@ -1,17 +1,16 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maradoner
3
- Version: 0.14.1
3
+ Version: 0.14.3
4
4
  Summary: Variance-adjusted estimation of motif activities.
5
- Home-page: https://github.com/autosome-ru/nemara
5
+ Home-page: https://github.com/autosome-ru/maradoner
6
6
  Author: Georgy Meshcheryakov
7
7
  Author-email: iam@georgy.top
8
- Classifier: Programming Language :: Python :: 3.9
9
- Classifier: Programming Language :: Python :: 3.10
10
8
  Classifier: Programming Language :: Python :: 3.11
11
9
  Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
12
11
  Classifier: Topic :: Scientific/Engineering
13
12
  Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.9
13
+ Requires-Python: >=3.11
15
14
  Description-Content-Type: text/markdown
16
15
  Requires-Dist: pip>=24.0
17
16
  Requires-Dist: typer>=0.13
@@ -27,6 +26,7 @@ Requires-Dist: dill>=0.3.9
27
26
  Requires-Dist: rich>=12.6.0
28
27
  Requires-Dist: tqdm>=4.0
29
28
  Requires-Dist: scikit-learn>=1.6
29
+ Requires-Dist: tables>=3.10
30
30
 
31
31
 
32
32
  **MARADONER**
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = '0.14.1'
2
+ __version__ = '0.14.3'
3
3
  import importlib
4
4
 
5
5
 
@@ -17,7 +17,8 @@ __min_reqs__ = [
17
17
  'dill>=0.3.9',
18
18
  'rich>=12.6.0',
19
19
  'tqdm>=4.0',
20
- 'scikit-learn>=1.6'
20
+ 'scikit-learn>=1.6',
21
+ 'tables>=3.10'
21
22
  ]
22
23
 
23
24
  def versiontuple(v):
@@ -13,7 +13,7 @@ def transform_loadings(df, mode: str, zero_cutoff=1e-9, prom_inds=None):
13
13
  df[df < zero_cutoff] = 0
14
14
  df = (df - df.min(axis=None)) / (df.max(axis=None) - df.min(axis=None))
15
15
  stds = df.std()
16
- drop_inds = (stds < 1e-16) | np.isnan(stds)
16
+ drop_inds = (stds == 0) | np.isnan(stds)
17
17
  if prom_inds is not None:
18
18
  df = df.loc[prom_inds, ~drop_inds]
19
19
  else:
@@ -3,12 +3,11 @@ import numpy as np
3
3
  import jax.numpy as jnp
4
4
  import jax
5
5
  from .utils import read_init, openers, ProjectData
6
- from .fit import FOVResult, ActivitiesPrediction, FitResult
7
- from scipy.optimize import minimize_scalar, minimize
6
+ from .fit import ActivitiesPrediction, FitResult
7
+ from scipy.optimize import minimize
8
8
  import os
9
9
  import dill
10
10
  from pandas import DataFrame as DF
11
- from scipy.stats import norm
12
11
  from functools import partial
13
12
  from tqdm import tqdm
14
13
 
@@ -20,6 +19,8 @@ def estimate_promoter_prior_variance(data: ProjectData, activities: ActivitiesPr
20
19
  group_inds = data.group_inds
21
20
  Y = Y - fit.promoter_mean.mean.reshape(-1, 1) - fit.sample_mean.mean.reshape(1, -1)
22
21
  Y = Y - B @ fit.motif_mean.mean.reshape(-1, 1)
22
+ if activities.filtered_motifs is not None and len(activities.filtered_motifs):
23
+ B = np.delete(B, activities.filtered_motifs, axis=1)
23
24
  Y = np.concatenate([Y[:, inds].mean(axis=1, keepdims=True) - B @ U.reshape(-1, 1)
24
25
  for inds, U in zip(group_inds, activities.U.T)],
25
26
  axis=1)
@@ -53,13 +54,14 @@ def estimate_promoter_variance(project_name: str, prior_top=0.90):
53
54
  top=prior_top)
54
55
  print('Piror standard deviation:', prior_var ** 0.5)
55
56
  prior_means = fit.error_variance.variance
56
-
57
57
  Y = Y - fit.promoter_mean.mean.reshape(-1, 1) - fit.sample_mean.mean.reshape(1, -1)
58
58
  Y = Y - B @ fit.motif_mean.mean.reshape(-1, 1)
59
59
  Y = Y ** 2
60
60
  B_hat = B ** 2 * fit.motif_variance.motif
61
61
  B_hat = B_hat.sum(axis=1)
62
62
  var = list()
63
+ jax.config.update('jax_enable_x64', True)
64
+ jax.config.update('jax_platform_name', 'cpu')
63
65
  for inds, prior_mean, nu in tqdm(list(zip(group_inds, prior_means, fit.motif_variance.group))):
64
66
  Yt = Y[:, inds].sum(axis=1)
65
67
  s = len(inds)
@@ -78,6 +80,47 @@ def estimate_promoter_variance(project_name: str, prior_top=0.90):
78
80
  return var
79
81
 
80
82
 
83
+ def bayesian_fdr_control(p0, alpha=0.05):
84
+ """
85
+ Control Bayesian FDR using sorted posterior probabilities of H0.
86
+
87
+ Args:
88
+ p0: Array of posterior probabilities P(H0|X) for each hypothesis.
89
+ alpha: Target FDR level (e.g., 0.05).
90
+
91
+ Returns:
92
+ discoveries: Boolean array (True = reject H0).
93
+ threshold: Rejection threshold for P(H0|X).
94
+ """
95
+ p0 = np.asarray(p0)
96
+ if p0.size == 0:
97
+ return np.zeros_like(p0, dtype=bool), -np.inf
98
+
99
+ # Sort in ascending order
100
+ sorted_p0 = np.sort(p0)
101
+ m = len(sorted_p0)
102
+
103
+ # Compute cumulative FDR = (sum_{i=1}^k p_i) / k
104
+ cum_sum = np.cumsum(sorted_p0)
105
+ fdr_k = cum_sum / np.arange(1, m + 1)
106
+
107
+ # Find largest k where FDR(k) <= alpha
108
+ valid_indices = np.where(fdr_k <= alpha)[0] # 0-based indices
109
+ if len(valid_indices) == 0:
110
+ k = 0
111
+ else:
112
+ k = valid_indices[-1] + 1 # Convert to 1-based index
113
+
114
+ # Set threshold and discover
115
+ if k > 0:
116
+ threshold = sorted_p0[k - 1] # k-th element (0-indexed at k-1)
117
+ discoveries = p0 <= threshold
118
+ else:
119
+ threshold = -np.inf
120
+ discoveries = np.zeros_like(p0, dtype=bool)
121
+
122
+ return discoveries, threshold
123
+
81
124
  def grn(project_name: str, output: str, use_hdf=False, save_stat=True,
82
125
  fdr_alpha=0.05, prior_h1=1/100):
83
126
  data = read_init(project_name)
@@ -153,11 +196,20 @@ def grn(project_name: str, output: str, use_hdf=False, save_stat=True,
153
196
  lr = lr[inds]
154
197
  belief = belief[inds]
155
198
  belief = belief.astype(np.half)
156
- sorted_beliefs = np.sort(belief.flatten())
157
- cumulative_fdr = np.cumsum(sorted_beliefs) / (np.arange(len(sorted_beliefs)) + 1)
199
+ # fdr_threshold = bayesian_fdr_control(belief.flatten(), fdr_alpha)
200
+ # print(fdr_threshold[0].mean(), fdr_threshold[1])
201
+ # fdr_threshold = fdr_threshold[1]
202
+ sorted_beliefs = belief.flatten()
203
+ sorted_beliefs = sorted_beliefs[sorted_beliefs > 0.5]
204
+ sorted_beliefs = np.sort(sorted_beliefs)[::-1]
205
+ sorted_inbeliefs = 1 - sorted_beliefs
206
+
207
+ cumulative_fdr = np.cumsum(sorted_inbeliefs) / (np.arange(len(sorted_inbeliefs)) + 1)
208
+ # print(fdr_alpha)
158
209
  try:
159
- k = np.max(np.where(cumulative_fdr <= fdr_alpha)[0])
160
- fdr_threshold = sorted_beliefs[k-1]
210
+ k = np.min(np.where(cumulative_fdr <= fdr_alpha)[0])
211
+ fdr_threshold = sorted_beliefs[k]
212
+ print(k, fdr_threshold)
161
213
  except ValueError:
162
214
  fdr_threshold = 1.0
163
215
  filename = os.path.join(folder_belief, f'{name}.txt')
@@ -314,7 +314,7 @@ def _select_motifs(name: str = Argument(..., help='Project name'),
314
314
 
315
315
  __grn_doc = 'Tests each promoter against each motif per each group. Some people call it GRN.'
316
316
  @app.command('grn',
317
- help=__select_motif_doc)
317
+ help=__grn_doc)
318
318
  def _grn(name: str = Argument(..., help='Project name'),
319
319
  folder: Path = Argument(..., help='Output folder where results will be stored. In total, expect number_of_groups tables of size'
320
320
  ' comparable to the expression file size.'),
@@ -331,7 +331,7 @@ def _grn(name: str = Argument(..., help='Project name'),
331
331
  rprint(f'[green][bold]✔️[/bold] Done![/green]\t time: {dt:.2f} s.')
332
332
 
333
333
  __estimate_promvar_doc = 'Estimates each promoter variance for each group using empirical Bayesian shrinkage.'\
334
- ' A necessary step before computing GRN.'
334
+ ' A very recommended step before computing GRN.'
335
335
  @app.command('estimate-promoter-variance',
336
336
  help=__estimate_promvar_doc)
337
337
  def _estimate_promoter_variance(name: str = Argument(..., help='Project name'),
@@ -1,17 +1,16 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maradoner
3
- Version: 0.14.1
3
+ Version: 0.14.3
4
4
  Summary: Variance-adjusted estimation of motif activities.
5
- Home-page: https://github.com/autosome-ru/nemara
5
+ Home-page: https://github.com/autosome-ru/maradoner
6
6
  Author: Georgy Meshcheryakov
7
7
  Author-email: iam@georgy.top
8
- Classifier: Programming Language :: Python :: 3.9
9
- Classifier: Programming Language :: Python :: 3.10
10
8
  Classifier: Programming Language :: Python :: 3.11
11
9
  Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
12
11
  Classifier: Topic :: Scientific/Engineering
13
12
  Classifier: Operating System :: OS Independent
14
- Requires-Python: >=3.9
13
+ Requires-Python: >=3.11
15
14
  Description-Content-Type: text/markdown
16
15
  Requires-Dist: pip>=24.0
17
16
  Requires-Dist: typer>=0.13
@@ -27,6 +26,7 @@ Requires-Dist: dill>=0.3.9
27
26
  Requires-Dist: rich>=12.6.0
28
27
  Requires-Dist: tqdm>=4.0
29
28
  Requires-Dist: scikit-learn>=1.6
29
+ Requires-Dist: tables>=3.10
30
30
 
31
31
 
32
32
  **MARADONER**
@@ -12,3 +12,4 @@ dill>=0.3.9
12
12
  rich>=12.6.0
13
13
  tqdm>=4.0
14
14
  scikit-learn>=1.6
15
+ tables>=3.10
@@ -23,13 +23,12 @@ setup(
23
23
  author='Georgy Meshcheryakov',
24
24
  author_email='iam@georgy.top',
25
25
  install_requires=__min_reqs__,
26
- python_requires='>=3.9',
27
- url="https://github.com/autosome-ru/nemara",
26
+ python_requires='>=3.11',
27
+ url="https://github.com/autosome-ru/maradoner",
28
28
  classifiers=[
29
- "Programming Language :: Python :: 3.9",
30
- "Programming Language :: Python :: 3.10",
31
29
  "Programming Language :: Python :: 3.11",
32
30
  "Programming Language :: Python :: 3.12",
31
+ "Programming Language :: Python :: 3.13",
33
32
  "Topic :: Scientific/Engineering",
34
33
  "Operating System :: OS Independent"]
35
34
 
File without changes
File without changes
File without changes
File without changes