-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstColCount.cpp
More file actions
56 lines (42 loc) · 1.61 KB
/
FirstColCount.cpp
File metadata and controls
56 lines (42 loc) · 1.61 KB
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
#include<iostream>
#include<fstream>
#include<string>
// Program 1
using std::cout; using std::fstream; using std::streamoff; using std::streampos; using std::ios; using std::string; using std::flush;
#define ull unsigned long long
string lastColFilename = "data/dataset1/chrX_last_col.txt";
string rankFirstColFilename = "FirstCol.txt";
void printAndSave(ull, ull, ull, ull);
int main(int argc, char const *argv[]){
fstream lastColFile(lastColFilename, ios::in|ios::app);
char ch;
ull A_count = 0 ,C_count = 0 ,G_count = 0 ,T_count = 0;
if(!lastColFile.is_open()){
cout<<"| Unable to open "<<lastColFilename<<".\n";
return EXIT_FAILURE;
}
cout<<"Parsing...";
while (lastColFile.get(ch)){
if (ch == '\n') continue;
switch(ch){
case 'A': A_count++; break;
case 'C': C_count++; break;
case 'G': G_count++; break;
case 'T': T_count++; break;
case '$': break;
}
}
cout<<"\rParsed.\n";
printAndSave(A_count,C_count,G_count,T_count);
lastColFile.close();
}
void printAndSave(ull A_count, ull C_count, ull G_count, ull T_count){
fstream rankFirstColFile(rankFirstColFilename, ios::out|ios::trunc);
if(!rankFirstColFile.is_open()){
cout<<"| Unable to open "<<"FirstCol.txt"<<" to write into it. Output binned.\n";
return;
}
cout<<"A="<<A_count<<"\nC="<<C_count<<"\nG="<<G_count<<"\nT="<<T_count<<"\nSum="<<A_count+C_count+G_count+T_count<<"\n";
rankFirstColFile<<A_count<<'\n'<<C_count<<'\n'<<G_count<<'\n'<<T_count<<'\n';
rankFirstColFile.close();
}