[Genabel-commits] r1750 - branches/ProbABEL-pvals/ProbABEL/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 29 15:23:32 CEST 2014


Author: lckarssen
Date: 2014-05-29 15:23:32 +0200 (Thu, 29 May 2014)
New Revision: 1750

Modified:
   branches/ProbABEL-pvals/ProbABEL/src/main.cpp
   branches/ProbABEL-pvals/ProbABEL/src/main_functions_dump.cpp
Log:
In the ProbABEL p-values branch: Nicely catch the exception when chi^2 < 0. Throw the exception up and let the calling function handle it.


Modified: branches/ProbABEL-pvals/ProbABEL/src/main.cpp
===================================================================
--- branches/ProbABEL-pvals/ProbABEL/src/main.cpp	2014-05-29 13:12:41 UTC (rev 1749)
+++ branches/ProbABEL-pvals/ProbABEL/src/main.cpp	2014-05-29 13:23:32 UTC (rev 1750)
@@ -562,7 +562,16 @@
 #if WITH_BOOST_MATH
             // Calulate p-values based on the chi^2 values
             int chi2df = 1;
-            *pval[model] << pchisq(*chi2val[model], chi2df);
+            try
+            {
+                *pval[model] << pchisq(*chi2val[model], chi2df);
+            }
+            catch (std::exception &e)
+            {
+                std::cerr << mli.name[csnp] << ": "
+                          << e.what() << std::endl;
+                *pval[model] << NAN;
+            }
 #endif
         }  // END of model cycle
 

Modified: branches/ProbABEL-pvals/ProbABEL/src/main_functions_dump.cpp
===================================================================
--- branches/ProbABEL-pvals/ProbABEL/src/main_functions_dump.cpp	2014-05-29 13:12:41 UTC (rev 1749)
+++ branches/ProbABEL-pvals/ProbABEL/src/main_functions_dump.cpp	2014-05-29 13:23:32 UTC (rev 1750)
@@ -46,6 +46,7 @@
 
 #if WITH_BOOST_MATH
 #include <boost/math/distributions.hpp>
+#include <boost/exception/all.hpp>
 #endif
 
 #include "maskedmatrix.h"
@@ -495,13 +496,27 @@
 
     if (!std::isnan(chi2))
     {
-        // Initialise the distribution
-        boost::math::chi_squared chi2dist(df);
+        try
+        {
+            // Initialise the distribution
+            boost::math::chi_squared chi2dist(df);
 
-        /* Use the complement here (in R we would also set
-         * lower.tail=FALSE)
-         */
-        pval = boost::math::cdf(complement(chi2dist, chi2));
+            /* Use the complement here (in R we would also set
+             * lower.tail=FALSE)
+             */
+            pval = boost::math::cdf(complement(chi2dist, chi2));
+        }
+        catch (boost::exception &e)
+        {
+            /* Pass on exceptions like chi^2 < 0. By throwing them up
+             * a level we can make use of e.g. the SNP information
+             * when printing the error message.
+             * Note that when we 'throw' pval won't be set, so that
+             * needs to be taken care of as well in the calling
+             * function.
+             */
+            throw;
+        }
     }
     else
     {



More information about the Genabel-commits mailing list