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

Member Function Documentation

◆ FHread()

void TTDeletMutBitstrFH::FHread ( string &  filename)
virtual

Implements FileHandler.

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

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

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

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

Locations of visitors to this page
Catalogued on GSR