Parallel PopGen Package
go_fish_data_struct.h
Go to the documentation of this file.
1 
11 /* go_fish_data_struct.h
12  *
13  * Author: David Lawrie
14  * Subset of go_fish.cuh: GO_Fish data structures
15  */
16 
17 #ifndef GO_FISH_DATA_H_
18 #define GO_FISH_DATA_H_
19 
20 #include <iostream>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string>
24 #include <sstream>
25 #include <cstring>
26 
28 namespace Spectrum_details{ class transfer_allele_trajectories; } //for passing data to SPECTRUM functions
30 
31 namespace GO_Fish{
32 
33 /* ----- sim result output ----- */
35 struct mutID{
39  int reserved;
41  inline mutID();
43 
45  inline mutID(int origin_generation, int origin_population, int origin_threadID, int reserved);
46 
48  inline std::string toString();
50  inline std::string toString() const;
51 };
52 
55  //----- initialization parameters -----
57  struct sim_constants{
58  int seed1;
59  int seed2;
61  float num_sites;
63  bool init_mse;
67  int device;
69  inline sim_constants();
70  };
71 
73  //----- end -----
74 
76  inline allele_trajectories();
77 
79  inline allele_trajectories(const allele_trajectories & in);
80 
82  inline allele_trajectories & operator=(allele_trajectories in);
83 
85  inline sim_constants last_run_constants();
86 
88  inline int num_sites();
89 
91  inline int num_populations();
92 
94  inline int num_time_samples();
95 
97  inline int maximal_num_mutations();
98 
100  inline int num_mutations_time_sample(int sample_index);
101 
103  inline int final_generation();
104 
106  inline int sampled_generation(int sample_index);
107 
109  inline bool extinct(int sample_index, int population_index);
110 
112  inline int effective_number_of_chromosomes(int sample_index, int population_index);
113 
115  inline float frequency(int sample_index, int population_index, int mutation_index);
116 
118  inline mutID mutation_ID(int mutation_index);
119 
121  inline void delete_time_sample(int sample_index);
122 
124  inline void reset();
125 
127  inline ~allele_trajectories();
128 
130  friend void swap(allele_trajectories & a, allele_trajectories & b);
131 
132  friend std::ostream & operator<<(std::ostream & stream, allele_trajectories & A);
133 
134  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>
135  friend 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);
136 
137  friend class Spectrum_details::transfer_allele_trajectories;
139 private:
140 
141  struct time_sample{
142  float * mutations_freq; //allele frequency of mutations in final generation
143  bool * extinct; //extinct[pop] == true, flag if population is extinct by time sample
144  int * Nchrom_e; //effective number of chromosomes in each population
145  int num_mutations; //number of mutations in frequency array (columns array length for freq)
146  int sampled_generation; //number of generations in the simulation at point of sampling
147 
148  time_sample();
149  ~time_sample();
150  };
151 
152  inline void initialize_run_constants();
153 
154  inline void initialize_sim_result_vector(int new_length);
155 
156  sim_constants sim_run_constants; //stores constants of the simulation run currently held by time_samples
157  time_sample ** time_samples; //the actual allele trajectories output from the simulation
158  int num_samples; //number of time samples taken from the simulation
159  mutID * mutations_ID; //unique ID for each mutation in simulation
160  int all_mutations; //number of mutations in mutation ID array - maximal set of mutations stored in allele_trajectories
161 };
164 inline std::ostream & operator<<(std::ostream & stream, const mutID & id);
165 
167 inline std::ostream & operator<<(std::ostream & stream, allele_trajectories & A);
168 
170 inline void swap(allele_trajectories & a, allele_trajectories & b);
171 
172 /* ----- end sim result output ----- */
173 
174 } /* ----- end namespace GO_Fish ----- */
175 
176 /* ----- import inline function definitions ----- */
177 #include "../3P/_internal/inline_go_fish_data_struct.hpp"
178 /* ----- end ----- */
179 
180 #endif /* GO_FISH_DATA_H_ */
int prev_sim_sample
time sample of previous simulation to use for initializing current simulation
int origin_generation
generation in which mutation appeared in simulation
control and output data structure for GO_Fish simulation
int compact_interval
how often to compact the simulation and remove fixed or lost mutations
specification of simulation constants
int num_populations
number of populations in simulation
std::ostream & operator<<(std::ostream &stream, allele_trajectories &A)
insertion operator: sends allele_trajectories A into the ostream stream
int origin_threadID
threadID that generated mutation
structure specifying the ID for a mutation in a GO_Fish simulation
void swap(allele_trajectories &a, allele_trajectories &b)
swaps data held by allele_trajectories a and b
int origin_population
population in which mutation first arose
__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)
runs a single-locus Wright-Fisher simulation specified by the given simulation functions and sim_cons...
float num_sites
number of sites in simulation
bool init_mse
true: initialize simulation in mutation_selection_equilibrium; false: initialize blank simulation or ...
int device
GPU identity to run simulation on, if -1 next available GPU will be assigned.
Namespace for single-locus, forward, Monte-Carlo Wright-Fisher simulation and output data structures...
Definition: go_fish.cuh:326
sim_constants sim_input_constants
constants for initializing the next simulation
int reserved
reserved for later use, currently 0
int num_generations
number of generations in simulation