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
350 { }

Member Function Documentation

◆ FHread()

void TTDeletMutBitstrFH::FHread ( string &  filename)
virtual

Implements FileHandler.

1215 {
1216  unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
1217  unsigned int patchNbr = _pop->getPatchNbr();
1219 
1220  ifstream FILE(filename.c_str(),ios::in);
1221 
1222  if(!FILE) fatal("could not open DELET input file \"%s\"\n",filename.c_str());
1223 
1224  unsigned int genot, age, sex, ped, origin, xline = 0;
1225  unsigned long ID;
1226  int pop;
1227  age_idx agex;
1228  Individual *ind;
1229  unsigned char all0, all1;
1230  bitstring *seq[2];
1231  seq[0] = new bitstring(nb_locus);
1232  seq[1] = new bitstring(nb_locus);
1233 
1234  double* effects[2];
1235  int lnbr = 3;
1236 
1237  effects[0] = new double [nb_locus];
1238  effects[1] = new double [nb_locus];
1239 
1240  string str; // swallow header line, read pop + num locus + 5 info fields
1241  for (unsigned int i = 0; i < nb_locus + 6; ++i) {
1242  FILE>>str;
1243  }
1244 
1245  if(!FILE)
1246  fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1247  filename.c_str(), nb_locus + 6);
1248 
1249 
1250  // read until EOF
1251  xline = 0;
1252  while(FILE>>pop) {
1253 
1254  if(pop > (int)patchNbr)
1255  fatal("Patch number found in file exceeds number of patches in the population.\n");
1256 
1257  if(pop == -1) { // this is a special row used to store mutation effects
1258  // copy the mutation effects from the input file
1259  // effects are recorded on two lines max, first is for 's', the second for 'hs'
1260 
1261  assert(xline <= 1);
1262 
1263  for(unsigned int i = 0; i < nb_locus; ++i) {
1264  FILE>>effects[xline][i];
1265  }
1266  // read last five columns, unused (set to -1 in the file)
1267  for(unsigned int i = 0; i < 5; ++i)
1268  FILE>>str;
1269 
1270  if(!FILE)
1271  fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1272  filename.c_str(), nb_locus + 6);
1273 
1274  xline++;
1275  }
1276  else {
1277 
1278  for(unsigned int i = 0; i < nb_locus; ++i) {
1279 
1280  FILE>>genot;
1281 
1282  all0 = (unsigned char) genot/10;
1283  all1 = (unsigned char) genot%10;
1284 
1285  if(all0 <= 1) {
1286 
1287  if(all0) seq[0]->set(i);
1288 
1289  } else {
1290  error("in DELET input file at line %i, locus %i : \
1291  first allele value %d is greater than 1!\n", lnbr, i+1, all0);
1292  fatal("Please check the input file.\n");
1293  }
1294 
1295  if(all1 <= 1){
1296 
1297  if(all1) seq[1]->set(i);
1298 
1299  } else {
1300  error("in DELET input file at line %i, locus %i : \
1301  second allele value %i is greater than 1!\n", lnbr, i+1, all1);
1302  fatal("Please check the input file.\n");
1303  }
1304  }
1305 
1306  FILE >> age >> sex >> ped >> origin >> ID;
1307 
1308  if(!FILE)
1309  fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1310  filename.c_str(), nb_locus + 6);
1311 
1312  agex = (age == ADULTS ? ADLTx : OFFSx);
1313 
1314  ind = _pop->makeNewIndividual(0, 0, sex_t(sex), origin);
1315  ind->setPedigreeClass((unsigned char)ped);
1316  ind->setAge(age);
1317  ind->setHome(origin);
1318  trait = dynamic_cast<TTDeletMutations_bitstring*> (ind->getTrait(_FHLinkedTraitIndex));
1319  trait->set_sequence(seq); //copy the sequence
1320  trait->set_value(); //sets the hetero- and homozygosity counters
1321 
1322  _pop->getPatch(pop-1)->add(sex_t(sex), agex, ind);
1323 
1324  seq[0]->reset();
1325  seq[1]->reset();
1326 
1327  }
1328 
1329  lnbr++;
1330 
1331  }
1332 
1333  FILE.close();
1334 
1335  // set the mutation effects from the input file, but only if they have been read:
1336  if(xline == 2) {
1338 
1339  for(unsigned int i = 0; i < nb_locus; ++i) {
1340  proto->set_effect(1, i, effects[0][i]); // the order is swapt in the proto, hs first, then s
1341  proto->set_effect(0, i, effects[1][i]);
1342  }
1343  }
1344  delete seq[0];
1345  delete seq[1];
1346  delete [] effects[0];
1347  delete [] effects[1];
1348 }
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:103
Individual * makeNewIndividual(Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Creates an individual with pointers to parents, sex and home ID set but no genetic data.
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:171
int get_nb_locus()
Definition: ttdeletmutations_bitstring.h:179
void set_effect(unsigned int at, unsigned int loc, float val)
Definition: ttdeletmutations_bitstring.h:197
Bitstring implementation of TTDeletMutations with recombination.
Definition: ttdeletmutations_bitstring.h:47
virtual void set_value()
Definition: ttdeletmutations_bitstring.cc:825
void set_sequence(bitstring **seq)
Definition: ttdeletmutations_bitstring.cc:653
int _FHLinkedTraitIndex
Definition: filehandler.h:220
TProtoDeletMutations_bitstring * _FHLinkedTrait
Definition: filehandler.h:219
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:256
void reset(size_t length)
Definition: bitstring.h:140
void fatal(const char *str,...)
Definition: output.cc:96
int error(const char *str,...)
Definition: output.cc:77
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTrait, TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTraitIndex, FileHandler::_pop, Patch::add(), ADLTx, ADULTS, error(), fatal(), TProtoDeletMutations_bitstring::get_nb_locus(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), IndFactory::makeNewIndividual(), OFFSx, 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 >.

1104 {
1105  if(!get_pop_ptr()->isAlive()) return;
1106 
1107  // sets the pop ptr to a sub sampled pop, if sub sampling happened
1109 
1110  int nb_locus = this->_FHLinkedTrait->get_nb_locus();
1111  int patchNbr = _pop->getPatchNbr();
1112  sex_t SEX;
1113  bitstring** seq;
1114  Patch* current_patch;
1115  Individual *ind;
1116 
1117  std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + get_extension();
1118 
1119 #ifdef _DEBUG_
1120  message("TTNeutralGenesFH::FHwrite (%s)\n",filename.c_str());
1121 #endif
1122 
1123  ofstream FILE (filename.c_str(), ios::out);
1124 
1125  if(!FILE) fatal("could not open DELET output file!!\n");
1126 
1127  //FILE<<patchNbr<<" "<<nb_locus<<" "<<2<<" "<<1<<"\n";
1128 
1129  FILE<<"pop ";
1130 
1131  for(int i = 0; i < nb_locus; i++)
1132  FILE<<"loc"<<i+1<<" ";
1133 
1134  FILE<<"age sex home ped isMigrant father mother ID\n";
1135 
1137 
1138  float *s = _FHLinkedTrait->get_s_continous();
1139 
1140  float *hs = _FHLinkedTrait->get_hs_continous();
1141 
1142  FILE<<"-1 "; //'pop'
1143 
1144  for(int i = 0; i < nb_locus; i++)
1145  FILE<< s[i] << " " ;
1146 
1147  FILE<<"-1 -1 -1 -1 -1 -1 -1 -1"<< endl; //age sex home ped isMigrant father mother ID
1148 
1149  FILE<<"-1 ";
1150 
1151  for(int i = 0; i < nb_locus; i++)
1152  FILE<< hs[i] << " " ;
1153 
1154  FILE<<"-1 -1 -1 -1 -1 -1 -1 -1"<< endl;
1155  }
1156 
1157  for (int i = 0; i < patchNbr; ++i) {
1158 
1159  current_patch = _pop->getPatch(i);
1160 
1161  for(int s = 1; s >= 0; s-- ) { // always start with females
1162 
1163  SEX = sex_t(s);
1164 
1165  for (unsigned int j = 0, size = current_patch->size(SEX, OFFSx); j < size; ++j) {
1166 
1167 
1168  FILE<<i+1<<" ";
1169  ind = current_patch->get(SEX, OFFSx, j);
1171 
1172  for(int k = 0; k < nb_locus; ++k)
1173  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1174 
1175  FILE << OFFSx<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
1176  << (ind->getFather() && ind->getMother() ?
1177  (ind->getFather()->getHome()!= current_patch->getID() ) + (ind->getMother()->getHome()!= current_patch->getID() ) : 0)
1178  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
1179  }
1180  }
1181 
1182 
1183  for(int s = 1; s >= 0; s-- ) {
1184 
1185  SEX = sex_t(s);
1186 
1187  for (unsigned int j = 0, size = current_patch->size(SEX, ADLTx); j < size; ++j) {
1188 
1189 
1190  FILE<<i+1<<" ";
1191  ind = current_patch->get(SEX, ADLTx, j);
1193 
1194  for(int k = 0; k < nb_locus; ++k)
1195  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1196 
1197  FILE << ADLTx <<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
1198  << (ind->getFather() && ind->getMother() ?
1199  (ind->getFather()->getHome()!= current_patch->getID() ) + (ind->getMother()->getHome()!= current_patch->getID() ) : 0)
1200  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
1201  }
1202  }
1203 
1204  }
1205 
1206  FILE.close();
1207 
1208  // reset to pop ptr to main pop:
1209  _pop = get_service()->get_pop_ptr();
1210 }
std::string & get_path()
Definition: filehandler.h:139
Metapop * get_pop_ptr()
Returns the pointer to the current metapop through the FileServices interface.
Definition: filehandler.h:131
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
std::string & get_extension()
Definition: filehandler.h:143
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:438
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:111
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:189
float * get_s_continous()
Definition: ttdeletmutations_bitstring.h:188
bool get_iscontinuous()
Definition: ttdeletmutations_bitstring.h:185
virtual void ** get_sequence() const =0
sequence accessor.
void message(const char *message,...)
Definition: output.cc: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.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR