-
Notifications
You must be signed in to change notification settings - Fork 0
/
RanGen.java
88 lines (60 loc) · 2.28 KB
/
RanGen.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
// this code does 3 things
// 1. generates 1000 random DNA 3 mers with bases of uniform frequency
// 2. tracks how often the 3 mer AAA is printed
// 3. modifies the frequency of bases to a specified value and then tracks how often the 3 mer AAA is printed
package jCode;
import java.util.Random;
public class RanGen {
public static void main(String[] args) {
// sets up variable for counting
int count = 0;
//for loop to give 1000 3 mers
for (int s =0; s <= 1000; s++) {
Random random = new Random();
//sets up string of bases to loop through
String bases = "ATCG";
for (int i=0; i < 1; i++) {
//establishes each character of the 3 mer
char x = (bases.charAt(random.nextInt(bases.length())));
char y = (bases.charAt(random.nextInt(bases.length())));
char z = (bases.charAt(random.nextInt(bases.length())));
//puts each character into one string
String ss = String.valueOf(x) + String.valueOf(y) + String.valueOf(z);
//this print statement will print out the 1000 randomly generated DNA 3 mers when not commented out
//System.out.println((ss));
//if the 3 mer is equal to "AAA", the count increases by one
if (ss.equals("AAA"))
count = count + 1;
}
}
System.out.println(("Uniform base frequency: The 3 mer AAA was printed " + count + " times."));
int count2 = 0;
for (int s =0; s <= 1000; s++) {
//sets up empty string for the bases to be added to
String base = "";
//loop to make 3 mer
while (base.length() < 3 ) {
Random ran = new Random();
//gives random number between 0 and 1
float f = ran.nextFloat();
String a = "";
//if statements to establish frequency
if (f < .13)
a = a + "A";
else if (f < .51 && f > .12 )
a = a + "C";
else if(f < .90 && f > .50 )
a = a + "G";
else if (f >= .90 )
a = a + "T";
base = base + a;
}
//this will print out 1000 DNA 3 mers of the modified frequency
//System.out.println((base));
if (base.equals("AAA"))
count2 = count2 + 1;
}
//we would expect AAA to appear around 1.7 times... Java produces AAA at a similar frequency
System.out.println(("Modified base frequency: The 3 mer AAA was printed " + count2 + " times."));
}
}