-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.java
127 lines (111 loc) · 4.67 KB
/
part2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
public class part2{
public static void main(String args[]){
oriC("aagcc"); // TEST CASE 1: basic functionality
oriC("GGCCATGGTCC"); // TEST CASE 2: non-case sensitive, handles ties
oriC("ccataca"); // TEST CASE 3: handles oriC at sequence start
oriC("ataaata"); // TEST CASE 4: handles lack of g/c bases
oriC("ccaggccgga"); // TEST CASE 5: handles 3 way ties and ties with origin
} // end main
public static void oriC(String input){
int i = 0;
int ratioMeter = 0;
int gCount = 0;
int cCount = 0;
int marker = 0;
int negativeRatio = 0;
String potentialSites = "";
for(i = 0; i < input.length(); i++){ // finds first highest "peak" in G/C ratio
if (String.valueOf(input.charAt(i)).equals("G") || String.valueOf(input.charAt(i)).equals("g")){
ratioMeter++;
gCount++;
} // end if
if (String.valueOf(input.charAt(i)).equals("C") || String.valueOf(input.charAt(i)).equals("c")){
ratioMeter--;
cCount++;
} // end if
if (ratioMeter > marker){
marker = ratioMeter;
potentialSites = Integer.toString(i + 1);
negativeRatio = 1; // prevents trigger of returning sequence start if peak ever exceeds 0
} // end if
} // end for
if (cCount == 0 && gCount == 0){
System.out.print("\nNo cytosine or guanine bases by which to predict oriC location.");
return;
} // end if
i = 0; // resets loop
ratioMeter = 0; // resets counter
for(i = 0; i < input.length(); i++){ // finds alternative potential sites, e.g. "ties"
if (String.valueOf(input.charAt(i)).equals("G") || String.valueOf(input.charAt(i)).equals("G")){
ratioMeter++;
} // end if
if (String.valueOf(input.charAt(i)).equals("C") || String.valueOf(input.charAt(i)).equals("c")){
ratioMeter--;
} // end if
if (ratioMeter == marker && ratioMeter > 0 && // conditional prevents A and T indexes from being appended
(String.valueOf(input.charAt(i)).equals("G") ||
String.valueOf(input.charAt(i)).equals("g"))) { // appends positive tie cases
if (i > potentialSites.length()) { // prevents appending with same base #
potentialSites += Integer.toString(i + 1);
} // end if
} // end if
} // end for
i = 0; // resets loop
ratioMeter = 0; // resets counter
if (negativeRatio == 0){
for(i = 0; i < input.length(); i++){ // finds alternative potential sites @ zero, e.g. "ties"
if (String.valueOf(input.charAt(i)).equals("G") || String.valueOf(input.charAt(i)).equals("g")){
ratioMeter++;
} // end if
if (String.valueOf(input.charAt(i)).equals("C") || String.valueOf(input.charAt(i)).equals("c")){
ratioMeter--;
} // end if
if (ratioMeter == 0 && (String.valueOf(input.charAt(i)).equals("G") || // prevents A and T from being appended
String.valueOf(input.charAt(i)).equals("g"))) { // appends tie cases
if(i > potentialSites.length()){ // prevents appending origin again
potentialSites += Integer.toString(i + 1);
} // end if
} // end if
} // end for
if (potentialSites.length() == 0) {
System.out.print("\nThe most likely oriC site based on G/C ratio is at the sequence start.");
return;
} // end if
else {
System.out.print("\nThe most likely oriC sites based on G/C ratio are at the sequence start");
if(potentialSites.length() == 1){ // if one other incident of ratio equaling zero
System.out.print(" and base # " + potentialSites.charAt(0) + ".");
return;
} // end if
else{
int j;
System.out.print(" and base numbers ");
for (j = 0; j < potentialSites.length() - 1; j++){
System.out.print(potentialSites.charAt(j) + ", ");
} // end for
System.out.print("and " + potentialSites.charAt(potentialSites.length() - 1) + ".");
return;
} // end else
} // end else
} // end if
if(potentialSites.length() == 1){
System.out.print("\nThe most likely oriC site based on G/C ratio is after base # " + potentialSites + ".");
return;
} // end if
if(potentialSites.length() > 1){
System.out.print("\nThe most likely oriC sites based on G/C ratio are after base numbers ");
int j;
if(potentialSites.length() == 2){
System.out.print(potentialSites.charAt(0) + " and " + potentialSites.charAt(1) + ".");
return;
} // end if
else{
for (j = 0; j < potentialSites.length() - 1; j++){
System.out.print(potentialSites.charAt(j) + ", ");
} // end for
System.out.println("and " + potentialSites.charAt(potentialSites.length() - 1) + ".");
return;
} // end else
} // end if
} // end oriC
} // end part2