-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodonStateSpace.h
More file actions
115 lines (86 loc) · 2.96 KB
/
CodonStateSpace.h
File metadata and controls
115 lines (86 loc) · 2.96 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
#ifndef CODONSTATESPACE_H
#define CODONSTATESPACE_H
#include "StateSpace.h"
class CodonStateSpace : public StateSpace {
public:
static const int Npos = 3;
// by default, codons always exclude stops
// if a method takes or returns a codon stops INCLUDED, then this is made explicit in the method's name
CodonStateSpace(GeneticCodeType incode);
~CodonStateSpace();
// -----
// generic methods
// exist for any state space, and should have a consistent meaning throughout
int GetNstate() {return Nstate;}
// give a three letter code, returns codon (if stop exits with error message)
int GetState(string state);
// give a codon (stops excluded), returns a three letter code
string GetState(int state);
// -----
// codon specific methods
DNAStateSpace* GetDNAStateSpace() {return nucstatespace;}
ProteinStateSpace* GetProteinStateSpace() {return protstatespace;}
// returns a codon based on three letters
// returns -1 (== unknown) if at least one of the positions is unknown
// if stop exits with error message...
int GetCodonFromDNA(int pos1, int pos2, int pos3);
/*
string TranslateDNASequenceWithStops(string s);
string GetStateWithStops(int state);
int isCodingSequence(string s);
*/
// 2 codons excluding stops are compared
// method returns -1 if identical
// returns 3 is codons differ at more than one position
// otherwise, returns the position at which codons differ (i.e. returns 0,1 or 2 if the codons differ at position 1,2 or 3)
int GetDifferingPosition(int codon1, int codon2);
// return the integer encoding for the base at requested position
// stops excluded
int GetCodonPosition(int pos, int codon) {
if ((pos<0) || (pos>=Npos)) {
cerr << "GetCodonPosition: pos out of bound\n";
cerr << pos << '\n';
exit(1);
}
if ((codon<0) || (codon>=Nstate)) {
cerr << "GetCodonPosition: codon out of bound\n";
cerr << codon << '\n';
exit(1);
}
return CodonPos[pos][codon];
}
int GetNbDiff(int codon1, int codon2) {
int res =0;
if(CodonPos[0][codon1] != CodonPos[0][codon2]){res++;}
if(CodonPos[1][codon1] != CodonPos[1][codon2]){res++;}
if(CodonPos[2][codon1] != CodonPos[2][codon2]){res++;}
return res;
}
// translation stops excluded
int Translation(int codon) {
return CodonCode[codon];
}
// stops excluded
bool Synonymous(int codon1, int codon2) {
return (CodonCode[codon1] == CodonCode[codon2]);
}
// returns -1 if stop codon
// otherwise returns integer in [0,19] standing for an amino-acid (one letter code, alphabetical order)
int TranslationWithStops(int codon) {
return CodonCodeWithStops[codon];
}
private:
GeneticCodeType code;
DNAStateSpace* nucstatespace;
ProteinStateSpace* protstatespace;
// number of codons, not including stops (61 in general)
int Nstate;
// and array of size Ncodon = 64
// whose entries are between -1 and 19
// -1 : stop codon
// 0..19 : amino acid encoded (1 letter code, alphabetical order)
int* CodonCodeWithStops;
int* CodonCode;
int** CodonPos;
};
#endif