Commit 8f142c83 authored by Yannis Duffourd's avatar Yannis Duffourd

Implementing new method to FET computing, not in used actually

parent 4f1e74c9
...@@ -214,3 +214,109 @@ char checkBase(char incoming ) ...@@ -214,3 +214,109 @@ char checkBase(char incoming )
} }
return 'N'; return 'N';
} }
//Method for calculating a sd from a vector of double
double sd_calculator( vector<double> incVector )
{
// Déclarations
double sd;
double temp_value;
double sumone = 0;
double sumtwo = 0;
double moyenne;
int number = 0;
double variance;
// calcul des moyennes et moyennes carrées
vector<double>::iterator myIter;
for( myIter = incVector.begin() ; myIter != incVector.end() ; myIter ++ )
{
temp_value = * myIter;
sumone += temp_value;
sumtwo += ( temp_value * temp_value );
number ++;
}
// calcul de la moyenne
moyenne = sumone / number;
// Calcul de la variance
variance = ( sumtwo / number ) - ( moyenne * moyenne );
// Calcul ecart type
sd = sqrt(variance);
return sd;
}
// Method for calculating a mean from a vector of double
double moyenne_calculator( vector<double> incVector )
{
// Déclarations
double temp_value;
double sumone;
double moyenne;
int number = 0;
// calcul des moyennes et moyennes carrées
vector<double>::iterator myIter;
for( myIter = incVector.begin() ; myIter != incVector.end() ; myIter ++ )
{
temp_value = * myIter;
sumone += temp_value;
number ++;
}
// calcul de la moyenne
if( number != 0 )
{
moyenne = sumone / number;
}
else
{
return 0;
}
return moyenne;
}
// Method for calculating fisher exact test 2-sided, return the pvalue.
double FET( int a , int b , int c , int d )
{
int n = a + b + c + d;
double logpCutOff = logHypergeometricProb( a , b , c , d );
double pFraction = 0;
double logpValue = 0;
for( int x = 0 ; x <= n ; x ++ )
{
if( ( a + b - x >= 0 ) && ( a + c - x >= 0 ) && ( d - a + x >= 0 ) )
{
double l = logHypergeometricProb( x , a + b - x , a + c - x , d - a + x );
if( l <= logpCutOff )
{
pFraction += exp( l - logpCutOff );
}
}
}
logpValue = logpCutOff + log( pFraction );
return exp(logpValue);
}
// method for calculating the hypergeometrical log value for the FET.
double logHypergeometricProb( int a , int b , int c , int d )
{
return logFactoriel( a + b ) + logFactoriel( c + d ) + logFactoriel( a + c ) + logFactoriel( b + d )- logFactoriel( a ) - logFactoriel( b ) - logFactoriel( c ) - logFactoriel( d ) - logFactoriel( a + b + c + d );
}
// Method for calculating a log factoriel
double logFactoriel( int inc )
{
double ret;
for( ret = 0 ; inc > 0 ; inc -- )
{
ret += log( (double)inc );
}
return ret;
}
...@@ -17,7 +17,10 @@ char string_to_char( std::string ); ...@@ -17,7 +17,10 @@ char string_to_char( std::string );
std::string strip( std::string ); std::string strip( std::string );
double chisquare( std::vector<double>, std::vector<double> ); double chisquare( std::vector<double>, std::vector<double> );
double fisher_test(std::vector<double> , std::vector<double> ); double fisher_test(std::vector<double> , std::vector<double> );
double sd_calculator( std::vector<double> );
double moyenne_calculator( std::vector<double> );
double FET( int , int , int , int );
double logHypergeometricProb( int , int , int , int );
double logFactoriel( int );
#endif #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