maradoner 0.14.1__tar.gz → 0.14.2__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.
- {maradoner-0.14.1 → maradoner-0.14.2}/PKG-INFO +1 -1
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/__init__.py +1 -1
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/create.py +1 -1
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/grn.py +58 -8
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/main.py +1 -1
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner.egg-info/PKG-INFO +1 -1
- {maradoner-0.14.1 → maradoner-0.14.2}/README.md +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/dataset_filter.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/export.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/fit.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/mara/__init__.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/mara/export.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/mara/fit.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/mara/main.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/mara.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/meta_optimizer.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/select.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/synthetic_data.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner/utils.py +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner.egg-info/SOURCES.txt +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner.egg-info/dependency_links.txt +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner.egg-info/entry_points.txt +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner.egg-info/requires.txt +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/maradoner.egg-info/top_level.txt +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/setup.cfg +0 -0
- {maradoner-0.14.1 → maradoner-0.14.2}/setup.py +0 -0
|
@@ -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
|
|
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
|
|
7
|
-
from scipy.optimize import
|
|
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,7 +54,6 @@ 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
|
|
@@ -78,6 +78,47 @@ def estimate_promoter_variance(project_name: str, prior_top=0.90):
|
|
|
78
78
|
return var
|
|
79
79
|
|
|
80
80
|
|
|
81
|
+
def bayesian_fdr_control(p0, alpha=0.05):
|
|
82
|
+
"""
|
|
83
|
+
Control Bayesian FDR using sorted posterior probabilities of H0.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
p0: Array of posterior probabilities P(H0|X) for each hypothesis.
|
|
87
|
+
alpha: Target FDR level (e.g., 0.05).
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
discoveries: Boolean array (True = reject H0).
|
|
91
|
+
threshold: Rejection threshold for P(H0|X).
|
|
92
|
+
"""
|
|
93
|
+
p0 = np.asarray(p0)
|
|
94
|
+
if p0.size == 0:
|
|
95
|
+
return np.zeros_like(p0, dtype=bool), -np.inf
|
|
96
|
+
|
|
97
|
+
# Sort in ascending order
|
|
98
|
+
sorted_p0 = np.sort(p0)
|
|
99
|
+
m = len(sorted_p0)
|
|
100
|
+
|
|
101
|
+
# Compute cumulative FDR = (sum_{i=1}^k p_i) / k
|
|
102
|
+
cum_sum = np.cumsum(sorted_p0)
|
|
103
|
+
fdr_k = cum_sum / np.arange(1, m + 1)
|
|
104
|
+
|
|
105
|
+
# Find largest k where FDR(k) <= alpha
|
|
106
|
+
valid_indices = np.where(fdr_k <= alpha)[0] # 0-based indices
|
|
107
|
+
if len(valid_indices) == 0:
|
|
108
|
+
k = 0
|
|
109
|
+
else:
|
|
110
|
+
k = valid_indices[-1] + 1 # Convert to 1-based index
|
|
111
|
+
|
|
112
|
+
# Set threshold and discover
|
|
113
|
+
if k > 0:
|
|
114
|
+
threshold = sorted_p0[k - 1] # k-th element (0-indexed at k-1)
|
|
115
|
+
discoveries = p0 <= threshold
|
|
116
|
+
else:
|
|
117
|
+
threshold = -np.inf
|
|
118
|
+
discoveries = np.zeros_like(p0, dtype=bool)
|
|
119
|
+
|
|
120
|
+
return discoveries, threshold
|
|
121
|
+
|
|
81
122
|
def grn(project_name: str, output: str, use_hdf=False, save_stat=True,
|
|
82
123
|
fdr_alpha=0.05, prior_h1=1/100):
|
|
83
124
|
data = read_init(project_name)
|
|
@@ -153,11 +194,20 @@ def grn(project_name: str, output: str, use_hdf=False, save_stat=True,
|
|
|
153
194
|
lr = lr[inds]
|
|
154
195
|
belief = belief[inds]
|
|
155
196
|
belief = belief.astype(np.half)
|
|
156
|
-
|
|
157
|
-
|
|
197
|
+
# fdr_threshold = bayesian_fdr_control(belief.flatten(), fdr_alpha)
|
|
198
|
+
# print(fdr_threshold[0].mean(), fdr_threshold[1])
|
|
199
|
+
# fdr_threshold = fdr_threshold[1]
|
|
200
|
+
sorted_beliefs = belief.flatten()
|
|
201
|
+
sorted_beliefs = sorted_beliefs[sorted_beliefs > 0.5]
|
|
202
|
+
sorted_beliefs = np.sort(sorted_beliefs)[::-1]
|
|
203
|
+
sorted_inbeliefs = 1 - sorted_beliefs
|
|
204
|
+
|
|
205
|
+
cumulative_fdr = np.cumsum(sorted_inbeliefs) / (np.arange(len(sorted_inbeliefs)) + 1)
|
|
206
|
+
# print(fdr_alpha)
|
|
158
207
|
try:
|
|
159
|
-
k = np.
|
|
160
|
-
fdr_threshold = sorted_beliefs[k
|
|
208
|
+
k = np.min(np.where(cumulative_fdr <= fdr_alpha)[0])
|
|
209
|
+
fdr_threshold = sorted_beliefs[k]
|
|
210
|
+
print(k, fdr_threshold)
|
|
161
211
|
except ValueError:
|
|
162
212
|
fdr_threshold = 1.0
|
|
163
213
|
filename = os.path.join(folder_belief, f'{name}.txt')
|
|
@@ -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
|
|
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'),
|
|
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
|