Parallel PopGen Package
go_fish.cuh
Go to the documentation of this file.
1 
12 /*
13  * go_fish.cuh
14  *
15  * Author: David Lawrie
16  * GO Fish Simulation API
17  */
18 
19 #ifndef GO_FISH_API_H_
20 #define GO_FISH_API_H_
21 #include <cuda_runtime.h>
22 #include "../3P/_outside_libraries/helper_math.h"
23 #include "../3P/go_fish_data_struct.h"
24 
26 namespace Sim_Model{
27 
30 /* ----- mutation, dominance, & inbreeding models ----- */
33 {
34  float s;
35  inline selection_constant();
36  inline selection_constant(float s);
37  template <typename Functor_demography, typename Functor_inbreeding>
38  inline selection_constant(float gamma, Functor_demography demography, Functor_inbreeding F, int forward_generation_shift = 0);
39  __device__ __forceinline__ float operator()(const int population, const int generation, const float freq) const;
40 };
41 
44 {
45  float slope;
46  float intercept;
48  inline selection_linear_frequency_dependent(float slope, float intercept);
49  template <typename Functor_demography, typename Functor_inbreeding>
50  inline selection_linear_frequency_dependent(float gamma_slope, float gamma_intercept, Functor_demography demography, Functor_inbreeding F, int forward_generation_shift = 0);
51  __device__ __forceinline__ float operator()(const int population, const int generation, const float freq) const;
52 };
53 
56 {
57  float A;
58  float pi;
59  float rho;
60  float D;
63  inline selection_sine_wave();
64  inline selection_sine_wave(float A, float pi, float D, float rho = 0, int generation_shift = 0);
65  template <typename Functor_demography, typename Functor_inbreeding>
66  inline selection_sine_wave(float gamma_A, float pi, float gamma_D, Functor_demography demography, Functor_inbreeding F, float rho = 0, int generation_shift = 0, int forward_generation_shift = 0);
67  __device__ __forceinline__ float operator()(const int population, const int generation, const float freq) const;
68 };
69 
71 template <typename Functor_sel, typename Functor_sel_pop>
73 {
74  int pop;
76  Functor_sel s;
77  Functor_sel_pop s_pop;
79  inline selection_population_specific(Functor_sel s_in, Functor_sel_pop s_pop_in, int pop, int generation_shift = 0);
80  __device__ __forceinline__ float operator()(const int population, const int generation, const float freq) const;
81 };
82 
84 template <typename Functor_sel1, typename Functor_sel2>
86 {
89  Functor_sel1 s1;
90  Functor_sel2 s2;
91  inline selection_piecewise();
92  inline selection_piecewise(Functor_sel1 s1_in, Functor_sel2 s2_in, int inflection_point, int generation_shift = 0);
93  __device__ __forceinline__ float operator()(const int population, const int generation, const float freq) const;
94 };
95 /* ----- end selection models ----- */
99 /* ----- inbreeding, mutation, & dominance models ----- */
102 {
103  float p;
104  inline F_mu_h_constant();
105  inline F_mu_h_constant(float p);
106  __host__ __forceinline__ float operator()(const int population, const int generation) const;
107 };
108 
111 {
112  float A;
113  float pi;
114  float rho;
115  float D;
117 
118  inline F_mu_h_sine_wave();
119  inline F_mu_h_sine_wave(float A, float pi, float D, float rho = 0, int generation_shift = 0);
120  __host__ __forceinline__ float operator()(const int population, const int generation) const;
121 };
122 
124 template <typename Functor_p, typename Functor_p_pop>
126 {
127  int pop;
129  Functor_p p;
130  Functor_p_pop p_pop;
131  inline F_mu_h_population_specific();
132  inline F_mu_h_population_specific(Functor_p p_in, Functor_p_pop p_pop_in, int pop, int generation_shift = 0);
133  __host__ __forceinline__ float operator()(const int population, const int generation) const;
134 };
135 
137 template <typename Functor_p1, typename Functor_p2>
139 {
142  Functor_p1 p1;
143  Functor_p2 p2;
144  inline F_mu_h_piecewise();
145  inline F_mu_h_piecewise(Functor_p1 p1_in, Functor_p2 p2_in, int inflection_point, int generation_shift = 0);
146  __host__ __forceinline__ float operator()(const int population, const int generation) const;
147 };
148 /* ----- end of inbreeding, mutation, & dominance models ----- */
152 /* ----- demography models ----- */
155 {
156  int N;
157  inline demography_constant();
158  inline demography_constant(int p);
159  __host__ __device__ __forceinline__ int operator()(const int population, const int generation) const;
160 };
161 
164 {
165  float A;
166  float pi;
167  float rho;
168  float D;
170 
171  inline demography_sine_wave();
172  inline demography_sine_wave(float A, float pi, int D, float rho = 0, int generation_shift = 0);
173  __host__ __device__ __forceinline__ int operator()(const int population, const int generation) const;
174 };
175 
178 {
179  float rate;
182 
184  inline demography_exponential_growth(float rate, int initial_population_size, int generation_shift = 0);
185  __host__ __device__ __forceinline__ int operator()(const int population, const int generation) const;
186 };
187 
190 {
191  float rate;
195 
196  inline demography_logistic_growth();
197  inline demography_logistic_growth(float rate, int initial_population_size, int carrying_capacity, int generation_shift = 0);
198  __host__ __device__ __forceinline__ int operator()(const int population, const int generation) const;
199 };
200 
202 template <typename Functor_d, typename Functor_d_pop>
204 {
205  int pop;
207  Functor_d d;
208  Functor_d_pop d_pop;
210  inline demography_population_specific(Functor_d d_in, Functor_d_pop d_pop_in, int pop, int generation_shift = 0);
211  __host__ __device__ __forceinline__ int operator()(const int population, const int generation) const;
212 };
213 
215 template <typename Functor_d1, typename Functor_d2>
217 {
220  Functor_d1 d1;
221  Functor_d2 d2;
222  inline demography_piecewise();
223  inline demography_piecewise(Functor_d1 d1_in, Functor_d2 d2_in, int inflection_point, int generation_shift = 0);
224  __host__ __device__ __forceinline__ int operator()(const int population, const int generation) const;
225 };
226 /* ----- end of demography models ----- */
230 /* ----- migration models ----- */
233 {
234  float m;
235  int num_pop;
236  inline migration_constant_equal();
237  inline migration_constant_equal(float m, int num_pop);
238  __host__ __device__ __forceinline__ float operator()(const int pop_FROM, const int pop_TO, const int generation) const;
239 };
240 
242 template <typename Functor_m1>
244 {
245  float m;
246  int pop1;
247  int pop2;
248  Functor_m1 rest;
250  inline migration_constant_directional(float m, int pop1, int pop2, Functor_m1 rest_in);
251  __host__ __device__ __forceinline__ float operator()(const int pop_FROM, const int pop_TO, const int generation) const;
252 };
253 
255 template <typename Functor_m1, typename Functor_m2>
257 {
260  Functor_m1 m1;
261  Functor_m2 m2;
262  inline migration_piecewise();
263  inline migration_piecewise(Functor_m1 m1_in, Functor_m2 m2_in, int inflection_point, int generation_shift = 0);
264  __host__ __device__ __forceinline__ float operator()(const int pop_FROM, const int pop_TO, const int generation) const;
265 };
266 /* ----- end of migration models ----- */
270 /* ----- preserving & sampling functions ----- */
272 struct bool_off{
273  __host__ __forceinline__ bool operator()(const int generation) const;
274 };
275 
277 struct bool_on{
278  __host__ __forceinline__ bool operator()(const int generation) const;
279 };
280 
281 /* will switch to variadic templates/initializer lists when switching to C++11
282 struct bool_pulse_array{
283  bool * array;
284  int num_generations;
285  int generation_start;
286  inline bool_pulse_array();
287  inline bool_pulse_array(const bool default_return, const int generation_start, const int num_generations, int generation_pulse...);
288  __host__ __forceinline__ bool operator()(const int generation) const;
289  ~bool_pulse_array();
290 
291 private:
292  inline bool_pulse_array(int generation_pulse...);
293  inline bool_pulse_array(int generation_pulse);
294 }; */
295 
297 template <typename Functor_default, typename Functor_action>
298 struct bool_pulse{
299  int pulse;
301  Functor_default f_default;
302  Functor_action f_action;
303  bool_pulse();
304  bool_pulse(int pulse, int generation_shift = 0);
305  bool_pulse(Functor_default f_default_in, Functor_action f_action, int pulse, int generation_shift = 0);
306  __host__ __forceinline__ bool operator()(const int generation) const;
307 };
308 
310 template <typename Functor_first, typename Functor_second>
314  Functor_first f1;
315  Functor_second f2;
316  inline bool_piecewise();
317  inline bool_piecewise(int inflection_point, int generation_shift = 0);
318  inline bool_piecewise(Functor_first f1_in, Functor_second f2_in, int inflection_point, int generation_shift = 0);
319  __host__ __forceinline__ bool operator()(const int generation) const;
320 };
321 /* ----- end of preserving & sampling functions ----- */
323 } /* ----- end namespace Sim_Model ----- */
324 
326 namespace GO_Fish{
327 
328 /* ----- go_fish_impl ----- */
330 template <typename Functor_mutation, typename Functor_demography, typename Functor_migration, typename Functor_selection, typename Functor_inbreeding, typename Functor_dominance, typename Functor_preserve, typename Functor_timesample>
331 __host__ void run_sim(allele_trajectories & all_results, const Functor_mutation mu_rate, const Functor_demography demography, const Functor_migration mig_prop, const Functor_selection sel_coeff, const Functor_inbreeding FI, const Functor_dominance dominance, const Functor_preserve preserve_mutations, const Functor_timesample take_sample);
333 template <typename Functor_mutation, typename Functor_demography, typename Functor_migration, typename Functor_selection, typename Functor_inbreeding, typename Functor_dominance, typename Functor_preserve, typename Functor_timesample>
334 __host__ void run_sim(allele_trajectories & all_results, const Functor_mutation mu_rate, const Functor_demography demography, const Functor_migration mig_prop, const Functor_selection sel_coeff, const Functor_inbreeding FI, const Functor_dominance dominance, const Functor_preserve preserve_mutations, const Functor_timesample take_sample, const allele_trajectories & prev_sim);
335 /* ----- end go_fish_impl ----- */
336 
337 } /* ----- end namespace GO_Fish ----- */
338 
339 /* ----- importing functor implementations ----- */
340 #include "../3P/_internal/template_inline_simulation_functors.cuh"
341 /* ----- end importing functor implementations ----- */
342 
343 /* ----- importing go_fish_impl ----- */
344 #include "../3P/_internal/go_fish_impl.cuh"
345 /* ----- end importing go_fish_impl ----- */
346 
347 
348 #endif /* GO_FISH_API_H_ */
functor: models population size (individuals) as a sine wave through time
Definition: go_fish.cuh:163
functor: models selection coefficient s as a constant across populations and over time ...
Definition: go_fish.cuh:32
int initial_population_size
initial population size
Definition: go_fish.cuh:180
int num_pop
number of population participating in equal migration
Definition: go_fish.cuh:235
int N
population size (individuals) constant
Definition: go_fish.cuh:156
Functor_m2 m2
second migration function
Definition: go_fish.cuh:261
float D
Offset of sine wave.
Definition: go_fish.cuh:60
float rate
logistic growth rate
Definition: go_fish.cuh:191
float m
migration rate from pop i to pop j =/= i
Definition: go_fish.cuh:234
functor: migration function changes from m1 to m2 at generation inflection_point
Definition: go_fish.cuh:256
functor: turns sampling and preserving off (for every generation except the final one which is always...
Definition: go_fish.cuh:272
functor: parameter function changes from p1 to p2 at generation inflection_point
Definition: go_fish.cuh:138
control and output data structure for GO_Fish simulation
int inflection_point
generation in which the Demographic function switches from d1 to d2
Definition: go_fish.cuh:218
functor: single, constant population size (N individuals) across populations and over time ...
Definition: go_fish.cuh:154
float pi
Frequency of sine wave.
Definition: go_fish.cuh:166
float A
Amplitude of sine wave.
Definition: go_fish.cuh:112
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:313
float A
Amplitude of sine wave.
Definition: go_fish.cuh:57
float rho
Phase of sine wave.
Definition: go_fish.cuh:59
functor: migration flows at rate m from pop1 to pop2 and function rest for all other migration rates ...
Definition: go_fish.cuh:243
Functor_sel_pop s_pop
population specific selection function for pop
Definition: go_fish.cuh:77
functor: one population, pop, has a different, selection function, s_pop, all other have function s ...
Definition: go_fish.cuh:72
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:61
float pi
Frequency of sine wave.
Definition: go_fish.cuh:113
int pop
population with specific demography function
Definition: go_fish.cuh:205
Namespace of functions for controlling GO_Fish simulations.
Definition: go_fish.cuh:26
__device__ __forceinline__ float operator()(const int population, const int generation, const float freq) const
selection operator, returns selection coefficient, s, for a given population, generation, freq
Functor_sel s
selection function applied to all other populations
Definition: go_fish.cuh:76
float p
parameter constant
Definition: go_fish.cuh:103
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:300
float D
Offset of sine wave.
Definition: go_fish.cuh:115
Functor_d2 d2
second demographic function
Definition: go_fish.cuh:221
functor: models logistic growth of population size (individuals) over time
Definition: go_fish.cuh:189
Functor_d1 d1
first demographic function
Definition: go_fish.cuh:220
functor: one population, pop, has a different, parameter function, p_pop, all others have function p ...
Definition: go_fish.cuh:125
float slope
slope of selection coefficient&#39;s linear dependence on frequency
Definition: go_fish.cuh:45
Functor_d d
demographic function applied to all other populations
Definition: go_fish.cuh:207
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:206
Functor_p1 p1
first parameter function
Definition: go_fish.cuh:142
int inflection_point
generation in which the migration function switches from m1 to m2
Definition: go_fish.cuh:258
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:259
functor: models parameter as a sine wave through time
Definition: go_fish.cuh:110
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:116
functor: one population, pop, has a different, demography function, d_pop, all others have function...
Definition: go_fish.cuh:203
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:194
int pulse
generation in which the boolean pulse f_action is emitted
Definition: go_fish.cuh:299
int inflection_point
generation in which the boolean function switches from f1 to f2
Definition: go_fish.cuh:312
float A
Amplitude of sine wave.
Definition: go_fish.cuh:165
Functor_m1 rest
migration function specifying migration in remaining migration directions
Definition: go_fish.cuh:248
Functor_p p
parameter function applied to all other populations
Definition: go_fish.cuh:129
Functor_d_pop d_pop
population specific demographic function for pop
Definition: go_fish.cuh:208
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:88
int inflection_point
generation in which the selection function switches from s1 to s2
Definition: go_fish.cuh:87
Functor_m1 m1
first migration function
Definition: go_fish.cuh:260
Functor_sel1 s1
first selection function
Definition: go_fish.cuh:89
float m
migration rate from pop1 to pop2
Definition: go_fish.cuh:245
Functor_p2 p2
second parameter function
Definition: go_fish.cuh:143
functor: selection function changes from s1 to s2 at generation inflection_point
Definition: go_fish.cuh:85
float D
Offset of sine wave.
Definition: go_fish.cuh:168
__host__ void run_sim(allele_trajectories &all_results, const Functor_mutation mu_rate, const Functor_demography demography, const Functor_migration mig_prop, const Functor_selection sel_coeff, const Functor_inbreeding FI, const Functor_dominance dominance, const Functor_preserve preserve_mutations, const Functor_timesample take_sample, const allele_trajectories &prev_sim)
runs a single-locus Wright-Fisher simulation specified by the given simulation functions and sim_cons...
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:181
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:128
functor: models selection coefficient as linearly dependent on frequency
Definition: go_fish.cuh:43
Functor_second f2
second boolean function
Definition: go_fish.cuh:315
float rho
Phase of sine wave.
Definition: go_fish.cuh:114
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:169
functor: returns the result of function f1 until generation inflection_point, then returns the result...
Definition: go_fish.cuh:311
functor: models parameter p as a constant across populations and over time
Definition: go_fish.cuh:101
functor: migration flows at rate m from pop i to pop j =/= i and 1-(num_pop-1)*m for i == j ...
Definition: go_fish.cuh:232
functor: turns sampling and preserving on (for every generation except the final one which is always ...
Definition: go_fish.cuh:277
float pi
Frequency of sine wave.
Definition: go_fish.cuh:58
functor: models exponential growth of population size (individuals) over time
Definition: go_fish.cuh:177
float intercept
selection coefficient&#39;s intercept with frequency 0
Definition: go_fish.cuh:46
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:141
Functor_sel2 s2
second selection function
Definition: go_fish.cuh:90
Functor_first f1
first boolean function
Definition: go_fish.cuh:314
functor: models selection as a sine wave through time
Definition: go_fish.cuh:55
Functor_p_pop p_pop
population specific parameter function for pop
Definition: go_fish.cuh:130
int inflection_point
generation in which the Inbreeding/Mutation/Dominance function switches from p1 to p2 ...
Definition: go_fish.cuh:140
float rate
exponential growth rate
Definition: go_fish.cuh:179
float rho
Phase of sine wave.
Definition: go_fish.cuh:167
int pop
population with specific selection function
Definition: go_fish.cuh:74
int carrying_capacity
carrying capacity
Definition: go_fish.cuh:193
Namespace for single-locus, forward, Monte-Carlo Wright-Fisher simulation and output data structures...
Definition: go_fish.cuh:326
functor: returns the result of function f_default except at generation pulse returns the result of fu...
Definition: go_fish.cuh:298
Functor_default f_default
default boolean function
Definition: go_fish.cuh:301
int initial_population_size
initial population size
Definition: go_fish.cuh:192
Functor_action f_action
boolean function emitted at generation pulse
Definition: go_fish.cuh:302
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:219
float s
selection coefficient
Definition: go_fish.cuh:34
int generation_shift
number of generations to shift function backwards
Definition: go_fish.cuh:75
int pop
population with specific parameter function
Definition: go_fish.cuh:127
functor: demography function changes from d1 to d2 at generation inflection_point ...
Definition: go_fish.cuh:216