Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
TTDeletMutBitstrFH Class Reference

The FileHandler associated with the TTDeletMutations_bitstring trait. More...

#include <ttdeletmutations_bitstring.h>

+ Inheritance diagram for TTDeletMutBitstrFH:
+ Collaboration diagram for TTDeletMutBitstrFH:

Public Member Functions

 TTDeletMutBitstrFH (TProtoDeletMutations_bitstring *TP)
 
virtual ~TTDeletMutBitstrFH ()
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
- Public Member Functions inherited from TraitFileHandler< TProtoDeletMutations_bitstring >
 TraitFileHandler (TProtoDeletMutations_bitstring *trait_proto, const char *ext)
 
virtual ~TraitFileHandler ()
 
virtual void FHread (string &filename)=0
 
virtual void set (bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path, TProtoDeletMutations_bitstring *trait_proto)
 
virtual void set_multi (bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path, TProtoDeletMutations_bitstring *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 vector< string > 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 ()
 

Additional Inherited Members

- Protected Attributes inherited from TraitFileHandler< TProtoDeletMutations_bitstring >
TProtoDeletMutations_bitstring_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

The FileHandler associated with the TTDeletMutations_bitstring trait.

Used to save genotypes in a text file.

Constructor & Destructor Documentation

◆ TTDeletMutBitstrFH()

◆ ~TTDeletMutBitstrFH()

virtual TTDeletMutBitstrFH::~TTDeletMutBitstrFH ( )
inlinevirtual
361 { }

Member Function Documentation

◆ FHread()

void TTDeletMutBitstrFH::FHread ( string &  filename)
virtual

Implements FileHandler.

1300 {
1301  unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
1302  unsigned int patchNbr = _pop->getPatchNbr();
1304 
1305  ifstream FILE(filename.c_str(),ios::in);
1306 
1307  if(!FILE) fatal("could not open DELET input file \"%s\"\n",filename.c_str());
1308 
1309  unsigned int genot, age, sex, home, ped, isMigrant, xline = 0;
1310  unsigned long fatherID, motherID, ID;
1311  int pop;
1312  age_idx agex;
1313  Individual *ind;
1314  unsigned char all0, all1;
1315  bitstring *seq[2];
1316  seq[0] = new bitstring(nb_locus);
1317  seq[1] = new bitstring(nb_locus);
1318 
1319  double* effects[2];
1320  int lnbr = 3;
1321 
1322  effects[0] = new double [nb_locus];
1323  effects[1] = new double [nb_locus];
1324 
1325  // swallow header: pop + nb_locus loci + age sex home ped isMigrant father mother ID
1326  string str;
1327  for (unsigned int i = 0; i < nb_locus + 9; ++i) {
1328  FILE>>str;
1329  }
1330 
1331  if(!FILE)
1332  fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1333  filename.c_str(), nb_locus + 6);
1334 
1335 
1336  // read until EOF
1337  xline = 0;
1338  while(FILE>>pop) {
1339 
1340  if(pop > (int)patchNbr)
1341  fatal("Patch number found in file exceeds number of patches in the population.\n");
1342 
1343  if(pop == -1) { // this is a special row used to store mutation effects
1344  // copy the mutation effects from the input file
1345  // effects are recorded on two lines max, first is for 's', the second for 'hs'
1346 
1347  assert(xline <= 1);
1348 
1349  for(unsigned int i = 0; i < nb_locus; ++i) {
1350  FILE>>effects[xline][i];
1351  }
1352  // read last 8 columns, unused (set to -1 in the file)
1353  // format: age sex home ped isMigrant father mother ID
1354  for(unsigned int i = 0; i < 8; ++i)
1355  FILE>>str;
1356 
1357  if(!FILE)
1358  fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1359  filename.c_str(), nb_locus + 6);
1360 
1361  xline++;
1362  }
1363  else {
1364 
1365  for(unsigned int i = 0; i < nb_locus; ++i) {
1366 
1367  FILE>>genot;
1368 
1369  all0 = (unsigned char) genot/10;
1370  all1 = (unsigned char) genot%10;
1371 
1372  if(all0 <= 1) {
1373 
1374  if(all0) seq[0]->set(i);
1375 
1376  } else {
1377  error("in DELET input file at line %i, locus %i : \
1378  first allele value %d is greater than 1!\n", lnbr, i+1, all0);
1379  fatal("Please check the input file.\n");
1380  }
1381 
1382  if(all1 <= 1){
1383 
1384  if(all1) seq[1]->set(i);
1385 
1386  } else {
1387  error("in DELET input file at line %i, locus %i : \
1388  second allele value %i is greater than 1!\n", lnbr, i+1, all1);
1389  fatal("Please check the input file.\n");
1390  }
1391  }
1392 
1393  FILE >> age >> sex >> home >> ped >> isMigrant >> fatherID >> motherID >> ID;
1394 
1395  if(!FILE)
1396  fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1397  filename.c_str(), nb_locus + 9);
1398 
1399  agex = static_cast<age_idx>(age);
1400 
1401  ind = _pop->makeNewIndividual(0, 0, sex_t(sex), home);
1402  ind->setPedigreeClass((unsigned char)ped);
1403  ind->setAge(age);
1404  ind->setHome(home);
1405  trait = dynamic_cast<TTDeletMutations_bitstring*> (ind->getTrait(_FHLinkedTraitIndex));
1406  trait->set_sequence(seq); //copy the sequence
1407  trait->set_value(); //sets the hetero- and homozygosity counters
1408 
1409  _pop->getPatch(pop-1)->add(sex_t(sex), agex, ind);
1410 
1411  seq[0]->reset();
1412  seq[1]->reset();
1413 
1414  }
1415 
1416  lnbr++;
1417 
1418  }
1419 
1420  FILE.close();
1421 
1422  // set the mutation effects from the input file, but only if they have been read:
1423  if(xline == 2) {
1425 
1426  for(unsigned int i = 0; i < nb_locus; ++i) {
1427  proto->set_effect(1, i, effects[0][i]); // the order is swapt in the proto, hs first, then s
1428  proto->set_effect(0, i, effects[1][i]);
1429  }
1430  }
1431  delete seq[0];
1432  delete seq[1];
1433  delete [] effects[0];
1434  delete [] effects[1];
1435 }
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:101
Individual * makeNewIndividual(Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Creates an individual from existing pointer with new ID.
Definition: indfactory.cc:150
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:113
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:275
void setHome(unsigned short value)
Definition: individual.h:109
void setAge(unsigned short value)
Definition: individual.h:103
unsigned int getPatchNbr()
Definition: metapop.h:274
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:255
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it.
Definition: metapop.h:549
Prototype class of the bitstring-deleterious mutations trait class.
Definition: ttdeletmutations_bitstring.h:176
int get_nb_locus()
Definition: ttdeletmutations_bitstring.h:184
void set_effect(unsigned int at, unsigned int loc, float val)
Definition: ttdeletmutations_bitstring.h:202
Bitstring implementation of TTDeletMutations with recombination.
Definition: ttdeletmutations_bitstring.h:45
virtual void set_value()
Definition: ttdeletmutations_bitstring.cc:849
void set_sequence(bitstring **seq)
Definition: ttdeletmutations_bitstring.cc:670
int _FHLinkedTraitIndex
Definition: filehandler.h:222
TProtoDeletMutations_bitstring * _FHLinkedTrait
Definition: filehandler.h:221
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:53
void set(size_t n)
Set a bit to 1.
Definition: bitstring.h:332
void reset(size_t length)
Definition: bitstring.h:136
void fatal(const char *str,...)
Definition: output.cc:98
int error(const char *str,...)
Definition: output.cc:77
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:39

References TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTrait, TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTraitIndex, FileHandler::_pop, Patch::add(), error(), fatal(), TProtoDeletMutations_bitstring::get_nb_locus(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), IndFactory::makeNewIndividual(), bitstring::reset(), bitstring::set(), TProtoDeletMutations_bitstring::set_effect(), TTDeletMutations_bitstring::set_sequence(), TTDeletMutations_bitstring::set_value(), Individual::setAge(), Individual::setHome(), and Individual::setPedigreeClass().

◆ FHwrite()

void TTDeletMutBitstrFH::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoDeletMutations_bitstring >.

1186 {
1187  if(!get_pop_ptr()->isAlive()) return;
1188 
1189  // sets the pop ptr to a sub sampled pop, if sub sampling happened
1191 
1192  int nb_locus = this->_FHLinkedTrait->get_nb_locus();
1193  int patchNbr = _pop->getPatchNbr();
1194  sex_t SEX;
1195  bitstring** seq;
1196  Patch* current_patch;
1197  Individual *ind;
1198 
1199  std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + get_extension();
1200 
1201 #ifdef _DEBUG_
1202  message("TTNeutralGenesFH::FHwrite (%s)\n",filename.c_str());
1203 #endif
1204 
1205  ofstream FILE (filename.c_str(), ios::out);
1206  std::ios_base::sync_with_stdio(false); // better for writing performances
1207 
1208  if(!FILE) fatal("could not open DELET output file!!\n");
1209 
1210  //FILE<<patchNbr<<" "<<nb_locus<<" "<<2<<" "<<1<<"\n";
1211 
1212  FILE<<"pop ";
1213 
1214  for(int i = 0; i < nb_locus; i++)
1215  FILE<<"loc"<<i+1<<" ";
1216 
1217  FILE<<"age sex home ped isMigrant father mother ID\n";
1218 
1220 
1221  float *s = _FHLinkedTrait->get_s_continous();
1222 
1223  float *hs = _FHLinkedTrait->get_hs_continous();
1224 
1225  FILE<<"-1 "; //'pop'
1226 
1227  for(int i = 0; i < nb_locus; i++)
1228  FILE<< s[i] << " " ;
1229 
1230  FILE<<"-1 -1 -1 -1 -1 -1 -1 -1"<< endl; //age sex home ped isMigrant father mother ID
1231 
1232  FILE<<"-1 ";
1233 
1234  for(int i = 0; i < nb_locus; i++)
1235  FILE<< hs[i] << " " ;
1236 
1237  FILE<<"-1 -1 -1 -1 -1 -1 -1 -1"<< endl;
1238  }
1239 
1240  for (int i = 0; i < patchNbr; ++i) {
1241 
1242  current_patch = _pop->getPatch(i);
1243 
1244  for(int s = 1; s >= 0; s-- ) { // always start with females
1245 
1246  SEX = sex_t(s);
1247 
1248  for (unsigned int j = 0, size = current_patch->size(SEX, OFFSx); j < size; ++j) {
1249 
1250 
1251  FILE<<i+1<<" ";
1252  ind = current_patch->get(SEX, OFFSx, j);
1254 
1255  for(int k = 0; k < nb_locus; ++k)
1256  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1257 
1258  FILE << OFFSx<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
1259  << (ind->getFather() && ind->getMother() ?
1260  (ind->getFather()->getHome()!= current_patch->getID() ) + (ind->getMother()->getHome()!= current_patch->getID() ) : 0)
1261  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
1262  }
1263  }
1264 
1265 
1266  for(int s = 1; s >= 0; s-- ) {
1267 
1268  SEX = sex_t(s);
1269 
1270  for (unsigned int j = 0, size = current_patch->size(SEX, ADLTx); j < size; ++j) {
1271 
1272 
1273  FILE<<i+1<<" ";
1274  ind = current_patch->get(SEX, ADLTx, j);
1276 
1277  for(int k = 0; k < nb_locus; ++k)
1278  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1279 
1280  FILE << ADLTx <<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
1281  << (ind->getFather() && ind->getMother() ?
1282  (ind->getFather()->getHome()!= current_patch->getID() ) + (ind->getMother()->getHome()!= current_patch->getID() ) : 0)
1283  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
1284  }
1285  }
1286 
1287  }
1288 
1289  FILE.close();
1290 
1291  std::ios_base::sync_with_stdio(true); // reset
1292 
1293  // reset to pop ptr to main pop:
1294  _pop = get_service()->get_pop_ptr();
1295 }
std::string & get_path()
Definition: filehandler.h:141
Metapop * get_pop_ptr()
Returns the pointer to the current metapop through the FileServices interface.
Definition: filehandler.h:133
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:137
std::string & get_extension()
Definition: filehandler.h:145
Metapop * getSampledPop()
Sets the down-sampled population and provides accessor to file handlers.
Definition: fileservices.cc:196
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:465
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:111
unsigned long getID()
Definition: individual.h:120
unsigned short getHome()
Definition: individual.h:126
Individual * getMother()
Definition: individual.h:125
unsigned long getMotherID()
Definition: individual.h:123
Individual * getFather()
Definition: individual.h:124
sex_t getSex()
Definition: individual.h:127
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:177
unsigned long getFatherID()
Definition: individual.h:122
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:496
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:532
unsigned int getID()
Definition: metapop.h:479
float * get_hs_continous()
Definition: ttdeletmutations_bitstring.h:194
float * get_s_continous()
Definition: ttdeletmutations_bitstring.h:193
bool get_iscontinuous()
Definition: ttdeletmutations_bitstring.h:190
virtual void ** get_sequence() const =0
sequence accessor.
void message(const char *message,...)
Definition: output.cc:38
@ OFFSx
Definition: types.h:40
@ ADLTx
Definition: types.h:40

References TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTrait, TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTraitIndex, FileHandler::_pop, ADLTx, fatal(), Patch::get(), FileHandler::get_extension(), TProtoDeletMutations_bitstring::get_hs_continous(), TProtoDeletMutations_bitstring::get_iscontinuous(), TProtoDeletMutations_bitstring::get_nb_locus(), FileHandler::get_path(), FileHandler::get_pop_ptr(), FileServices::get_pop_ptr(), TProtoDeletMutations_bitstring::get_s_continous(), TTrait::get_sequence(), FileHandler::get_service(), Individual::getFather(), Individual::getFatherID(), FileServices::getGenerationReplicateFileName(), Individual::getHome(), Individual::getID(), Patch::getID(), Individual::getMother(), Individual::getMotherID(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getPedigreeClass(), FileServices::getSampledPop(), Individual::getSex(), Individual::getTrait(), message(), OFFSx, and Patch::size().


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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR