-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_bitmap_last_col.cpp
More file actions
63 lines (49 loc) · 1.79 KB
/
vector_bitmap_last_col.cpp
File metadata and controls
63 lines (49 loc) · 1.79 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
57
58
59
60
61
62
63
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
// Program 3
using std::cout; using std::fstream; using std::vector; using std::ios; using std::string; using std::flush;
#define ull unsigned long long
#define ll long long
string lastColFilename = "data/dataset1/chrX_last_col.txt";
string lastColBitmapFilename = "chrX_last_col_bitmap.txt";
void addCharToBitmap(vector<int>&, char);
void printVector(vector<int>&);
int main(int argc, char** argv){
fstream lastColFile(lastColFilename, ios::in|ios::app);
if(!lastColFile.is_open()){
cout<<"| Unable to open "<<lastColFilename<<".\n";
return EXIT_FAILURE;
}
vector<int> ACGTBitmap;
const int A_mask = 1000, C_mask = 0100, G_mask = 0010, T_mask = 0001;
ull A_count = 0 ,C_count = 0 ,G_count = 0 ,T_count = 0;
char bwtLastColChar;
cout<<"Parsing..."<<flush;
while (lastColFile.get(bwtLastColChar)) {
if (bwtLastColChar == '\n') continue;
addCharToBitmap(ACGTBitmap, bwtLastColChar);
}
cout<<"\rParsed.\n";
printVector(ACGTBitmap);
}
void addCharToBitmap(vector<int>& bitMap, char ch) {
switch(ch){
case 'A': bitMap.push_back(1000); break;
case 'C': bitMap.push_back(100); break;
case 'G': bitMap.push_back(10); break;
case 'T': bitMap.push_back(1); break;
case '$': bitMap.push_back(0); break;
default: throw std::invalid_argument("Wrong character "+std::to_string(ch)+" read in addCharToBitmap.\n");
}
}
void printVector(vector<int>& R){
fstream lastColBitmapFile(lastColBitmapFilename, ios::out|ios::trunc);
cout<<"Writing to file..."<<flush;
for (ll i = 0; i < R.size(); i++){
lastColBitmapFile<<R[i]<<'\n';
}
cout<<"\rWritten to file.\n";
lastColBitmapFile.close();
}