-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgc.cpp
50 lines (42 loc) · 1.25 KB
/
gc.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
#include <string>
#include <fstream>
#include <iostream>
int main() {
std::fstream fs("chry_multiplied.fa", std::ios::in);
int a = 0;
int t = 0;
int g = 0;
int c = 0;
if ( fs.is_open() ) {
std::string line;
while (std::getline(fs, line)) {
if(*(line.begin()) != '>') {
for(std::string::const_iterator pos = line.begin(); pos!=line.end() ; ++pos){
switch (*pos){
case 'A' :
a++;
break;
case 'C' :
c++;
break;
case 'G' :
g++;
break;
case 'T' :
t++;
break;
default:
break;
}
}
}
}
//std::cout << "gcCount: " << gcCount << " / totalBaseCount: "<< totalBaseCount << " = " ;
int totalBaseCount = a + t + g + c;
int gcCount = g + c;
std::cout << ( (float)gcCount / (float)totalBaseCount ) * 100 << std::endl ;
} else {
std::cout << "can't open file" ;
}
return 0 ;
}