-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNA.java
More file actions
204 lines (184 loc) · 4.91 KB
/
Copy pathDNA.java
File metadata and controls
204 lines (184 loc) · 4.91 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
package asg_1;
import BasicIO.ASCIIDataFile;
/*
* Class: DNA.Java
* Project: Assignment_1
* Author: Trevor Vanderee
* Student ID: 5877022
*/
public class DNA {
private Node crt;
/**
* This program reads in data from a text file and
* finds the gcContent and Reverse Complement of each
* given strand. It then generates all possible strands
* based on given criteria.
*/
public DNA( ){
ASCIIDataFile in = new ASCIIDataFile();
Node p;
int numStrands = in.readInt();
for(int i =0; i<(numStrands); i++){
int numBases = in.readInt();
Node strand = new Node(in.readString(),null);
p= strand;
for(int j =0; j<=numBases-2; j++){
p.next = new Node(in.readString(),null);
p=p.next;
}
System.out.println(printStrand(strand)+ "\t GC content: "+ gcContent(strand)+
"\t Reverse Complement: "+ printStrand(reverseCompliment(strand)));
reverseCompliment(strand);
crt = new Node ("a",null);
}
int length = in.readInt();
int gcc= in.readInt();
generateStrands(length,0,gcc,crt);
}//DNA
/**
* This method takes a variety of parameters and creates
* a mock DNA strand in lexicographic order.
* @param int n: The Length of the desired strands.
* @param int k: The current position of the recursive calls.
* @param int gcc: The desired gcContent for each strand.
* @param Node x: The Node used for creating each strand.
*/
private void generateStrands(int n,int k, int gcc,Node x){
if(!(k==n-1)){
x.next = new Node("A",null);
x.item = "A";
generateStrands(n,k+1,gcc,x.next);
x.item ="C";
generateStrands(n,k+1,gcc,x.next);
x.item="G";
generateStrands(n,k+1,gcc,x.next);
x.item="T";
generateStrands(n,k+1,gcc,x.next);
}else{
x.item = "A";
if(gcContent(crt)==gcc){
if(!(compareStrands(crt,reverseCompliment(crt)))){
}
}
x.item = "C";
if(gcContent(crt)==gcc){
if(!(compareStrands(crt,reverseCompliment(crt)))){
System.out.println(printStrand(crt));
}
}
x.item = "G";
if(gcContent(crt)==gcc){
if(!(compareStrands(crt,reverseCompliment(crt)))){
System.out.println(printStrand(crt));
}
}
x.item = "T";
if(gcContent(crt)==gcc){
if(!(compareStrands(crt,reverseCompliment(crt)))){
System.out.println(printStrand(crt));
}
}
x.item="A";
}
}//generateStrands
/**
* This method takes a Strand and returns
* its reverse complement.
* @param Node n: The Node to be acted on.
* @return Node: The finished node.
*/
private Node reverseCompliment(Node n){
Node r;
Node p;
if(!(n.next==null)){
r = reverseCompliment(n.next);
p=r;
while(!(p.next==null)){
p = p.next;
}
p.next = new Node(getCompliment(n.item),null);
}else{
r = new Node(getCompliment(n.item),null);
}
return r;
}//reverseCompliment
/**
* This method takes the strand and returns the amount
* of g's and c's found in the strand.
* @param Node n: The Strand to be examined.
* @return int: The number of g's and c's in the strand.
*/
private int gcContent(Node n){
int l =0;
if(!(n==null)){
l = gcContent(n.next);
if (n.item.equals("G")||n.item.equals("C")){
return ++l;
}else {
return l;
}
}
return l;
}//gcContent
/**
* This method takes a String and finds its DNA
* complement and returns the complement.
* @param String s: the input to be complemented.
* @return String out: the complement of s.
*/
private String getCompliment(String s){
String out;
if(s.equals("A")){
out = "T";
}else if(s.equals("T")){
out = "A";
}else if(s.equals("G")){
out = "C";
}else if(s.equals("C")){
out = "G";
}else{
out =s;
}
return out;
}//getCompliment
/**
* This Method takes the data from the Nodes and adds
* it to a String to be returned to the invoker.
* @param Node in: the strand to be Converted to string
* @return String to be printed
*/
private String printStrand(Node in){
String out = "";
Node p=in;
while(!(p==null)){
out += p.item;
p=p.next;
}
return out;
}//printStrand
/**
* This method compares to strands and returns a true
* boolean if the strands are equivalent.
* @param Node a: A strand to be compared to strand b.
* @param Node b: A strand to be compared to strand a.
* @return boolean: returns true if strands are equivalent.
*/
private boolean compareStrands(Node a, Node b){
boolean ret;
if(a.next==null^b.next==null){
return false;
}
if(a.next==null){
if(a.item.equals(b.item)){
return true;
}else{
return false;
}
}else{
ret = compareStrands(a.next,b.next);
}
return ret;
}//compareStrands
public static void main(String[] args){@SuppressWarnings("unused")
DNA d = new DNA( );}
}