comparison egglib/egglib-2.1.5/include/egglib-cpp/Arg.hpp @ 1:420b57c3c185 draft

Uploaded
author dereeper
date Fri, 10 Jul 2015 04:39:30 -0400
parents
children
comparison
equal deleted inserted replaced
0:3e19d0dfcf3e 1:420b57c3c185
1 /*
2 Copyright 2009-2010 Stéphane De Mita, Mathieu Siol
3
4 This file is part of the EggLib library.
5
6 EggLib is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 EggLib is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with EggLib. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 #ifndef EGGLIB_ARG_HPP
22 #define EGGLIB_ARG_HPP
23
24
25 #include "Current.hpp"
26 #include "Edge.hpp"
27 #include <string>
28
29
30 /** \defgroup coalesce coalesce
31 *
32 * \brief Coalescent simulator
33 *
34 * The set of classes implements a three-scale coalescent simulator with
35 * recombination, and a flexible mutation model. The main classes are
36 * Controller (the starting point for generating genealogies), ParamSet
37 * (that centralizes parameter specification), the Change hierarchy
38 * (that implements demographic change specifications), Arg (ancestral
39 * recombination graph; the result of generation a genealogy) and
40 * Mutator (that generates genotype data from an ARG).
41 *
42 */
43
44
45 namespace egglib {
46
47 class Random;
48
49 /** \brief Ancestral recombination graph
50 *
51 * \ingroup coalesce
52 *
53 * This class stores the ARG (genealogical information). It is
54 * progressively built by appropriate (especially regarding to the
55 * timing) calls to coal() and recomb() methods. Then it can be
56 * used by a mutator class to generates data, or it can also
57 * generate newick trees (one tree by non-recombining segment).
58 *
59 */
60 class Arg {
61
62 public:
63
64 /** \brief Default constructor
65 *
66 * Creates a null, useless, object.
67 *
68 */
69 Arg();
70
71
72 /** \brief Object initialization
73 *
74 * \param current address of the Current instance used by
75 * the simulator.
76 *
77 * \param numberOfSegments number of recombining segments.
78 *
79 */
80 void set(Current* current, unsigned int numberOfSegments);
81
82
83 /** \brief Object reset method
84 *
85 * This method doesn't reset all parameters (the number of
86 * segments and associated tables are retained, as well as
87 * the Edge object pool).
88 *
89 * \param current address of the Current instance used by
90 * the simulator.
91 *
92 */
93 void reset(Current* current);
94
95
96 /** \brief Standard constructor
97 *
98 * \param current address of the Current instance used by
99 * the simulator.
100 *
101 * \param numberOfSegments number of recombining segments
102 *
103 */
104 Arg(Current* current, unsigned int numberOfSegments);
105
106
107 /** \brief Destructor
108 *
109 * Clears all Edge instances referenced in the object.
110 *
111 */
112 virtual ~Arg();
113
114
115 /** \brief Gets the current value of the time counter
116 *
117 */
118 double time() const;
119
120
121 /** \brief Increments the time counter
122 *
123 */
124 void addTime(double increment);
125
126
127 /** \brief Performs a coalescence event
128 *
129 * For this version, the two lineages to coalesce are
130 * predefined.
131 *
132 * \param incr increment of the time counter.
133 * \param pop index of the population.
134 * \param index1 first lineage to coalesce.
135 * \param index2 second lineage to coalesce.
136 *
137 */
138 void coalescence(double incr, unsigned int pop, unsigned int index1, unsigned int index2);
139
140
141 /** \brief Performs a coalescence event
142 *
143 * For this version, the two lineages to coalesce are
144 * randomly picked in the given population
145 *
146 * \param incr increment of the time counter.
147 * \param pop index of the population.
148 * \param random pointer to simulator's random generator
149 * instance.
150 *
151 */
152 void coalescence(double incr, unsigned int pop, Random* random);
153
154
155 /** \brief Performs a recombination event
156 *
157 * \param incr increment of the time counter.
158 * \param random pointer to simulator's random generator
159 * instance.
160 *
161 */
162 void recombination(double incr, Random* random);
163
164
165 /** \brief Places a mutation
166 *
167 * \param segment index of the segment affected.
168 *
169 * \param treePosition a random number placed on the
170 * interval defined by the tree length at this position.
171 *
172 * \return the concerned Edge's address.
173 *
174 * \todo why this is not encapsulated?
175 *
176 * Another nerve-taking point: calling this method assume
177 * that all Edge of have previously undergone a call of
178 * branchLength(position) with intervalPosition - what
179 * should be done by the called (that is, Mutator) through
180 * my (Arg's) treeLength of something. BEWARE WHEN MODIFYING
181 * (enhancements should be directed to Edge in my view)
182 *
183 */
184 Edge* mute(unsigned int segment, double treePosition);
185
186
187 /** \brief Age of the uMRCA
188 *
189 * The uMRCA is the ultimate Most Recent Common Ancestor,
190 * that is the point where the last segment finds its most
191 * recent common ancestor. This member will have a meaningful
192 * value only if the coalescent process is completed.
193 *
194 */
195 inline double ageUltimateMRCA() const {
196 return _time;
197 }
198
199
200 /** \brief Age of the MRCA for a given segment
201 *
202 * The MRCA is the Most Recent Common Ancestor, that is the
203 * point where the coalescent process is over (all lineages
204 * have coalesced). This member will have a meaningful
205 * value only if the coalescent process is completed.
206 *
207 * Note that the value is cached; it is computed only one
208 * upon first call and no again, even if the Arg is modified<
209 *
210 */
211 inline double ageMRCA(unsigned int segmentIndex) {
212 return _MRCA[segmentIndex]->bottom;
213 }
214
215 /** \brief MRCA for each segment
216 *
217 * The MRCA is the Most Recent Common Ancestor, that is the
218 * point where the coalescent process is over (all lineages
219 * have coalesced). This member will have a meaningful
220 * value only if the coalescent process is completed.
221 *
222 * Note that the value is cached; it is computed only one
223 * upon first call and no again, even if the Arg is modified
224 *
225 */
226 inline const Edge* MRCA(unsigned int segmentIndex) {
227 return _MRCA[segmentIndex];
228 }
229
230 /// Ultimate MRCA
231
232 inline const Edge* uMRCA() {
233 return edges[numberOfEdges-1];
234 }
235
236
237 /// the number of recombining segments
238 unsigned int numberOfSegments;
239
240 /** \brief Formats the newick-formatted tree for a segment
241 *
242 */
243 std::string newick(unsigned int segment);
244
245
246 /// Number of initial lineages
247 unsigned int numberOfSamples;
248
249
250 /** \brief Total tree length (summed over all segments)
251 *
252 */
253 double totalLength;
254
255 /** \brief Segment-specific tree length
256 *
257 */
258 double* segmentLengths;
259
260 /// Current number of Edges in the tree (including the MRCA node)
261 unsigned int numberOfEdges;
262
263 /// Total number of recombination events that occurred
264 unsigned int numberOfRecombinationEvents;
265
266 /// Set the number of actual sites in all branches
267 void set_actualNumberOfSites(unsigned int actualNumberOfSites);
268
269
270 private:
271
272 /// Copy constructor not available
273 Arg(const Arg&) { }
274
275 /// Assignment operator not available
276 Arg& operator=(const Arg&) { return *this; }
277
278 void init_stable_parameters();
279 void init_variable_parameters();
280 void clear();
281 void addEdge(Edge*);
282 std::string rnewick(Edge* edge, unsigned int segment, double cache);
283
284 Current* current;
285 double _time;
286 Edge** edges;
287
288 void findMRCA(unsigned int segmentIndex);
289 void computeTotalLength();
290 void computeSegmentLength(unsigned int segmentIndex);
291
292 unsigned int* numberOfEdgesPerSegment;
293 Edge** _MRCA;
294
295 EdgePool edgePool;
296 };
297
298 }
299
300 #endif