forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
Locus.hpp
1 //
2 // Locus.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 _LOCUS_HPP_
37 #define _LOCUS_HPP_
38 
39 
40 #include "Configurable.hpp"
41 
42 
48 
49 
50 //
51 // Locus
52 //
53 
54 
67 
68 
69 struct Locus : public Configurable
70 {
71  size_t chromosome_pair_index;
72  unsigned int position;
73 
74  Locus(const std::string& id, size_t _chromosome_pair_index = 0, unsigned int _position = 0)
75  : Configurable(id), chromosome_pair_index(_chromosome_pair_index), position(_position)
76  {}
77 
78  // Configurable interface
79 
80  virtual std::string class_name() const {return "Locus";}
81  virtual Parameters parameters() const;
82  virtual void configure(const Parameters& parameters, const Registry& registry);
83 };
84 
85 
86 typedef shared_ptr<Locus> LocusPtr;
87 typedef std::set<Locus> Loci;
88 
89 
90 bool operator<(const Locus& a, const Locus& b);
91 bool operator==(const Locus& a, const Locus& b);
92 bool operator!=(const Locus& a, const Locus& b);
93 std::ostream& operator<<(std::ostream& os, const Locus& locus);
94 
95 
96 //
97 // LocusList
98 //
99 
100 
122 
123 
124 class LocusList : public std::vector<Locus>, public Configurable
125 {
126  public:
127 
128  LocusList(const std::string& id) : Configurable(id) {}
129 
130  // Configurable interface
131 
132  virtual std::string class_name() const {return "LocusList";}
133  virtual Parameters parameters() const;
134  virtual void configure(const Parameters& parameters, const Registry& registry);
135  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
136 
137  protected:
138 
139  std::string generate_locus_id(size_t index) const;
140 };
141 
142 
143 typedef shared_ptr<LocusList> LocusListPtr;
144 typedef std::vector<LocusListPtr> LocusListPtrs;
145 
146 
147 //
148 // LocusList_Random
149 //
150 
151 
163 
164 
166 {
167  public:
168 
169  LocusList_Random(const std::string& id) : LocusList(id), locus_count_(0) {}
170 
171  // Configurable interface
172 
173  virtual std::string class_name() const {return "LocusList_Random";}
174  virtual Parameters parameters() const;
175  virtual void configure(const Parameters& parameters, const Registry& registry);
176  virtual void initialize(const SimulatorConfig& config);
177  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const {}
178 
179  private:
180 
181  size_t locus_count_;
182 };
183 
184 
185 #endif // _LOCUS_HPP_
186