-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNA.cpp
249 lines (241 loc) · 7.68 KB
/
DNA.cpp
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
#include "DNA.h"
using namespace std;
//name: DNA (default constructor)
//pre: None
//post: A linked list (DNA) where m_head and m_tail points to NULL
DNA::DNA()
{
m_head = NULL;
m_tail = NULL;
m_size = 0;
}
//name: ~DNA (destructor)
//pre: There is an existing linked list
//post: A linked list (DNA) is deallocated (including all dynamically
// allocated nucleotides)
DNA::~DNA()
{
Clear();
}
//name: InsertEnd
//pre: Takes in a char. Creates new node (nucleotide).
// Requires a linked list (strand of DNA)
//post: Adds a new node (nucleotide) to the end of the linked list (strand of DNA).
void DNA::InsertEnd(char payload)
{
Nucleotide *myNode = new Nucleotide();
myNode->m_payload = payload;
myNode->m_next = NULL;
//applies for the first Node
if (m_tail == NULL)
{
m_head = myNode;
}
//applies for rest
else
{
m_tail->m_next=myNode;
}
m_tail = myNode;
}
//name: Display
//pre: Outputs the dna strand(s); Pass it 1 for just the nucleotides;
// 2 for the nucleotides and it's complement (base pair)
//post: None
void DNA::Display(int numStrand)
{
cout << "Base Pairs:" << endl;
Nucleotide *myNode = new Nucleotide();
myNode = m_head;
//For just single nucleotides
if (numStrand == 1)
{
for (int i = 0; i < m_size; i++)
{
cout << myNode->m_payload << endl;
myNode = myNode->m_next;
}
cout << "END" << endl;
cout << m_size << " nucleotides listed" << endl;
cout << m_size/TRINUCLEOTIDE_SIZE << " trinucleotides listed" << endl;
}
//For base pairs
else if (numStrand == 2)
{
for (int i = 0; i < m_size; i++)
{
cout << myNode->m_payload << "-";
char basePair = myNode->m_payload;
switch (basePair)
{
case ('A'):
basePair = 'T';
break;
case ('T'):
basePair = 'A';
break;
case ('G'):
basePair = 'C';
break;
case ('C'):
basePair = 'G';
break;
default:
break;
}
cout << basePair << endl;
myNode = myNode->m_next;
}
cout << "END" << endl;
cout << m_size << " base pairs listed" << endl;
cout << m_size/TRINUCLEOTIDE_SIZE << " trinucleotides listed" << endl;
}
}
//name: NumAmino
//pre: Takes in an amino acid name and its trinucleotide codon
// Trinucleotides are just three nucleotides in a row.
//post: Searches the linked list for specific sequence; outputs results
void DNA::NumAmino(string name, string trinucleotide)
{
int totalAmino = 0;
Nucleotide *myNode = new Nucleotide();
myNode = m_head;
for (int i = 0; i < (m_size/TRINUCLEOTIDE_SIZE); i++)
{
string triNucleotide;
triNucleotide.push_back(myNode->m_payload);
triNucleotide.push_back(myNode->m_next->m_payload);
triNucleotide.push_back(myNode->m_next->m_next->m_payload);
if (Translate(triNucleotide) == name)
{
totalAmino++;
}
myNode = myNode->m_next->m_next->m_next;
}
cout << name << ": " << totalAmino << " identified" << endl;
}
//name: Sequence
//pre: Takes in full genetic code of one polynucleotide and looks at
// one trinucleotide at a time.
// Known amino acids are displayed, others are unknown. Stored in dynamic array.
//post: Displays either name of amino acid or unknown for each trinucleotide
void DNA::Sequence()
{
cout <<"Amino Acid List:" << endl;
Nucleotide *myNode = new Nucleotide();
myNode = m_head;
for (int i = 0; i < (m_size/TRINUCLEOTIDE_SIZE); i++)
{
string triNucleotide;
triNucleotide.push_back(myNode->m_payload);
triNucleotide.push_back(myNode->m_next->m_payload);
triNucleotide.push_back(myNode->m_next->m_next->m_payload);
cout << Translate(triNucleotide) << endl;
myNode = myNode->m_next->m_next->m_next;
}
}
//name: Translate (Provided)
//pre: Takes in three nucleotides (must be G,C,T, or A)
//post: Translates a trinucleotide to its amino acid
string DNA::Translate(const string trinucleotide){
if((trinucleotide=="ATT")||(trinucleotide=="ATC")||(trinucleotide=="ATA"))
return ("Isoleucine");
else if((trinucleotide=="CTT")||(trinucleotide=="CTC")||(trinucleotide=="CTA")||
(trinucleotide=="CTG")|| (trinucleotide=="TTA")||(trinucleotide=="TTG"))
return ("Leucine");
else if((trinucleotide=="GTT")||(trinucleotide=="GTC")||
(trinucleotide=="GTA")||(trinucleotide=="GTG"))
return ("Valine");
else if((trinucleotide=="TTT")||(trinucleotide=="TTC"))
return ("Phenylalanine");
else if((trinucleotide=="ATG"))
return ("Methionine");
else if((trinucleotide=="TGT")||(trinucleotide=="TGC"))
return ("Cysteine");
else if((trinucleotide=="GCT")||(trinucleotide=="GCC")||
(trinucleotide=="GCA")||(trinucleotide=="GCG"))
return ("Alanine");
else if((trinucleotide=="GGT")||(trinucleotide=="GGC")||
(trinucleotide=="GGA")||(trinucleotide=="GGG"))
return ("Glycine");
else if((trinucleotide=="CCT")||(trinucleotide=="CCC")||
(trinucleotide=="CCA")||(trinucleotide=="CCG"))
return ("Proline");
else if((trinucleotide=="ACT")||(trinucleotide=="ACC")||
(trinucleotide=="ACA")||(trinucleotide=="ACG"))
return ("Threonine");
else if((trinucleotide=="TCT")||(trinucleotide=="TCC")||
(trinucleotide=="TCA")||(trinucleotide=="TCG")||
(trinucleotide=="AGT")||(trinucleotide=="AGC"))
return ("Serine");
else if((trinucleotide=="TAT")||(trinucleotide=="TAC"))
return ("Tyrosine");
else if((trinucleotide=="TGG"))
return ("Tryptophan");
else if((trinucleotide=="CAA")||(trinucleotide=="CAG"))
return ("Glutamine");
else if((trinucleotide=="AAT")||(trinucleotide=="AAC"))
return ("Asparagine");
else if((trinucleotide=="CAT")||(trinucleotide=="CAC"))
return ("Histidine");
else if((trinucleotide=="GAA")||(trinucleotide=="GAG"))
return ("Glutamic acid");
else if((trinucleotide=="GAT")||(trinucleotide=="GAC"))
return ("Aspartic acid");
else if((trinucleotide=="AAA")||(trinucleotide=="AAG"))
return ("Lysine");
else if((trinucleotide=="CGT")||(trinucleotide=="CGC")||(trinucleotide=="CGA")||
(trinucleotide=="CGG")||(trinucleotide=="AGA")||(trinucleotide=="AGG"))
return ("Arginine");
else if((trinucleotide=="TAA")||(trinucleotide=="TAG")||(trinucleotide=="TGA"))
return ("Stop");
else
cout << "returning unknown" << endl;
return ("Unknown");
}
//name: IsEmpty
//pre: Takes in a linked list (DNA)
//post: Checks to see if the linked list (strand of DNA) is empty or not
bool DNA::IsEmpty()
{
//When size of List is 0
if (m_size == 0)
{
return true;
}
//when List is at least 1
else
{
return false;
}
}
//name: SizeOf
//pre: Takes in a linked list (DNA)
//post: Populates m_size with the total number of nucleotides loaded
void DNA::SizeOf()
{
m_size = 0;
Nucleotide *myNode = new Nucleotide();
myNode = m_head;
while (myNode != NULL)
{
m_size++;
myNode = myNode->m_next;
}
}
//name Clear
//pre: Takes in a linked list (DNA)
//post: Clears out the linked list (all nodes too)
void DNA::Clear()
{
Nucleotide *myNode = m_head;
while (myNode != NULL)
{
Nucleotide *next = myNode->m_next;
delete myNode;
myNode = next;
}
m_head = NULL;
m_tail = NULL;
m_size = 0;
}