Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vihgo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gad-public
vihgo
Commits
5abb3753
Commit
5abb3753
authored
Jul 10, 2020
by
Yannis Duffourd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding statistical tests (FET, CHI2), need a probable rewamp
parent
552afefb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
7 deletions
+53
-7
utils.cpp
cpp/utils.cpp
+49
-7
utils.h
cpp/utils.h
+4
-0
No files found.
cpp/utils.cpp
View file @
5abb3753
...
...
@@ -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
)
...
...
cpp/utils.h
View file @
5abb3753
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment