-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequence.cpp
More file actions
146 lines (129 loc) · 3 KB
/
Copy pathSequence.cpp
File metadata and controls
146 lines (129 loc) · 3 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
#include "Sequence.h"
#include <string.h>
using namespace std;
//constructor that points to a new char array of size 100
template <class T>
Sequence<T>::Sequence()
{
seq = new T [100];
}
//constructor that points to a new char array of size length
//that will be entered by the user
template <class T>
Sequence<T>::Sequence(int length)
{
seq = new T [length];
}
//constructor that creates a new Sequence to copy the sequence
template <class T>
Sequence<T>::Sequence(Sequence& rhs)
{
seq = new T [strlen(rhs.seq)];
strcpy(seq , rhs.seq) ;
}
// destructor to delete the data entered
template <class T>
Sequence<T>::~Sequence()
{
delete [] seq;
}
template <class T>
bool Sequence<T>::operator==(const Sequence<T>& S)
{
bool x = false; // bool variable
int length1 = strlen(S.seq); // the length of seq1
int length2 = strlen(seq); // the length of seq
if (length1 == length2)
{
for(int i = 0; i < length1; i++)
{
if(S.seq[i] == seq[i])
x = true; // x become true.
else
x = false;
}
if (x) // if x true
return true;
else
return false;
}
else
return false;
}
template <class T>
bool Sequence<T>::operator!=(const Sequence<T>& S)
{
bool x = false; // bool variable
int length1 = strlen(S.seq);// the length of seq1
int length2 = strlen(seq); // the length of seq
if (length1 == length2)
{
for(int i = 0; i < length1; i++)
{
if(S.seq[i] == seq[i])
x = true; // x become true.
else
x = false;
}
if (x) // if x true
return false;
else
return true;
}
else
return true;
}
template <class T>
Sequence<T>& Sequence<T>::operator+(const Sequence<T>& S)
{
seq=concat(seq,S.seq);
return *this;
}
template <class T>
ostream& operator<<(ostream& out,const Sequence<T>& S)
{
out << S.seq << endl;
return out ;
}
template <class T>
istream& operator>>(istream& in,Sequence<T>& S)
{
in>>S.seq ;
return in ;
}
template <class T>
Sequence<T>& Sequence<T>::operator=(const Sequence<T>& rhs)
{
delete [] seq;
seq = new T [strlen(rhs.seq)];
strcpy (seq,rhs.seq);
return *this ;
}
template <class T>
void Sequence <T> :: LCSAlignment ()
///AATGCT
///TAATGT
{
cout << "Enter the other sequance please: \n";
string seq2;
string lcs="";
cin >> seq2;
int counter=strlen(seq);
for (int i=seq2.size();i>=0;i--)
{
for (int j=counter;j>=0;j--)
{
if (seq[j]==seq2[i])
{
lcs+=seq2[i];
counter=j--;
break;
}
}
}
cout << "The LCS Alignment is: " ;
for (int i = lcs.size() ; i>=0; i--) {
cout << lcs[i] ;
}
cout << endl ;
}