-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNA_Strand.cpp
More file actions
267 lines (215 loc) · 9.8 KB
/
DNA_Strand.cpp
File metadata and controls
267 lines (215 loc) · 9.8 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
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
// File name: DNA_Strand.cpp
#include "DNA_Strand.h"
#include <stdexcept>
// Constructor
// Create an empty DNA_Strand with an array of the default size.
DNA_Strand::DNA_Strand ()
{
// add your code here or on initialization list
}
// Constructor
// Dynamically create an empty DNA_Strand of a given array size.
DNA_Strand::DNA_Strand (size_t size)
{
std::string junk(std::to_string(size)); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
// add your code here or on initialization list
}
// Constructor
// Create an initialized DNA_Strand.
// A dynamic array the size of ipStr will be created, and then initialized
// with the characters in ipStr
DNA_Strand::DNA_Strand (const std::string & ipStr)
{
std::string junk(ipStr); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
// add your code here or on initialization list
}
// The copy constructor.
DNA_Strand::DNA_Strand (const DNA_Strand & s)
{
std::string junk(std::to_string(s.maxSize())); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
// add your code here or on initialization list
}
// Destructor
// Clean up the DNA_Strand (e.g., delete dynamically allocated memory).
DNA_Strand::~DNA_Strand ()
{
// add your code here
}
// Assignment operator performs an assignment by making a copy of
// the contents of parameter <rhs>
const DNA_Strand& DNA_Strand::operator= (const DNA_Strand & rhs)
{
std::string junk(std::to_string(rhs.maxSize())); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
// add your code here
return *this;
}
//toString
//Returns string equivalent of the DNA
std::string DNA_Strand::toString() const
{
return "junk"; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// Set an item in the DNA_Strand at location index. Throws
// <std::out_of_range> if index is out of range, i.e., larger than or
// equal to the current size of the DNA_Strand.
// Uses zero-based indexing.
void DNA_Strand::set (char new_item, size_t index)
{
std::string junk(std::to_string(index+new_item)); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
}
// Get an item in the DNA_Strand at location index. Throws
// <std::out_of_range> if index is out of range, i.e., larger than or
// equal to the current size of the DNA_Strand.
// Uses zero-based indexing.
char DNA_Strand::get (size_t index) const
{
std::string junk(std::to_string(index)); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return '!'; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// Returns the current size of the DNA.
size_t DNA_Strand::size () const
{
return 999999; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// Returns the size of the array, which is also the max size of a strand we
// can represent
size_t DNA_Strand::maxSize () const
{
return 999999; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// isEqual
// Compare this DNA_Strand with s for equality. Returns true if the
// size()'s of the two DNA_Strands are equal and all the elements from 0
// .. size()-1 are equal, else false.
bool DNA_Strand::isEqual (const DNA_Strand &s) const
{
std::string junk(std::to_string(s.maxSize())); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return false; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// search
// Look for target in current DNA strand and return index.
// Return -1 if not found.
int DNA_Strand::search(const std::string & target)const
{
std::string junk(target); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return -1; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// search
// search with start position specified
// Look for target in current DNA strand and return index.
// Return -1 if not found.
int DNA_Strand::search(size_t pos, const std::string & target)const
{
std::string junk(target+std::to_string(pos)); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return -1; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// cleave
// Removes from current DNA strand the sequence between the end of the
// first occurrence of passed target sequence (e.g. "TTG"), through the end
// of the second occurence of the target sequence.
// pre: Array e.g. ACTTGACCTTGA and target e.g. "TTG"
// post: ACTTGA (ACCTTG removed)
void DNA_Strand::cleave(const std::string & target)
{
std::string junk(target); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
}
// cleave with start position specified
// cleave starting from an index, returns the index after the cleaved DNA
// or -1 if no cleaving was performed
int DNA_Strand::cleave(size_t pos, const std::string & target)
{
std::string junk(target+std::to_string(pos)+std::to_string(maxDNA+mySize)+myDNA[0]); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return -1; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// cleaveAll
// Removes from current DNA strand the sequence between pairs of target
// sequence, i.e. from the end 1 through the end of 2, from the end of 3
// through the end of 4, etc, but NOT from the end of 2 through the end 3,
// or from the end of 4 through the end of 5.
// (Make sure that you understand the specification)
// pre: Array e.g. ACTTGATTGGGTTGCTTGCC and target e.g. "TTG"
// post: ACTTGGGTTGCC (ATTG and CTTG removed)
void DNA_Strand::cleaveAll(const std::string & target)
{
std::string junk(target); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
}
// countEnzyme
// Counts the number of occurences of a single character target sequence
// in the DNA strand.
size_t DNA_Strand::countEnzyme(char target) const
{
std::string junk(std::to_string(target)); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return 999999; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// countEnzyme -- overloaded
// string parameter version
// Counts non-overlapping instances of the target
// Eg, the target "AAA" appears 3 non-overlapping times in the
// DNA "AAAAAAAAAAA"
size_t DNA_Strand::countEnzyme(const std::string & target) const
{
std::string junk(target); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return 999999; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// grow
// This method will allow us to increase the size of the dynamically allocated
// array by allocating a new array of the desired size, copying the data from
// the old array to the new array, and then releasing the old array.
// If the newSize is less than or equal to the current size, then no actions
// are taken.
void DNA_Strand::grow (size_t newSize)
{
std::string junk(std::to_string(newSize)); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
}
// append (accepting a string parameter)
// Append the characters of the parameter to the end of the current DNA,
// growing the array if necessary.
// Example: if myDNA contained ACTTGA and "ACCTG" was received as a parameter,
// then afterward myDNA will contain ACTTGAACCTG
void DNA_Strand::append(const std::string & rhs)
{
std::string junk(rhs); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
}
// append (accepting a DNA_Strand parameter)
// Append the characters of the parameter to the end of the current DNA,
// growing the array if necessary.
// Example: if myDNA contained ACTTGA and ACCTG was received as a parameter,
// then afterward myDNA will contain ACTTGAACCTG
void DNA_Strand::append(const DNA_Strand & rhs)
{
std::string junk(std::to_string(rhs.maxSize())); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
}
// splice (accepts 2 Strings representing sequences)
// finds first pair of targets in current DNA strand and replaces
// the sequence between the end of the first target through the end of the
// second with the insertSequence, growing the array if necessary.
// If two instances of the target are not found, then no changes are made.
// Example: if myDNA contained AGTTGA, then splice("G","CCCCC") would change
// the strand to be AGCCCCCA.
// See project spec for note on efficiency.
void DNA_Strand::splice(const std::string & target, const std::string & insertSequence)
{
std::string junk(target+insertSequence); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
}
// splice
// instead of starting from the beginning of the strand, this version
// starts from a given index, and returns the position *after* the splice,
// returns -1 if no changes are made.
// Example: if myDNA contained AGTTGA, then splice(1,"G","CCCCC") would change
// the strand to be AGCCCCCA and return index 7.
int DNA_Strand::splice(size_t pos, const std::string & target, const std::string & insertSequence)
{
std::string junk(target+insertSequence); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return pos; // DELETE THIS AND REPLACE WITH YOUR CODE.
}
// inRange : helper function
// Returns true if index is within range, i.e., 0 <= index < mySize
// else returns false.
bool DNA_Strand::inRange (size_t index) const
{
std::string junk(std::to_string(index)); // DELETE THIS AND REPLACE WITH YOUR CODE. THIS IS ONLY HERE TEMPORARILY TO MAKE THE COMPILER HAPPY
return false; // DELETE THIS AND REPLACE WITH YOUR CODE.
}