I have a final project in my intro C++ class that I'm having trouble with. I have made two classes (a list class and a strand class) and I have to read in user input for the strands, and then find a match within a user defined threshold and lastly merge the two strands and their labels together.
I have included the two header and implementation files as well as my main that will be running the program. makefile is included as well.
My professor has taught the basics of this stuff, but then threw me in the deep end with this project.
DNAList.cpp
#include "DNAList.h"
//Purpose: Constructor, initialize actualSize to "0"
ListType::ListType () {
actualSize=0;
}
//Purpose: Get length of list
int ListType::getLength() const{
return actualSize;
}
//Purpose: Insert a new item into the list
void ListType::insert(ListItemType item){
if (actualSize < MAX_SIZE){
array[actualSize]= item;
actualSize ++;
}
}
//Purpose: remove an item from the list
void ListType::remove(ListItemType item){
//look for item, find position
int position= (*this).search(item);
if (position !=-1){
//copy everything to the right over 1 cell to the left
for (int i= position; i < (actualSize - 1); i++){
array [i] = array [i+1];
}
actualSize --;
}
}
//Purpose: retrieve a specific element from the list
ListItemType ListType::retrieve (int index) const{
return array [index];
}
//Purpose: search list for specific item
int ListType::search (ListItemType item) const {
//sequential search
int position= -1;
int index= 0;
while ((position == -1) && (index < actualSize)){
if (item == array [index]){
position = index;
}
else {
index ++;
}
}
return position;
}
//Purpose: sort list
void ListType::sort (){
//bubble sort
for (int i= 0; i < actualSize - 1; i++){
for (int j= 0; j < actualSize - i; j++){
if (array [j] > array [j+1]){
ListItemType temp = array [j];
array [j]= array [j+1];
array [j+1] = temp;
}
}
}
}
//Print array
void ListType::print (){
for (int i = actualSize - 1; i >= 0; i--)
cout << array [i];
}
It would probably make it easier if you supplied some examples of strands and what the output would look like for different thresholds. Is the threshold a minimum/maximum value?
What the assignment seems to be requiring is an algorithm which will extract a substring of a length specified by the threshold from one string and then search for a match in another. Once a match is found, you probably have to do a comparison between the two strands to see how many bases actually match between the two strands. Then you can chop the end of one and append the end of the other strand to it (the merge). Tell me if this sounds right to you.
Take your example 1:
Strands: X= acggtcacgg, Y= gtcacatta
I guess you can start with strand Y since it is shorter. Threshold is 5 so you take a substring of Y which is the first five characters: gtcac
Now you find the substring in X, and you see that there is a match starting at index 4 of string X. Now you advance 5 indices from the match position in X and the start of Y and start comparing. Immediately you find there are no more matches. So you substring X to get acggtcac and you substring the rest of Y to get atta and then you put them together to get the output.
I don't understand case 3. It seems the first and second parts contradict themselves.