forked from samuell/gccontent-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc.java
40 lines (31 loc) · 940 Bytes
/
gc.java
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class gc {
/*
* https://github.com/pditommaso/gccontent-benchmark
*/
public static void main(String... args) throws IOException {
BufferedReader stream = new BufferedReader(new FileReader("chry_multiplied.fa"));
int a = 0;
int t = 0;
int g = 0;
int c = 0;
String line;
while( (line=stream.readLine())!= null ) {
if( line.charAt(0)=='>' )
continue;
for( int i=0; i<line.length(); i++ ) {
switch (line.charAt(i)) {
case 'A': a++; break;
case 'C': c++; break;
case 'G': g++; break;
case 'T': t++; break;
}
}
}
int totalBaseCount = a + t + g + c;
int gcCount = g + c;
System.out.println((float)gcCount / (float)totalBaseCount * 100);
}
}