-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequenceGUI.java
More file actions
424 lines (367 loc) · 17.1 KB
/
Copy pathsequenceGUI.java
File metadata and controls
424 lines (367 loc) · 17.1 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
package gui7;
import javax.swing.JOptionPane;
/**
*
* @author manu
*/
public class assignment2 extends javax.swing.JFrame {
public boolean spacing10 = false;
public boolean capitalization = false;
public int lineLength;
public String s;
public assignment2() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void initComponents() {
jCheckBox1 = new javax.swing.JCheckBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane3 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox<>();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea3 = new javax.swing.JTextArea();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Number Addition");
jCheckBox1.setText("Groups of 10?");
jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBox1ActionPerformed(evt);
}
});
jButton1.setText("Reset");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Process");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane3.setViewportView(jTextArea2);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jLabel1.setText("Enter Sequence:");
jLabel2.setText("Processed Sequence:");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "40", "50", "60", "70" }));
jComboBox1.setSelectedIndex(2); ////Indices start at 0, so 2 is 60
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
final String s = (String) jComboBox1.getSelectedItem();//get the selected item
switch (s) {//check for a match
case "60":
lineLength = 1;
break;
case "40":
lineLength = 2;
break;
case "50":
lineLength = 3;
break;
case "70":
lineLength = 4;
break;
}
}
});
jRadioButton1.setText("Uppercase");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
jRadioButton2.setText("Lowercase");
jRadioButton2.setSelected(true);
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jTextArea3.setColumns(20);
jTextArea3.setRows(5);
jScrollPane2.setViewportView(jTextArea3);
jLabel3.setText("Statistics:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(59, 59, 59)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jCheckBox1)
.addComponent(jRadioButton1)
.addComponent(jRadioButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1)
.addComponent(jButton2))))
.addGap(129, 129, 129))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(125, 125, 125)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 699, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(127, 127, 127)
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup()
.addGap(126, 126, 126)
.addComponent(jLabel3)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(20, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 730, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 730, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jCheckBox1)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jRadioButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jRadioButton2))
.addGap(18, 18, 18)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jCheckBox1.isSelected() == true)
spacing10 = true;
else
spacing10 = false;
}
//For displaying error messages
private void displayErrMsg(String msg) {
JOptionPane.showMessageDialog(null,
msg,
"Error message",
JOptionPane.ERROR_MESSAGE);
}
//For displaying confirmation message to reset
private boolean displayCfmMsg() {
int n = JOptionPane.showConfirmDialog(
null,
"Would you like to reset everything?",
"Reset",
JOptionPane.YES_NO_CANCEL_OPTION);
//a YES_NO_OPTION dialog always returns one of the following values: YES_OPTION, NO_OPTION, or CLOSED_OPTION.
if (n == JOptionPane.YES_OPTION) {
return true;
} else {
return false;
}
}
private boolean isValidSeq(String inSequence) {
/*any characters other than a,c,g,t, in either upper or lower case plus new lines)
* display an appropriate error message in a message dialog */
if (inSequence.matches("[acgtACGT\\n\\r]+")) {
return true;
} else {
displayErrMsg("Sequence should contain only a,c,g,t and new line characters, not even spaces");
return false;
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
boolean resetyes = displayCfmMsg();
if (resetyes) {
jTextArea1.setText("");
jTextArea2.setText("");
jTextArea3.setText("");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String inputSequence = null;
String outputSequence = null;
String statistics1 = null;
String countSequence = null;
int noA = 0;
int noC = 0;
int noG = 0;
int noT = 0;
inputSequence = jTextArea1.getText();
countSequence = inputSequence.toUpperCase();
int seqLength = countSequence.length();
for( int i=0; i<seqLength; i++ ) {
if( countSequence.charAt(i) == 'A' ) {
noA++;
}
}
for( int i=0; i<seqLength; i++ ) {
if( countSequence.charAt(i) == 'C' ) {
noC++;
}
}
for( int i=0; i<seqLength; i++ ) {
if( countSequence.charAt(i) == 'G' ) {
noG++;
}
}
for( int i=0; i<seqLength; i++ ) {
if( countSequence.charAt(i) == 'T' ) {
noT++;
}
}
// check if input sequence is valid
boolean isvalid = isValidSeq(inputSequence);
if (isvalid)
{
if(capitalization == true)
{
outputSequence = inputSequence.toUpperCase();
} else {
outputSequence = inputSequence.toLowerCase();
}
//remove all existing new lines from sequence
outputSequence = outputSequence.replace("\n", "");
System.out.println("Sequence = "+outputSequence);
jLabel3.setText("Total sequence length="+outputSequence.length());
int charsperline = 0;
int idx = jComboBox1.getSelectedIndex();
switch(idx) {
case 0: // 40
charsperline=40;
break;
case 1: // 50
charsperline=50;
break;
case 2: // 60
charsperline=60;
break;
case 3: // 70
charsperline=70;
break;
}
outputSequence = outputSequence.replaceAll(".{"+charsperline+"}", "$0\n");
if(spacing10 == true)
{
outputSequence = outputSequence.replaceAll(".{10}", "$0 ");
}
float pctA = (float)((noA*100)/seqLength);
float pctC = (float)((noC*100)/seqLength);
float pctG = (float)((noG*100)/seqLength);
float pctT = (float)((noT*100)/seqLength);
statistics1 = "Number of Adenine: "+noA
+"\nPercentage of Adenine: "+pctA+"%"
+"\nNumber of Cytosine: "+noC
+"\nPercentage of Cytosine: "+pctC+"%"
+"\nNumber of Guanine: "+noG
+"\nPercentage of Guanine: "+pctG+"%"
+"\nNumber of Thymine: "+noT
+"\nPercentage of Thymine: "+pctT+"%"
+"\nLength of Sequence: "+outputSequence.length()
+"\n";
jTextArea2.setText(outputSequence);
jTextArea3.setText(statistics1);
System.out.println("Sequence length= "+outputSequence.length());
}// sequence is valid
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(jRadioButton1.isSelected() == true)
{
capitalization = true;
jRadioButton2.setSelected(false);
}
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
if(jRadioButton2.isSelected() == true)
{
capitalization = false;
jRadioButton1.setSelected(false);
}
}
private void elseif(boolean b) {
// TODO Auto-generated method stub
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(assignment2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(assignment2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(assignment2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(assignment2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new assignment2().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextArea jTextArea3;
}