-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRNA.cpp
More file actions
86 lines (78 loc) · 1.86 KB
/
Copy pathRNA.cpp
File metadata and controls
86 lines (78 loc) · 1.86 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
#include "RNA.h"
#include <string.h>
using namespace std;
// constructor that sets the RNA type to a default: mRNA
RNA::RNA()
{
type = mRNA;
}
// constructor that takes sequence and RNA type from the user
RNA::RNA(char * seq, RNA_Type atype)
{
if(strlen(seq)%3!=0)
{
throw RNA_error();
}
for (int i=0 ; i<strlen(seq) ; i++)
{
if(seq[i]!='A' && seq[i]!='C' && seq[i]!='G' && seq[i]!='U' )
throw RNA_error2();
}
strcpy (this->seq, seq);
type = atype;
}
RNA::RNA(RNA& rhs)
{
strcpy (seq, rhs.seq);
type = mRNA;
}
// destructor
RNA::~RNA()
{
//
}
// function print to print the RNA sequence
void RNA::Print()
{
cout << seq ;
}
protein RNA::ConvertToProtein( CodonsTable & table)
{ Codon a ; // object from struct codon
protein obj; //object from protein
int length = strlen(seq); // length of seq.
obj.seq = new char [length/3]; // divide sequence to codon
char* value= new char[3]; // value = 3 chat like AAA
int k=0;
for (int i=0; i<length/3; i++)
{
// first codon.
value[0]=seq[k];
value[1]=seq[k+1];
value[2]=seq[k+2];
// second codon
k+=3;
a = table.getAminoAcid(value); // Get amino acid according the value
obj.seq[i] = a.AminoAcid; // set every seq to amino acid
}
return obj;
}
// converting a RNA sequence to a DNA sequence
DNA RNA::ConvertToDNA()
{
DNA obj; // object from DNA,
obj.seq = seq; // and initialize it with the same sequence.
// loop on the length of seq.
for (int i=0; i<strlen(seq); i++)
{
// Replace every U with T.
if (seq[i]=='U')
{
obj.seq[i]='T';
}
else
{
obj.seq[i]=seq[i];
}
}
return obj; //return obj.
}