-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComputingGCContent.java
More file actions
61 lines (52 loc) · 1.21 KB
/
Copy pathComputingGCContent.java
File metadata and controls
61 lines (52 loc) · 1.21 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
//http://rosalind.info/problems/gc/
import java.io.*;
public class ComputingGCContent {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String currentID = "";
String currentDNA = "";
double currentGC = 0;
String topID = "";
double topGC = 0;
boolean firstTime = true;
//input is up to 10 strings in FASTA format, i.e. 2-20 lines
while ( true ) {
String s = br.readLine();
if(s.length() == 0) {
if(currentGC > topGC) {
topGC = currentGC;
topID = currentID;
}
System.out.println(topID);
System.out.println(topGC);
return;
}
if(s.charAt(0) == '>') {
currentDNA = "";
if(firstTime) {
firstTime = false;
currentID = s.substring(1);
}
else {
if(currentGC > topGC) {
topGC = currentGC;
topID = currentID;
}
currentID = s.substring(1);
}
}
else {
currentDNA += s;
currentGC = gc(currentDNA);
}
}
}
public static double gc(String s) {
int gc = 0;
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'G' || s.charAt(i) == 'C')
gc++;
}
return ( gc/(double)s.length() )*100;
}
}