forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
MutationGenerator.hpp
1 //
2 // MutationGenerator.hpp
3 //
4 // Created by Darren Kessner with John Novembre
5 //
6 // Copyright (c) 2013 Regents of the University of California
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // * Neither UCLA nor the names of its contributors may be used to endorse or
20 // promote products derived from this software without specific prior
21 // written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34 
35 
36 #ifndef _MUTATIONGENERATOR_HPP_
37 #define _MUTATIONGENERATOR_HPP_
38 
39 
40 #include "Locus.hpp"
41 #include "Population.hpp"
42 #include "Trajectory.hpp"
43 #include "shared_ptr.hpp"
44 
45 
51 
52 
53 //
54 // MutationGenerator
55 //
56 
57 
61 
62 
64 {
65  public:
66 
67  struct MutationInfo
68  {
69  size_t individual_index;
70  Locus locus;
71  int which; // 0 == chromosome_pair.first, 1 == chromosome_pair.second
72  unsigned int value; // new value to be returned by VariantIndicator
73 
74  MutationInfo()
75  : individual_index(0), locus("id_dummy"), which(0), value(0)
76  {}
77  };
78 
79  typedef std::vector<MutationInfo> MutationInfos;
80 
81  MutationGenerator(const std::string& id) : Configurable(id) {}
82 
83  virtual MutationInfos generate_mutations(const Population& population,
84  size_t generation_index,
85  size_t population_index) const {return MutationInfos();}
86  // Configurable interface
87 
88  virtual std::string class_name() const {return "MutationGenerator";}
89  virtual Parameters parameters() const {return Parameters();}
90  virtual void configure(const Parameters& parameters, const Registry& registry) {}
91 
92  virtual ~MutationGenerator() {}
93 };
94 
95 
96 typedef shared_ptr<MutationGenerator> MutationGeneratorPtr;
97 
98 
99 std::ostream& operator<<(std::ostream& os, const MutationGenerator::MutationInfo& mutation_info);
100 
101 
102 //
103 // MutationGenerator_SingleLocus
104 //
105 
106 
123 
124 
126 {
127  public:
128 
129  MutationGenerator_SingleLocus(const std::string& id,
130  const Locus& locus = Locus("id_dummy"),
131  double mu = 0.)
132  : MutationGenerator(id), locus_(locus), mu_(mu)
133  {}
134 
135  virtual MutationInfos generate_mutations(const Population& population,
136  size_t generation_index,
137  size_t population_index) const;
138  // Configurable interface
139 
140  virtual std::string class_name() const {return "MutationGenerator_SingleLocus";}
141  virtual Parameters parameters() const;
142  virtual void configure(const Parameters& parameters, const Registry& registry);
143  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
144 
145  private:
146 
147  Locus locus_;
148  double mu_;
149 };
150 
151 
152 //
153 // MutationGenerator_Regions
154 //
155 
156 
172 
173 
175 {
176  public:
177 
178  struct RegionInfo
179  {
180  Locus locus;
181  size_t length;
182  TrajectoryPtr mutation_rate;
183 
184  RegionInfo(const Locus& _locus = Locus("id_dummy"),
185  size_t _length = 0,
186  TrajectoryPtr _mutation_rate = TrajectoryPtr())
187  : locus(_locus), length(_length), mutation_rate(_mutation_rate)
188  {}
189 
190  std::string configuration() const;
191  };
192 
193  typedef std::vector<RegionInfo> RegionInfos;
194 
195  MutationGenerator_Regions(const std::string& id,
196  const RegionInfos& region_infos = RegionInfos())
197  : MutationGenerator(id), region_infos_(region_infos)
198  {}
199 
200  virtual MutationInfos generate_mutations(const Population& population,
201  size_t generation_index,
202  size_t population_index) const;
203  // Configurable interface
204 
205  virtual std::string class_name() const {return "MutationGenerator_Regions";}
206  virtual Parameters parameters() const;
207  virtual void configure(const Parameters& parameters, const Registry& registry);
208  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
209 
210  private:
211 
212  RegionInfos region_infos_;
213 };
214 
215 
216 #endif // _MUTATIONGENERATOR_HPP_
217