Skip to content

Commit

Permalink
Set scale_to_one to false in *all* cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ezander committed Oct 1, 2024
1 parent 6aaf5b0 commit 11967f7
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions mokapot/peps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from typing import TypeVar, Callable, Iterator
import logging
from typing import TypeVar, Callable, Iterator

import numpy as np
import scipy.stats as stats
Expand Down Expand Up @@ -76,9 +76,7 @@ def peps_from_scores(
if pep_function is not None:
return pep_function(scores, targets, is_tdc)
else:
raise ValueError(
f"Unknown pep algorithm in peps_from_scores: {pep_algorithm}"
)
raise ValueError(f"Unknown pep algorithm in peps_from_scores: {pep_algorithm}")


@typechecked
Expand Down Expand Up @@ -417,9 +415,7 @@ def peps_from_scores_kde_nnls(
factor = (~targets).sum() / targets.sum()
else:
# Estimate pi0 and estimate number of correct targets
factor = estimate_pi0_by_slope(
target_pdf, decoy_pdf, pi0_estimation_threshold
)
factor = estimate_pi0_by_slope(target_pdf, decoy_pdf, pi0_estimation_threshold)

correct = target_pdf - decoy_pdf * factor
correct = np.clip(correct, 0, None)
Expand Down Expand Up @@ -526,9 +522,7 @@ def make_perm_mat(rows, cols):
tol = 1e-7
d, _, mode = _nnls(W @ A @ R, W @ k, tol=tol)
if mode != 1:
LOGGER.debug(
"\t - Warning: nnls went into loop. Taking last solution."
)
LOGGER.debug("\t - Warning: nnls went into loop. Taking last solution.")
p = np.cumsum(R @ d)

if not ascending:
Expand Down Expand Up @@ -744,7 +738,7 @@ def peps_from_scores_hist_nnls(
Scores and targets come from competition, rather than separate search.
scale_to_one:
Boolean value indicating whether to scale the PEP estimates to 1 for
small score values. Default is True.
small score values. Default is False.
Returns
-------
Expand All @@ -763,7 +757,7 @@ def peps_from_scores_hist_nnls(
def peps_func_from_hist_nnls(
hist_data: TDHistData,
is_tdc: bool,
scale_to_one: bool = True,
scale_to_one: bool = False,
weight_exponent: float = -1.0,
) -> Callable[[np.ndarray[float]], np.ndarray[float]]:
"""Compute a function that calculates the PEP (Posterior Error Probability)
Expand All @@ -779,7 +773,7 @@ def peps_func_from_hist_nnls(
is_tdc:
Scores and targets come from competition, rather than separate search.
scale_to_one: Scale the result if the maximum PEP is smaller than 1.
(Default value = True)
(Default value = False)
weight_exponent:
The weight exponent for the `fit_nnls` fit (see there, default 1).
Expand All @@ -799,9 +793,7 @@ def peps_func_from_hist_nnls(
# Do monotone fit, minimizing || n - diag(p) * k || with weights n over
# monotone descending p
try:
pep_est = fit_nnls(
n, k, ascending=False, weight_exponent=weight_exponent
)
pep_est = fit_nnls(n, k, ascending=False, weight_exponent=weight_exponent)
except RuntimeError as e:
raise PepsConvergenceError from e

Expand All @@ -811,6 +803,4 @@ def peps_func_from_hist_nnls(
# Linearly interpolate the pep estimates from the eval points to the scores
# of interest (keeping monotonicity) clip in case we went slightly out of
# bounds
return lambda scores: np.clip(
np.interp(scores, eval_scores, pep_est), 0, 1
)
return lambda scores: np.clip(np.interp(scores, eval_scores, pep_est), 0, 1)

0 comments on commit 11967f7

Please sign in to comment.