-
Notifications
You must be signed in to change notification settings - Fork 0
/
genome.cpp
163 lines (145 loc) · 3.58 KB
/
genome.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include "genome.h"
using namespace std;
Genome::Genome(string _DNA1,string _DNA2, string _RNA){
DNA1 = _DNA1;
DNA2 = _DNA2;
RNA = _RNA;
}
Genome::Genome(){}
//recieving RNA
void Genome::getRNA(){
cout << RNA << endl;
}
//recieving DNA in 2 lines
void Genome::getDNA(){
cout << DNA1 << endl;
cout<< DNA2 << endl;
}
void Genome::print() {
cout << "RNA: "<< endl;
getRNA();
cout<< "_____" <<endl;
cout << "DNA :" << endl;
getDNA();
cout<< "_____" <<endl;
}
//RNA or DNA supplement
string Genome::mokamel(string RNA){
string RNA__ = "";
for(int i = 0; i < RNA.size(); i++){
if(RNA[i] == 'A'){
RNA__ += 'T';
}
else if(RNA[i] == 'T'){
RNA__ += 'A';
}
else if(RNA[i] == 'C'){
RNA__ += 'G';
}
else if(RNA[i] == 'G'){
RNA__ += 'C';
}
}
return RNA__;
}
//used to correct DNA after replacements
void Genome::correctDNA(){\
for(int i=0; i<DNA1.size(); i++){
if(DNA1[i] == 'A'){
DNA2[i] = 'T';
}
else if(DNA1[i] == 'T'){
DNA2[i] = 'A';
}
else if(DNA1[i] == 'C'){
DNA2[i] = 'G';
}
else if(DNA1[i] == 'G'){
DNA2[i] = 'C';
}
}
for(int i=0; i<DNA2.size(); i++){
if(DNA2[i] == 'A'){
DNA1[i] = 'T';
}
else if(DNA2[i] == 'T'){
DNA1[i] = 'A';
}
else if(DNA2[i] == 'C'){
DNA1[i] = 'G';
}
else if(DNA2[i] == 'G'){
DNA1[i] = 'C';
}
}
}
//making DNA from RNA
string Genome::makeDNA(string _RNA){
string DNA__ = "";
for(int i = 0; i < _RNA.size(); i++){
if(_RNA[i] == 'A'){
DNA__ += 'T';
}
else if(_RNA[i] == 'T'){
DNA__ += 'A';
}
else if(_RNA[i] == 'C'){
DNA__ += 'G';
}
else if(_RNA[i] == 'G'){
DNA__ += 'C';
}
}
return DNA__ + "\n" + mokamel(DNA__);
}
//making a change by replacing n characters with another one
void Genome::replaceChar(char charToReplace, char charReplacement, int n){
int counter=0;
for(int i = 0; i < DNA1.size(); i++){
if(DNA1[i] == charToReplace){
DNA1[i] = charReplacement;
counter++;
}
if(counter == n){
break;
}
}
correctDNA();
counter=0;
for(int i = 0; i < RNA.size(); i++){
if(RNA[i] == charToReplace){
RNA[i] = charReplacement;
counter++;
if(counter == n){
break;
}
}
}
}
void Genome::hugejump(string stringtofind, string stringtoreplace){
if(RNA.find(stringtofind)!= string::npos){
RNA.replace(RNA.find(stringtofind), stringtofind.length(), stringtoreplace);
}
if(DNA1.find(stringtofind) != string::npos) {
DNA1.replace(DNA1.find(stringtofind), stringtofind.length(), stringtoreplace);
}
if(DNA2.find(stringtofind) != string::npos) {
DNA2.replace(DNA2.find(stringtofind), stringtofind.length(), stringtoreplace);
}
correctDNA();
}
void Genome::diverse_jump(string s1){
size_t in_rna = RNA.find(s1);
if(in_rna != string::npos){
RNA.replace(in_rna,s1.length(), mokamel(s1));
}
size_t in_dna = DNA1.find(s1);
if(in_dna != string::npos){
DNA1.replace(in_dna,s1.length(), mokamel(s1));
}
correctDNA();
}