-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfdr.c
64 lines (56 loc) · 1.32 KB
/
fdr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "radixsort.h"
#ifdef _MSC_VER
#else
#include <unistd.h>
#endif
#include <stdint.h>
#define printfd(...) fprintf(stderr, __VA_ARGS__)
#ifndef MAX
#define MAX(A,B) ((A) > (B) ? (A) : (B))
#endif
#ifndef MIN
#define MIN(A,B) ((A) > (B) ? (B) : (A))
#endif
float fdr(float *pvals, double qval, size_t nvox) {
if ((qval < 0.0) || (qval > 1.0)) {
printfd("qval out of range (0-1).\n");
return NAN;
}
//========[PART 1: FDR THRESHOLD]========================================
//Sort p-values
float* dx_out = (float*)malloc(nvox*sizeof(float));
uint32_t* idx_in = (uint32_t*)malloc(nvox*sizeof(uint32_t));
uint32_t* idx_out = (uint32_t*)malloc(nvox*sizeof(uint32_t));
float mn = pvals[0];
float mx = pvals[0];
for (int i = 0; i < nvox; i++) {
idx_in[i] = i;
mn = MIN(mn, pvals[i]);
mx = MAX(mx, pvals[i]);
}
if ((mn < 0.0) || (mx > 1.0)) {
printfd("Values out of range (0-1).\n");
return NAN;
}
radix11sort_f32(pvals, dx_out, idx_in, idx_out, nvox);
free(idx_in);
free(idx_out);
// Order (indices), in the same size as the pvalues
int v = 0;
do {
int v2 = v;
do {
v2++;
} while ( v2 < nvox );
v++;
} while ( v < nvox );
free(dx_out);
float thresh = 66.0;
return thresh;
}