statgen / pheweb

A tool to build a website to browse hundreds or thousands of GWAS.
MIT License
158 stars 65 forks source link

Fix bad qq-rendering with over-wide vertical pval bins #101

Closed pjvandehaar closed 3 years ago

pjvandehaar commented 6 years ago
diff --git a/pheweb/load/qq.py b/pheweb/load/qq.py
--- a/pheweb/load/qq.py
+++ b/pheweb/load/qq.py
@@ -20,7 +20,7 @@ import scipy.stats

 NEGLOG10_PVAL_BIN_SIZE = 0.05 # Use 0.05, 0.1, 0.15, etc
 NEGLOG10_PVAL_BIN_DIGITS = 2 # Then round to this many digits
-NUM_BINS = 1000
+NUM_BINS = 200

 NUM_MAF_RANGES = 4

@@ -69,7 +69,7 @@ def compute_qq(neglog10_pvals):
         return []

     max_exp_neglog10_pval = -math.log10(0.5 / len(neglog10_pvals))
-    max_obs_neglog10_pval = neglog10_pvals[0]
+    max_obs_neglog10_pval = min(neglog10_pvals[0], 9.01) # this matches the qq plot js.

     if max_obs_neglog10_pval == 0:
         print('WARNING: All pvalues are 1! How is that supposed to make a QQ plot?')
@@ -77,6 +77,7 @@ def compute_qq(neglog10_pvals):

     occupied_bins = set()
     for i, obs_neglog10_pval in enumerate(neglog10_pvals):
+        if obs_neglog10_pval > max_obs_neglog10_pval: continue
         exp_neglog10_pval = -math.log10( (i+0.5) / len(neglog10_pvals))
         exp_bin = int(exp_neglog10_pval / max_exp_neglog10_pval * NUM_BINS)
         obs_bin = int(obs_neglog10_pval / max_obs_neglog10_pval * NUM_BINS)
pjvandehaar commented 3 years ago

Fixed.