bpp-seq
2.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Friends
Pages
NucleicAlphabet.h
Go to the documentation of this file.
1
//
2
// File: NucleicAlphabet.h
3
// Authors: Guillaume Deuchst
4
// Julien Dutheil
5
// Sylvain Gaillard
6
// Created on: Tue Jul 22 2003
7
//
8
9
/*
10
Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
11
12
This software is a computer program whose purpose is to provide classes
13
for sequences analysis.
14
15
This software is governed by the CeCILL license under French law and
16
abiding by the rules of distribution of free software. You can use,
17
modify and/ or redistribute the software under the terms of the CeCILL
18
license as circulated by CEA, CNRS and INRIA at the following URL
19
"http://www.cecill.info".
20
21
As a counterpart to the access to the source code and rights to copy,
22
modify and redistribute granted by the license, users are provided only
23
with a limited warranty and the software's author, the holder of the
24
economic rights, and the successive licensors have only limited
25
liability.
26
27
In this respect, the user's attention is drawn to the risks associated
28
with loading, using, modifying and/or developing or reproducing the
29
software by the user in light of its specific status of free software,
30
that may mean that it is complicated to manipulate, and that also
31
therefore means that it is reserved for developers and experienced
32
professionals having in-depth computer knowledge. Users are therefore
33
encouraged to load and test the software's suitability as regards their
34
requirements in conditions enabling the security of their systems and/or
35
data to be ensured and, more generally, to use and operate it in the
36
same conditions as regards security.
37
38
The fact that you are presently reading this means that you have had
39
knowledge of the CeCILL license and that you accept its terms.
40
*/
41
42
#ifndef _NUCLEICALPHABET_H_
43
#define _NUCLEICALPHABET_H_
44
45
#include "
LetterAlphabet.h
"
46
#include "
NucleicAlphabetState.h
"
47
48
#include <map>
49
#include <iostream>
50
51
namespace
bpp
52
{
53
60
class
NucleicAlphabet
:
61
public
LetterAlphabet
62
{
63
private
:
64
std::map<int, unsigned int>
binCodes_
;
65
void
updateMaps_
(
int
pos,
const
NucleicAlphabetState
& st) {
66
if
(
binCodes_
.find(st.
getBinaryCode
()) ==
binCodes_
.end())
67
binCodes_
[st.
getBinaryCode
()] = pos;
68
}
69
70
public
:
71
NucleicAlphabet
():
binCodes_
() {}
72
73
virtual
~NucleicAlphabet
() {}
74
75
protected
:
80
void
registerState
(
const
NucleicAlphabetState
& st) {
81
LetterAlphabet::registerState
(st);
82
updateMaps_
(
getNumberOfChars
(), st);
83
}
84
void
setState
(
unsigned
int
pos,
const
NucleicAlphabetState
& st) {
85
LetterAlphabet::setState
(pos, st);
86
updateMaps_
(pos, st);
87
}
88
const
NucleicAlphabetState
&
getStateAt
(
unsigned
int
pos)
const
89
throw
(
IndexOutOfBoundsException
) {
90
return
dynamic_cast<
const
NucleicAlphabetState
&
>
(
91
AbstractAlphabet::getStateAt
(pos)
92
);
93
}
94
NucleicAlphabetState
&
getStateAt
(
unsigned
int
pos)
95
throw
(
IndexOutOfBoundsException
) {
96
return
dynamic_cast<
NucleicAlphabetState
&
>
(
97
AbstractAlphabet::getStateAt
(pos)
98
);
99
}
102
public
:
107
const
NucleicAlphabetState
&
getState
(
const
std::string& letter)
const
108
throw
(
BadCharException
) {
109
return
dynamic_cast<
const
NucleicAlphabetState
&
>
(
110
AbstractAlphabet::getState
(letter)
111
);
112
}
113
const
NucleicAlphabetState
&
getState
(
int
num)
const
114
throw
(
BadIntException
) {
115
return
dynamic_cast<
const
NucleicAlphabetState
&
>
(
116
AbstractAlphabet::getState
(num)
117
);
118
}
134
const
NucleicAlphabetState
&
getStateByBinCode
(
int
code)
const
135
throw
(
BadIntException
) {
136
std::map<int, unsigned int>::const_iterator it =
binCodes_
.find(code);
137
if
(it ==
binCodes_
.end())
138
throw
BadIntException
(code,
"NucleicAlphabet::getState(unsigned char): Binary code not in alphabet"
,
this
);
139
return
getStateAt
(it->second);
140
}
141
163
int
subtract
(
int
s1,
int
s2)
const
throw
(
BadIntException
) {
164
return
getStateByBinCode
(
getState
(s1).getBinaryCode() & ~
getState
(s2).getBinaryCode()).
getNum
();
165
}
166
187
std::string
subtract
(
const
std::string& s1,
const
std::string& s2)
const
throw
(
BadCharException
) {
188
return
intToChar
(
subtract
(
charToInt
(s1),
charToInt
(s2)));
189
}
190
212
int
getOverlap
(
int
s1,
int
s2)
const
throw
(
BadIntException
) {
213
return
getStateByBinCode
(
getState
(s1).getBinaryCode() &
getState
(s2).getBinaryCode()).
getNum
();
214
}
215
236
std::string
getOverlap
(
const
std::string& s1,
const
std::string& s2)
const
throw
(
BadCharException
) {
237
return
intToChar
(
getOverlap
(
charToInt
(s1),
charToInt
(s2)));
238
}
239
242
public
:
243
// return 4 : A, C, G, T (or U)
244
unsigned
int
getSize
()
const
{
return
4; }
245
246
// return 15 : gap isn't included, generic unresolved bases (N, X, ?, O, 0) count for one
247
unsigned
int
getNumberOfTypes
()
const
{
return
15; }
248
249
int
getUnknownCharacterCode
()
const
{
return
14; }
250
251
bool
isUnresolved
(
int
state)
const
{
return
state > 3; }
252
bool
isUnresolved
(
const
std::string& state)
const
{
return
charToInt
(state) > 3; }
253
254
};
255
256
}
//end of namespace bpp.
257
258
#endif // _NUCLEICALPHABET_H_
259
Bpp
Seq
Alphabet
NucleicAlphabet.h
Generated on Thu Mar 14 2013 16:34:50 for bpp-seq by
1.8.3.1-20130209