Nemo  2.3.46
TTQFreqExtractor Class Reference

TTQFreqExtractor. More...

#include <ttquanti.h>

+ Inheritance diagram for TTQFreqExtractor:
+ Collaboration diagram for TTQFreqExtractor:

Public Member Functions

 TTQFreqExtractor (TProtoQuanti *T)
 
void resetTable ()
 
virtual ~TTQFreqExtractor ()
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
- Public Member Functions inherited from TraitFileHandler< TProtoQuanti >
 TraitFileHandler (TProtoQuanti *trait_proto, const char *ext)
 
virtual ~TraitFileHandler ()
 
virtual void set (bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path, TProtoQuanti *trait_proto)
 
- Public Member Functions inherited from FileHandler
 FileHandler (const char *ext)
 
virtual ~FileHandler ()
 
virtual void init ()
 Called by notifier during simulation setup, performs file checking. More...
 
virtual bool ifExist ()
 Checks if any file associated with the current file name already exists on disk. More...
 
virtual void set (bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
 Sets the hanlder parameters. More...
 
virtual void set_multi (bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path)
 
virtual void update ()
 Updates the inner replicate and generation counters and calls FHwrite if needed by the the periodicity of the file. More...
 
Metapopget_pop_ptr ()
 Returns the pointer to the current metapop through the FileServices interface. More...
 
void set_pop_ptr (Metapop *pop_ptr)
 
FileServicesget_service ()
 Returns pointer to the FileServices. More...
 
void set_service (FileServices *srv)
 
std::string & get_path ()
 
void set_path ()
 
std::string & get_extension ()
 
void set_extension (const char *ext)
 
std::string & get_filename ()
 Builds and returns the current file name depending on the periodicity of the file. More...
 
bool get_isInputHandler ()
 
void set_isInputHandler (bool val)
 
bool get_isReplicatePeriodic ()
 
void set_isReplicatePeriodic (bool val)
 
unsigned int get_ReplicateOccurrence ()
 
void set_ReplicateOccurrence (unsigned int val)
 
bool get_isGenerationPeriodic ()
 
void set_isGenerationPeriodic (bool val)
 
unsigned int get_GenerationOccurrence ()
 
void set_GenerationOccurrence (unsigned int val)
 
unsigned int get_ExecRank ()
 unused yet... More...
 
void set_ExecRank (int val)
 
TMatrixget_OccMatrix ()
 
void set_OccMatrix (TMatrix *occ)
 
bool get_isMasterExec ()
 
void set_isMasterExec (bool is)
 
- Public Member Functions inherited from Handler
virtual ~Handler ()
 

Private Attributes

vector< string > _records
 

Additional Inherited Members

- Protected Attributes inherited from TraitFileHandler< TProtoQuanti >
TProtoQuanti_FHLinkedTrait
 
int _FHLinkedTraitIndex
 
- Protected Attributes inherited from FileHandler
Metapop_pop
 Pointer to the current metapop, set during initialization within the init function. More...
 

Detailed Description

Constructor & Destructor Documentation

TTQFreqExtractor::TTQFreqExtractor ( TProtoQuanti T)
inline
virtual TTQFreqExtractor::~TTQFreqExtractor ( )
inlinevirtual
333 {}

Member Function Documentation

virtual void TTQFreqExtractor::FHread ( string &  filename)
inlinevirtual

Implements TraitFileHandler< TProtoQuanti >.

335 {}
void TTQFreqExtractor::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoQuanti >.

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, _records, ADLTx, tstring::dble2str(), fatal(), FEM, Patch::get(), TProtoQuanti::get_allele_values(), FileHandler::get_extension(), FileHandler::get_GenerationOccurrence(), TProtoQuanti::get_nb_locus(), TProtoQuanti::get_nb_traits(), FileHandler::get_path(), FileHandler::get_pop_ptr(), TTrait::get_sequence(), FileHandler::get_service(), Metapop::getCurrentGeneration(), Metapop::getGenerations(), Metapop::getPatch(), Metapop::getPatchNbr(), FileServices::getReplicateFileName(), Individual::getTrait(), tstring::int2str(), MAL, resetTable(), and Patch::size().

2130 {
2131 
2132  Metapop* pop = get_pop_ptr();
2133  int patchNbr = pop->getPatchNbr();
2134  Patch* current_patch;
2135  Individual* ind;
2136 // TTQuanti* trait;
2137 // double* Tval;
2138  double **genes;
2139  int total_size = 0;
2140 
2141  double *snp_tab;
2142 // double *snp_tab2;
2143 
2144  double **snp_allele = _FHLinkedTrait->get_allele_values();
2145 
2146 
2147  unsigned int loc, rec;
2148  unsigned int nb_trait = _FHLinkedTrait->get_nb_traits();
2149  unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
2150 
2151 
2152  snp_tab = new double [ (nb_trait * nb_locus) ];
2153 
2154 // snp_allele = new double [ (nb_trait * nb_locus)];
2155 
2156 
2157  ostringstream REC;
2158  string current;
2159 
2160  //first generation to record, build the record table;
2161 
2162  if(pop->getCurrentGeneration() == this->get_GenerationOccurrence() ||
2163  pop->getCurrentGeneration() == 1) {
2164 
2165  resetTable();
2166 
2167  //create header
2168  _records.push_back("pop trait locus allele g" + tstring::int2str(pop->getCurrentGeneration()));
2169 
2170  rec = 1;
2171  for(int i = 0; i < patchNbr; i++)
2172  for(unsigned int k = 0; k < nb_trait; k++) {
2173  for(unsigned int l = 0; l < nb_locus; l++) {
2174 
2175  REC<<i+1<<" "<<k+1<<" "<<l+1<<" "<<snp_allele[l][0]; //only '+' or 'A' allele
2176 
2177  _records.push_back(REC.str());
2178 
2179  REC.str("");
2180 
2181  }
2182  }
2183 
2184  } else { //add a 'column' for each generation recorded
2185 
2186  current = _records[0];
2187 
2188  _records[0] = current + " g" + tstring::int2str(pop->getCurrentGeneration());
2189  }
2190 
2191 
2192  //ONLY IMPLEMENTED FOR DIALLELIC LOCI!
2193 
2194  rec = 1;
2195  for(int i = 0; i < patchNbr; i++) {
2196 
2197 
2198  current_patch = pop->getPatch(i);
2199 
2200  // fill the SNP_alleles with the first individual's haplotype, for comparison purposes:
2201 // ind = current_patch->get(FEM, ADLTx, 0);
2202 // genes = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
2203 
2204  for(unsigned int k = 0; k < nb_trait; k++) {
2205  for(unsigned int l = 0; l < nb_locus; l++) {
2206  loc = l * nb_trait + k;
2207  snp_tab [loc] = 0;
2208  }
2209  }
2210 
2211  total_size = 0;
2212  total_size += current_patch->size(FEM, ADLTx);
2213  total_size += current_patch->size(MAL, ADLTx);
2214 
2215 
2216  for(unsigned int j = 0, size = current_patch->size(FEM, ADLTx); j < size; j++) {
2217 
2218  ind = current_patch->get(FEM, ADLTx, j);
2219 
2220  genes = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
2221 
2222 
2223  for(unsigned int k = 0; k < nb_trait; k++) {
2224  for(unsigned int l = 0; l < nb_locus; l++) {
2225  loc = l * nb_trait + k;
2226 
2227  if (genes[0][loc] == snp_allele[l][0]){
2228  snp_tab [loc] += 1;
2229  }
2230 
2231  if (genes[1][loc] == snp_allele[l][0]){
2232  snp_tab [loc] += 1;
2233  }
2234 
2235  }
2236  }
2237 
2238 
2239  }
2240 
2241 
2242  for(unsigned int j = 0, size = current_patch->size(MAL, ADLTx); j < size; j++) {
2243 
2244  ind = current_patch->get(MAL, ADLTx, j);
2245 
2246  genes = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
2247 
2248  for(unsigned int k = 0; k < nb_trait; k++) {
2249  for(unsigned int l = 0; l < nb_locus; l++) {
2250  loc = l * nb_trait + k;
2251 
2252  if (genes[0][loc] == snp_allele[l][0]){
2253  snp_tab [loc] += 1;
2254  }
2255  if (genes[1][loc] == snp_allele[l][0]){
2256  snp_tab [loc] += 1;
2257  }
2258  }
2259  }
2260 
2261 
2262  }
2263 
2264  //calculate and record frequencies
2265  for(unsigned int k = 0; k < nb_trait; k++) {
2266  for(unsigned int l = 0; l < nb_locus; l++) {
2267 
2268  loc = l * nb_trait + k;
2269  //rec = i*nb_trait*nb_locus + k*nb_locus + l;
2270 
2271  assert(rec < _records.size());
2272 
2273  current = _records[ rec ];
2274 
2275  _records[ rec ] = _records[ rec ] + " " + tstring::dble2str( (snp_tab[loc] / (2 * total_size)) );
2276 
2277  rec++;
2278  }
2279  }
2280  }
2281 
2282 
2283  delete [] snp_tab;
2284 
2285  if(pop->getCurrentGeneration() == pop->getGenerations() ) { //have we reached the last generation?
2286 
2287  std::string filename = get_path() + get_service()->getReplicateFileName() + get_extension();
2288  std::ofstream FILE ;
2289 
2290  //open for writing
2291  FILE.open(filename.c_str(), ios::out);
2292 
2293  if(!FILE) fatal("Trait quanti could not open output file: \"%s\"\n",filename.c_str());
2294 
2295  for(unsigned int i = 0; i < _records.size(); ++i)
2296  FILE<<_records[i]<<endl;
2297 
2298  FILE.close();
2299  }
2300 }
TProtoQuanti * _FHLinkedTrait
Definition: filehandler.h:219
void resetTable()
Definition: ttquanti.cc:2122
unsigned int get_nb_traits()
Definition: ttquanti.h:155
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
unsigned int getCurrentGeneration()
Definition: metapop.h:286
std::string & get_extension()
Definition: filehandler.h:143
void fatal(const char *str,...)
Definition: output.cc:90
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
unsigned int getPatchNbr()
Definition: metapop.h:270
string & getReplicateFileName()
Accessor to the current replicate file name.
Definition: fileservices.cc:209
Definition: types.h:42
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:95
double ** get_allele_values() const
Definition: ttquanti.h:162
Metapop * get_pop_ptr()
Returns the pointer to the current metapop through the FileServices interface.
Definition: filehandler.h:131
virtual void ** get_sequence() const =0
sequence accessor.
Definition: types.h:37
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:523
unsigned int get_GenerationOccurrence()
Definition: filehandler.h:162
vector< string > _records
Definition: ttquanti.h:326
std::string & get_path()
Definition: filehandler.h:139
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
Definition: types.h:37
unsigned int get_nb_locus()
Definition: ttquanti.h:156
unsigned int getGenerations()
Definition: metapop.h:267
int _FHLinkedTraitIndex
Definition: filehandler.h:220
static string dble2str(const double d)
Writes a floating-point value into a string.
Definition: tstring.h:115
void TTQFreqExtractor::resetTable ( )

References _records.

Referenced by FHwrite(), and TProtoQuanti::loadFileServices().

2123 {
2124  if(_records.size() != 0) _records.clear();
2125 }
vector< string > _records
Definition: ttquanti.h:326

Member Data Documentation

vector< string > TTQFreqExtractor::_records
private

Referenced by FHwrite(), and resetTable().


The documentation for this class was generated from the following files:

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR