Nemo  2.4.0
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
362 { }

Member Function Documentation

◆ FHread()

void TTDeletMutBitstrFH::FHread ( string &  filename)
virtual

Implements FileHandler.

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

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 >.

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

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.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR