Commit 5abb3753 authored by Yannis Duffourd's avatar Yannis Duffourd

adding statistical tests (FET, CHI2), need a probable rewamp

parent 552afefb
......@@ -5,14 +5,21 @@
#include <sstream>
#include <stdexcept>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sys/time.h>
#include <sys/types.h>
#include <boost/math/distributions/chi_squared.hpp>
#include <boost/math/distributions/hypergeometric.hpp>
#include "utils.h"
using namespace std;
using namespace boost::math;
using boost::math::chi_squared;
using boost::math::quantile;
using boost::math::complement;
using boost::math::cdf;
// test if a file is readable
// return value : true if readable ; false if not
......@@ -80,6 +87,9 @@ string char_to_string(char incoming)
vector<string> parseOnSep( string inc , string sep )
{
// cerr << "Entering ParseOnSep function" << endl;
// cerr << "\tIncoming string : " << inc << " ; separator : " << sep << endl;
vector<string> ret;
istringstream issInc (inc);
string mot;
......@@ -116,16 +126,48 @@ string strip( string inc )
return inc;
}
double chisquare( vector<double> toTest , vector<double> all )
{
boost::math::chi_squared chi(1);
double a1 = toTest[0] ;
double a2 = toTest[1];
double b1 = all[0];
double b2 = all[1];;
double s = a1 + a2 + b1 + b2;
double K = s * (a1 * b2 - a2 * b1) * (a1 * b2 - a2 * b1) / (a1 + a2) / (b1 + b2) / (a1 + b1) / (a2 + b2);
double P = boost::math::cdf(chi, K);
return P;
}
double fisher_test(vector<double> toTest, vector<double> control )
{
double a = toTest[0];
double b = toTest[1];
double c = control[0];
double d = control[1];
double N = a + b + c + d;
double r = a + c;
double n = c + d;
double max_for_k = min(r, n);
double min_for_k = (double)max(0, int(r + n - N));
hypergeometric_distribution<> hgd(r, n, N);
double cutoff = pdf(hgd, c);
double tmp_p = 0.0;
for(int k = min_for_k;k < max_for_k + 1;k++)
{
double p = pdf(hgd, k);
if(p <= cutoff)
{
tmp_p += p;
}
}
return tmp_p;
}
char checkBase(char incoming )
......
......@@ -15,5 +15,9 @@ std::string char_to_string(char);
std::vector<std::string> parseOnSep( std::string , std::string );
char string_to_char( std::string );
std::string strip( std::string );
double chisquare( std::vector<double>, std::vector<double> );
double fisher_test(std::vector<double> , std::vector<double> );
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment