forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
QuantitativeTrait.hpp
1 //
2 // QuantitativeTrait.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 _QUANTITATIVETRAIT_HPP_
37 #define _QUANTITATIVETRAIT_HPP_
38 
39 
40 #include "Genotype.hpp"
41 #include "DataVector.hpp"
42 #include "shared_ptr.hpp"
43 
44 
45 //
46 // QuantitativeTrait
47 //
48 
52 
54 {
55  public:
56 
57  // return set of loci (the QTLs contributing to the trait)
58  const Loci& loci() const {return loci_;}
59 
60  // calculate trait values for a single population using genotypes
61  virtual DataVectorPtr calculate_trait_values(const GenotypeMap& genotypes,
62  size_t generation_index,
63  size_t population_index) const = 0;
64  virtual ~QuantitativeTrait() {}
65 
66  // Configurable interface
67 
68  virtual std::string class_name() const;
69  virtual Parameters parameters() const;
70  virtual void configure(const Parameters& parameters, const Registry& registry);
71 
72  protected:
73 
74  QuantitativeTrait(const std::string& id) : Configurable(id) {}
75 
76  Loci loci_;
77 };
78 
79 
80 typedef shared_ptr<QuantitativeTrait> QuantitativeTraitPtr;
81 typedef std::vector<QuantitativeTraitPtr> QuantitativeTraitPtrs;
82 
83 
84 class TraitValueMap : public std::map<std::string, DataVectorPtr> // map QT id -> trait_values
85 {
86  public:
87 
88  DataVectorPtr get(const std::string& qtid) const
89  {
90  if (!count(qtid))
91  throw std::runtime_error(("[TraitValueMap] Quantitative trait id " + qtid + " not found.").c_str());
92  return at(qtid);
93  }
94 };
95 
96 
97 typedef shared_ptr<TraitValueMap> TraitValueMapPtr;
98 
99 
100 #endif // _QUANTITATIVETRAIT_HPP_
101