bpp-phyl
2.1.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Friends
Pages
NonHomogeneousSequenceSimulator.h
Go to the documentation of this file.
1
//
2
// File: NonHomogeneousSequenceSimulator.h
3
// Created by: Julien Dutheil
4
// Bastien Boussau
5
// Created on: Wed Aug 24 15:20 2005
6
//
7
8
/*
9
Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
10
11
This software is a computer program whose purpose is to provide classes
12
for phylogenetic data analysis.
13
14
This software is governed by the CeCILL license under French law and
15
abiding by the rules of distribution of free software. You can use,
16
modify and/ or redistribute the software under the terms of the CeCILL
17
license as circulated by CEA, CNRS and INRIA at the following URL
18
"http://www.cecill.info".
19
20
As a counterpart to the access to the source code and rights to copy,
21
modify and redistribute granted by the license, users are provided only
22
with a limited warranty and the software's author, the holder of the
23
economic rights, and the successive licensors have only limited
24
liability.
25
26
In this respect, the user's attention is drawn to the risks associated
27
with loading, using, modifying and/or developing or reproducing the
28
software by the user in light of its specific status of free software,
29
that may mean that it is complicated to manipulate, and that also
30
therefore means that it is reserved for developers and experienced
31
professionals having in-depth computer knowledge. Users are therefore
32
encouraged to load and test the software's suitability as regards their
33
requirements in conditions enabling the security of their systems and/or
34
data to be ensured and, more generally, to use and operate it in the
35
same conditions as regards security.
36
37
The fact that you are presently reading this means that you have had
38
knowledge of the CeCILL license and that you accept its terms.
39
*/
40
41
#ifndef _NONHOMOGENEOUSSEQUENCESIMULATOR_H_
42
#define _NONHOMOGENEOUSSEQUENCESIMULATOR_H_
43
44
#include "
DetailedSiteSimulator.h
"
45
#include "
SequenceSimulator.h
"
46
#include "../TreeTemplate.h"
47
#include "../NodeTemplate.h"
48
#include "../Model/SubstitutionModel.h"
49
50
#include <
Bpp/Numeric/Random/RandomTools.h
>
51
#include <
Bpp/Numeric/Prob/DiscreteDistribution.h
>
52
53
// From SeqLib:
54
#include <
Bpp/Seq/Alphabet/Alphabet.h
>
55
#include <
Bpp/Seq/Site.h
>
56
#include <
Bpp/Seq/Container/SiteContainer.h
>
57
58
// From the STL:
59
#include <map>
60
#include <vector>
61
62
#include "../Model/SubstitutionModelSet.h"
63
64
namespace
bpp
65
{
66
67
class
SimData
68
{
69
public
:
70
int
state
;
71
std::vector<int>
states
;
72
VVVdouble
cumpxy
;
73
const
SubstitutionModel
*
model
;
74
75
public
:
76
SimData
():
state
(),
states
(),
cumpxy
(),
model
(0) {}
77
SimData
(
const
SimData
& sd):
state
(sd.
state
),
states
(sd.
states
),
cumpxy
(),
model
(sd.
model
) {}
78
SimData
&
operator=
(
const
SimData
& sd)
79
{
80
state
= sd.
state
;
81
states
= sd.
states
;
82
cumpxy
= sd.
cumpxy
;
83
model
= sd.
model
;
84
return
*
this
;
85
}
86
};
87
88
typedef
NodeTemplate<SimData> SNode;
89
95
class
NonHomogeneousSequenceSimulator
:
96
public
DetailedSiteSimulator
,
97
public
virtual
SequenceSimulator
98
{
99
private
:
100
const
SubstitutionModelSet
*
modelSet_
;
101
const
Alphabet
*
alphabet_
;
102
const
DiscreteDistribution
*
rate_
;
103
const
Tree
*
templateTree_
;
104
mutable
TreeTemplate<SNode>
tree_
;
105
bool
ownModelSet_
;
106
111
std::vector<SNode*>
leaves_
;
112
113
std::vector<std::string>
seqNames_
;
114
115
size_t
nbNodes_
;
116
size_t
nbClasses_
;
117
size_t
nbStates_
;
118
119
bool
continuousRates_
;
120
127
public
:
128
NonHomogeneousSequenceSimulator
(
129
const
SubstitutionModelSet
* modelSet,
130
const
DiscreteDistribution
* rate,
131
const
Tree
* tree
132
)
throw
(
Exception
);
133
134
NonHomogeneousSequenceSimulator
(
135
const
SubstitutionModel
* model,
136
const
DiscreteDistribution
* rate,
137
const
Tree
* tree
138
);
139
140
virtual
~NonHomogeneousSequenceSimulator
()
141
{
142
if
(
ownModelSet_
&&
modelSet_
)
delete
modelSet_
;
143
}
144
145
NonHomogeneousSequenceSimulator
(
const
NonHomogeneousSequenceSimulator
& nhss) :
146
modelSet_
(nhss.
modelSet_
),
147
alphabet_
(nhss.
alphabet_
),
148
rate_
(nhss.
rate_
),
149
templateTree_
(nhss.
templateTree_
),
150
tree_
(nhss.
tree_
),
151
ownModelSet_
(nhss.
ownModelSet_
),
152
leaves_
(nhss.
leaves_
),
153
seqNames_
(nhss.
seqNames_
),
154
nbNodes_
(nhss.
nbNodes_
),
155
nbClasses_
(nhss.
nbClasses_
),
156
nbStates_
(nhss.
nbStates_
),
157
continuousRates_
(nhss.
continuousRates_
)
158
{}
159
160
NonHomogeneousSequenceSimulator
&
operator=
(
const
NonHomogeneousSequenceSimulator
& nhss)
161
{
162
modelSet_
= nhss.
modelSet_
;
163
alphabet_
= nhss.
alphabet_
;
164
rate_
= nhss.
rate_
;
165
templateTree_
= nhss.
templateTree_
;
166
tree_
= nhss.
tree_
;
167
ownModelSet_
= nhss.
ownModelSet_
;
168
leaves_
= nhss.
leaves_
;
169
seqNames_
= nhss.
seqNames_
;
170
nbNodes_
= nhss.
nbNodes_
;
171
nbClasses_
= nhss.
nbClasses_
;
172
nbStates_
= nhss.
nbStates_
;
173
continuousRates_
= nhss.
continuousRates_
;
174
return
*
this
;
175
}
176
177
#ifndef NO_VIRTUAL_COV
178
NonHomogeneousSequenceSimulator
*
179
#else
180
Clonable
*
181
#endif
182
clone
()
const
{
return
new
NonHomogeneousSequenceSimulator
(*
this
); }
183
184
private
:
190
void
init
();
191
192
public
:
193
199
Site
*
simulate
()
const
;
200
Site
*
simulate
(
int
ancestralState)
const
;
201
Site
*
simulate
(
int
ancestralState,
double
rate)
const
;
202
Site
*
simulate
(
double
rate)
const
;
203
std::vector<std::string>
getSequencesNames
()
const
{
return
seqNames_
; }
211
RASiteSimulationResult
*
dSimulate
()
const
;
212
213
RASiteSimulationResult
*
dSimulate
(
int
ancestralState)
const
;
214
215
RASiteSimulationResult
*
dSimulate
(
int
ancestralState,
double
rate)
const
;
216
217
RASiteSimulationResult
*
dSimulate
(
double
rate)
const
;
225
SiteContainer
*
simulate
(
size_t
numberOfSites)
const
;
233
const
Alphabet
*
getAlphabet
()
const
{
return
alphabet_
; }
241
virtual
Site
*
simulate
(
int
ancestralState,
size_t
rateClass)
const
;
242
virtual
RASiteSimulationResult
*
dSimulate
(
int
ancestralState,
size_t
rateClass)
const
;
250
const
SubstitutionModelSet
*
getSubstitutionModelSet
()
const
{
return
modelSet_
; }
251
252
253
259
const
DiscreteDistribution
*
getRateDistribution
()
const
{
return
rate_
; }
260
266
const
Tree
*
getTree
()
const
{
return
templateTree_
; }
267
275
void
enableContinuousRates
(
bool
yn) {
continuousRates_
= yn; }
276
277
protected
:
278
285
int
evolve
(
const
SNode
* node,
int
initialState,
size_t
rateClass)
const
;
286
293
int
evolve
(
const
SNode
* node,
int
initialState,
double
rate)
const
;
294
300
void
multipleEvolve
(
const
SNode
* node,
const
Vint
& initialState,
const
std::vector<size_t>& rateClasses,
Vint
& finalStates)
const
;
301
SiteContainer
*
multipleEvolve
(
const
Vint
& initialStates,
const
std::vector<size_t>& rateClasses)
const
;
302
303
void
dEvolve
(
int
initialState,
double
rate,
RASiteSimulationResult
& rassr)
const
;
304
314
void
evolveInternal
(
SNode
* node,
size_t
rateClass)
const
;
318
void
evolveInternal
(
SNode
* node,
double
rate)
const
;
322
void
multipleEvolveInternal
(
SNode
* node,
const
std::vector<size_t>& rateClasses)
const
;
323
327
void
dEvolveInternal
(
SNode
* node,
double
rate,
RASiteSimulationResult
& rassr)
const
;
330
};
331
332
}
//end of namespace bpp.
333
334
#endif //_NONHOMOGENEOUSSEQUENCESIMULATOR_H_
335
Bpp
Phyl
Simulation
NonHomogeneousSequenceSimulator.h
Generated on Thu Mar 14 2013 16:39:10 for bpp-phyl by
1.8.3.1-20130209