-
Notifications
You must be signed in to change notification settings - Fork 20
/
convertToFasta_bh_correction.cpp
129 lines (95 loc) · 2.58 KB
/
convertToFasta_bh_correction.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <string>
#include <limits>
#include <vector>
#include <algorithm>
using namespace std;
//#include <pthread.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define MAX_REC_LEN 10240
#define eps 1e-30
long long int findkcase(long long int totkmer){
long long int m = totkmer;
FILE *in=fopen("pvals_case_top_merged_sorted.txt","r");
char *line= new char[MAX_REC_LEN];
int MAX_FILE_READ=MAX_REC_LEN/sizeof(line[0]);
long long int k = 1;
long long int maxk = 0;
while(fgets(line, MAX_FILE_READ, in)!=NULL){
char *temp=strtok(line,"\t\n ");
double pval=atof(temp);
double comp = 0.05*(((double)k)/(double)m);
if(pval<comp || fabs(pval-comp)<eps){
maxk = max(k,maxk);
}
k = k+1;
}
fclose(in);
return maxk;
}
long long int findkcontrol(long long int totkmer){
long long int m = totkmer;
FILE *in=fopen("pvals_control_top_merged_sorted.txt","r");
char *line= new char[MAX_REC_LEN];
int MAX_FILE_READ=MAX_REC_LEN/sizeof(line[0]);
long long int k = 1;
long long int maxk = 0;
while(fgets(line, MAX_FILE_READ, in)!=NULL){
char *temp=strtok(line,"\t\n ");
double pval=atof(temp);
double comp = 0.05*(((double)k)/(double)m);
if(pval<comp || fabs(pval-comp)<eps){
maxk = max(k,maxk);
}
k = k+1;
}
fclose(in);
return maxk;
}
int main(int argc, const char * argv[])
{
FILE *inFile=fopen("pvals_case_top_merged_sorted.txt","r");
FILE *outFile=fopen("case_kmers_bh_correction.fasta","w");
FILE *totalFile=fopen("total_kmers.txt","r");
char *line= new char[MAX_REC_LEN];
char *line2= new char[MAX_REC_LEN];
char *temp;
double pval;
long long int totalKmers;
fscanf(totalFile,"%lld",&totalKmers);
long long int kcase = findkcase(totalKmers);
//cout<<kcase<<"\n";
int MAX_FILE_READ=MAX_REC_LEN/sizeof(line[0]);
long long int k = 1;
while(k <= kcase){
fgets(line, MAX_FILE_READ, inFile);
temp=strtok(line,"\t\n ");
pval=atof(temp);
temp=strtok(NULL,"\t\n ");
fprintf(outFile,">%e\n%s\n",pval,temp);
k = k+1;
}
fclose(inFile);
fclose(outFile);
//fclose(totalFile);
inFile=fopen("pvals_control_top_merged_sorted.txt","r");
outFile=fopen("control_kmers_bh_correction.fasta","w");
long long int kcontrol = findkcontrol(totalKmers);
k = 1;
//cout<<kcontrol<<"\n";
while(k <= kcontrol){
fgets(line, MAX_FILE_READ, inFile);
temp=strtok(line,"\t\n ");
pval=atof(temp);
temp=strtok(NULL,"\t\n ");
fprintf(outFile,">%e\n%s\n",pval,temp);
k = k+1;
}
fclose(inFile);
fclose(outFile);
fclose(totalFile);
}