Egglib 2.1.11
C++ library reference manual
Edge.hpp
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 #ifndef EGGLIB_EDGE_HPP
21 #define EGGLIB_EDGE_HPP
22 
23 #include <vector>
24 #include <climits>
25 #include "EggException.hpp"
26 
27 namespace egglib {
28 
29  class Random;
30 
49  class Edge {
50 
51  public:
52 
54  virtual ~Edge();
55 
65  Edge(unsigned int numberOfSegments);
66 
67 
69  void reset();
70 
71 
90  void coalescence(double date, Edge* son1, Edge* son2,
91  unsigned int* edgesPerSegments, Edge** MRCA,
92  double& totalLength, double* segmentLengths);
93 
94 
110  void recombination(double date,
111  Edge* dest1, Edge* dest2, Random* random,
112  double& totalLength, double* segmentLengths);
113 
114 
120  void set_terminal(unsigned int leaf_index);
121 
123  double length;
124 
126  unsigned int coverage;
127 
129  double bottom;
130 
132  double top;
133 
136 
139 
141  unsigned int numberOfSons;
142 
144  inline bool segment(unsigned int segmentIndex) const {
145  //while(segments[segmentIndex]==0) segmentIndex--;
146  if (segments[segmentIndex]==0) return false;
147  if (segments[segmentIndex]==UINT_MAX) return true;
148  return segbools[segmentIndex];
149  }
150 
152  inline unsigned int label() const {
153  return _label;
154  }
155 
158 
160  void set_actualNumberOfSites(unsigned int actualNumberOfSites);
161 
162 
163  private:
164 
165  unsigned int _label;
166 
168  Edge();
169 
171  Edge(const Edge& edge) {}
172 
174  Edge& operator=(const Edge& edge) { return *this; }
175 
176  void init(unsigned int numberOfSegments);
177 
178  unsigned int numberOfSegments;
179  unsigned int* segments;
180  bool* segbools;
181 
183  inline void fill() {
184  coverage=0.;
185  unsigned int i=0,j;
186  while (i<numberOfSegments) {
187  if (segbools[i]==true) {
188  coverage += segments[i];
189  for (j=1; j<segments[i]; j++) {
190  segments[i+j] = UINT_MAX;
191  }
192  }
193  i+=segments[i];
194  }
195  }
196 
197 
198 
200  inline void update_lengths(double& totalLength, double* segmentLengths) {
201  unsigned int i=0,j;
202  while (i<numberOfSegments) {
203  if (segbools[i]==true) {
204  totalLength += segments[i]*length;
205  for (j=0; j<segments[i]; j++) {
206  segmentLengths[i+j] += length;
207  }
208  }
209  i+=segments[i];
210  }
211  }
212 
213 
214  };
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
240  class EdgePool {
241 
242  public:
243 
245  EdgePool();
246 
247 
249  virtual ~EdgePool();
250 
251 
268  void set(unsigned int numberOfSegments, unsigned numberOfPreAllocated);
269 
270 
278  void clear();
279 
280 
289  Edge* deliver();
290 
291 
300  void releaseLast();
301 
302 
311  void releaseAll();
312 
313  private:
314 
316  EdgePool(const EdgePool& ep) {}
317 
319  EdgePool& operator=(const EdgePool& ep) { return *this; }
320 
321  unsigned int numberOfSegments;
322  unsigned int used;
323  unsigned int released;
324  unsigned int ready;
325  Edge** cache;
326 
327  };
328 
329 }
330 
331 #endif
virtual ~EdgePool()
Destructor.
Definition: Edge.cpp:456
Pseudo-random number generator.
Definition: Random.hpp:41
void releaseLast()
Release an Edge.
Definition: Edge.cpp:501
void set_actualNumberOfSites(unsigned int actualNumberOfSites)
Sets the actual number of sites.
Definition: Edge.cpp:402
double bottom
Time position of the branch's bottom.
Definition: Edge.hpp:129
void set_terminal(unsigned int leaf_index)
Define this edge to be terminal.
Definition: Edge.cpp:82
Edge * son1
Address of the first son.
Definition: Edge.hpp:135
Edge * deliver()
Deliver an Edge.
Definition: Edge.cpp:474
unsigned int label() const
leaf index (0 for internal nodes)
Definition: Edge.hpp:152
unsigned int coverage
Number of covered segments.
Definition: Edge.hpp:126
double top
Time position of the branch's top.
Definition: Edge.hpp:132
Edge * son2
Address of the second son.
Definition: Edge.hpp:138
void set(unsigned int numberOfSegments, unsigned numberOfPreAllocated)
Configure pool.
Definition: Edge.cpp:434
void releaseAll()
Release all Edge's.
Definition: Edge.cpp:511
double length
Branch's raw length (doesn't take account segment coverage)
Definition: Edge.hpp:123
unsigned int * numberOfMutationsPerActualSite
Number of mutations per segment.
Definition: Edge.hpp:157
Edge of the ancestral recombination graph.
Definition: Edge.hpp:49
void clear()
Frees internally stored memory.
Definition: Edge.cpp:461
unsigned int numberOfSons
Number of sons (0, 1 or 2)
Definition: Edge.hpp:141
Definition: ABC.cpp:37
void recombination(double date, Edge *dest1, Edge *dest2, Random *random, double &totalLength, double *segmentLengths)
Generates a recombination event.
Definition: Edge.cpp:262
virtual ~Edge()
Destructor.
Definition: Edge.cpp:75
bool segment(unsigned int segmentIndex) const
Checks if a given segment is covered.
Definition: Edge.hpp:144
Pool of Edge objects.
Definition: Edge.hpp:240
void coalescence(double date, Edge *son1, Edge *son2, unsigned int *edgesPerSegments, Edge **MRCA, double &totalLength, double *segmentLengths)
Builds for internal node.
Definition: Edge.cpp:132
EdgePool()
Default constructor (nothing allocated)
Definition: Edge.cpp:426
void reset()
Restore object to factory state.
Definition: Edge.cpp:93

Hosted by 
Get EggLib at SourceForge.net. Fast, secure and Free Open Source software downloads