Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Add pi0estimation extended error help into separate PR from PR … #103

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pyprophet/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,13 @@ def plot_scores(df, out, color_palette="normal"):
plt.subplot(212)

pdf.savefig()
plt.close()
plt.close()

def plot_hist(x, title, xlabel, ylabel, pdf_path="histogram_plot.png"):

if plt is not None:
counts, __, __ = plt.hist(x, bins=20, density=True)
plt.title(title, wrap=True)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.savefig(pdf_path)
4 changes: 3 additions & 1 deletion pyprophet/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .optimized import (find_nearest_matches as _find_nearest_matches,
count_num_positives, single_chromatogram_hypothesis_fast)
from .report import plot_hist
from statsmodels.nonparametric.kde import KDEUnivariate
from collections import namedtuple
# from .config import CONFIG
Expand Down Expand Up @@ -224,7 +225,8 @@ def pi0est(p_values, lambda_ = np.arange(0.05,1.0,0.05), pi0_method = "smoother"
else:
raise click.ClickException("pi0_method must be one of 'smoother' or 'bootstrap'.")
if (pi0<=0):
raise click.ClickException("The estimated pi0 <= 0. Check that you have valid p-values or use a different range of lambda.")
plot_hist(p, f"p-value density histogram used during pi0 estimation", "p-value", "density histogram", "pi0_estimation_error_pvalue_histogram_plot.pdf")
raise click.ClickException(f"The estimated pi0 <= 0. Check that you have valid p-values or use a different range of lambda. Current lambda range: {lambda_}")

return {'pi0': pi0, 'pi0_lambda': pi0_lambda, 'lambda_': lambda_, 'pi0_smooth': pi0Smooth}

Expand Down