Nemo  2.3.56
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 FHwrite ()=0
 
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)
 
- 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 FHwrite ()=0
 Default behavior of the class, called by Handler::update(). More...
 
virtual void FHread (string &filename)=0
 Default input function. More...
 
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 void init ()=0
 Inits state. More...
 
virtual void update ()=0
 Updates the handler state. More...
 
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::TTDeletMutBitstrFH ( TProtoDeletMutations_bitstring TP)
inline
Template class for the trait's FileHandler.
Definition: filehandler.h:217

◆ ~TTDeletMutBitstrFH()

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

Member Function Documentation

◆ FHread()

void TTDeletMutBitstrFH::FHread ( string &  filename)
virtual

Implements FileHandler.

1228{
1229 unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
1230 unsigned int patchNbr = _pop->getPatchNbr();
1232
1233 ifstream FILE(filename.c_str(),ios::in);
1234
1235 if(!FILE) fatal("could not open DELET input file \"%s\"\n",filename.c_str());
1236
1237 unsigned int genot, age, sex, ped, origin, xline = 0;
1238 unsigned long ID;
1239 int pop;
1240 age_idx agex;
1241 Individual *ind;
1242 unsigned char all0, all1;
1243 bitstring *seq[2];
1244 seq[0] = new bitstring(nb_locus);
1245 seq[1] = new bitstring(nb_locus);
1246
1247 double* effects[2];
1248 int lnbr = 3;
1249
1250 effects[0] = new double [nb_locus];
1251 effects[1] = new double [nb_locus];
1252
1253 string str; // swallow header line, read pop + num locus + 5 info fields
1254 for (unsigned int i = 0; i < nb_locus + 6; ++i) {
1255 FILE>>str;
1256 }
1257
1258 if(!FILE)
1259 fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1260 filename.c_str(), nb_locus + 6);
1261
1262
1263 // read until EOF
1264 xline = 0;
1265 while(FILE>>pop) {
1266
1267 if(pop > (int)patchNbr)
1268 fatal("Patch number found in file exceeds number of patches in the population.\n");
1269
1270 if(pop == -1) { // this is a special row used to store mutation effects
1271 // copy the mutation effects from the input file
1272 // effects are recorded on two lines max, first is for 's', the second for 'hs'
1273
1274 assert(xline <= 1);
1275
1276 for(unsigned int i = 0; i < nb_locus; ++i) {
1277 FILE>>effects[xline][i];
1278 }
1279 // read last five columns, unused (set to -1 in the file)
1280 for(unsigned int i = 0; i < 5; ++i)
1281 FILE>>str;
1282
1283 if(!FILE)
1284 fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1285 filename.c_str(), nb_locus + 6);
1286
1287 xline++;
1288 }
1289 else {
1290
1291 for(unsigned int i = 0; i < nb_locus; ++i) {
1292
1293 FILE>>genot;
1294
1295 all0 = (unsigned char) genot/10;
1296 all1 = (unsigned char) genot%10;
1297
1298 if(all0 <= 1) {
1299
1300 if(all0) seq[0]->set(i);
1301
1302 } else {
1303 error("in DELET input file at line %i, locus %i : \
1304 first allele value %d is greater than 1!\n", lnbr, i+1, all0);
1305 fatal("Please check the input file.\n");
1306 }
1307
1308 if(all1 <= 1){
1309
1310 if(all1) seq[1]->set(i);
1311
1312 } else {
1313 error("in DELET input file at line %i, locus %i : \
1314 second allele value %i is greater than 1!\n", lnbr, i+1, all1);
1315 fatal("Please check the input file.\n");
1316 }
1317 }
1318
1319 FILE >> age >> sex >> ped >> origin >> ID;
1320
1321 if(!FILE)
1322 fatal("reading delet genotypes from \"%s\" failed (expecting %i elements per line)\n",
1323 filename.c_str(), nb_locus + 6);
1324
1325 agex = (age == ADULTS ? ADLTx : OFFSx);
1326
1327 ind = _pop->makeNewIndividual(0, 0, sex_t(sex), origin);
1328 ind->setPedigreeClass((unsigned char)ped);
1329 ind->setAge(age);
1330 ind->setHome(origin);
1331 trait = dynamic_cast<TTDeletMutations_bitstring*> (ind->getTrait(_FHLinkedTraitIndex));
1332 trait->set_sequence(seq); //copy the sequence
1333 trait->set_value(); //sets the hetero- and homozygosity counters
1334
1335 _pop->getPatch(pop-1)->add(sex_t(sex), agex, ind);
1336
1337 seq[0]->reset();
1338 seq[1]->reset();
1339
1340 }
1341
1342 lnbr++;
1343
1344 }
1345
1346 FILE.close();
1347
1348 // set the mutation effects from the input file, but only if they have been read:
1349 if(xline == 2) {
1351
1352 for(unsigned int i = 0; i < nb_locus; ++i) {
1353 proto->set_effect(1, i, effects[0][i]); // the order is swapt in the proto, hs first, then s
1354 proto->set_effect(0, i, effects[1][i]);
1355 }
1356 }
1357 delete seq[0];
1358 delete seq[1];
1359 delete [] effects[0];
1360 delete [] effects[1];
1361}
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:549
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:842
void set_sequence(bitstring **seq)
Definition: ttdeletmutations_bitstring.cc:670
int _FHLinkedTraitIndex
Definition: filehandler.h:220
TProtoDeletMutations_bitstring * _FHLinkedTrait
Definition: filehandler.h:219
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56
void reset()
Set all bits to 0.
Definition: bitstring.h:256
void set(size_t n)
Set a bit to 1.
Definition: bitstring.h:240
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 >.

1121{
1122 if(!get_pop_ptr()->isAlive()) return;
1123
1124 // sets the pop ptr to a sub sampled pop, if sub sampling happened
1126
1127 int nb_locus = this->_FHLinkedTrait->get_nb_locus();
1128 int patchNbr = _pop->getPatchNbr();
1129 sex_t SEX;
1130 bitstring** seq;
1131 Patch* current_patch;
1132 Individual *ind;
1133
1134 std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + get_extension();
1135
1136#ifdef _DEBUG_
1137 message("TTNeutralGenesFH::FHwrite (%s)\n",filename.c_str());
1138#endif
1139
1140 ofstream FILE (filename.c_str(), ios::out);
1141
1142 if(!FILE) fatal("could not open DELET output file!!\n");
1143
1144 //FILE<<patchNbr<<" "<<nb_locus<<" "<<2<<" "<<1<<"\n";
1145
1146 FILE<<"pop ";
1147
1148 for(int i = 0; i < nb_locus; i++)
1149 FILE<<"loc"<<i+1<<" ";
1150
1151 FILE<<"age sex ped origin ID"<<endl;
1152
1154
1155 float *s = _FHLinkedTrait->get_s_continous();
1156
1157 float *hs = _FHLinkedTrait->get_hs_continous();
1158
1159 FILE<<"-1 "; //'pop'
1160
1161 for(int i = 0; i < nb_locus; i++)
1162 FILE<< s[i] << " " ;
1163
1164 FILE<<"-1 -1 -1 -1 -1"<< endl; //'age' 'sex' 'ped' 'origin' 'ID'
1165
1166 FILE<<"-1 ";
1167
1168 for(int i = 0; i < nb_locus; i++)
1169 FILE<< hs[i] << " " ;
1170
1171 FILE<<"-1 -1 -1 -1 -1"<< endl;
1172 }
1173
1174 for (int i = 0; i < patchNbr; ++i) {
1175
1176 current_patch = _pop->getPatch(i);
1177
1178 for(unsigned int s=0; s < 2; ++s ) {
1179
1180 SEX = sex_t(s);
1181
1182 for (unsigned int j = 0, size = current_patch->size(SEX, OFFSx); j < size; ++j) {
1183
1184
1185 FILE<<i+1<<" ";
1186 ind = current_patch->get(SEX, OFFSx, j);
1188
1189 for(int k = 0; k < nb_locus; ++k)
1190 FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1191
1192 FILE << OFFSPRG << " " << SEX << " " << ind->getPedigreeClass() << " "
1193 << ind->getHome()<<" "<<ind->getID()<<endl;
1194 }
1195 }
1196
1197
1198 for(unsigned int s=0; s < 2; ++s ) {
1199
1200 SEX = sex_t(s);
1201
1202 for (unsigned int j = 0, size = current_patch->size(SEX, ADLTx); j < size; ++j) {
1203
1204
1205 FILE<<i+1<<" ";
1206 ind = current_patch->get(SEX, ADLTx, j);
1208
1209 for(int k = 0; k < nb_locus; ++k)
1210 FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1211
1212 FILE << ADULTS << " " << SEX << " " << ind->getPedigreeClass() << " "
1213 << ind->getHome()<<" "<<ind->getID()<<endl;
1214 }
1215 }
1216
1217 }
1218
1219 FILE.close();
1220
1221 // reset to pop ptr to main pop:
1223}
Metapop * get_pop_ptr()
Returns the pointer to the current metapop through the FileServices interface.
Definition: filehandler.h:131
std::string & get_extension()
Definition: filehandler.h:143
std::string & get_path()
Definition: filehandler.h:139
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
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:390
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
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
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
float * get_hs_continous()
Definition: ttdeletmutations_bitstring.h:189
bool get_iscontinuous()
Definition: ttdeletmutations_bitstring.h:185
float * get_s_continous()
Definition: ttdeletmutations_bitstring.h:188
virtual void ** get_sequence() const =0
sequence accessor.
void message(const char *message,...)
Definition: output.cc:40
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50

References TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTrait, TraitFileHandler< TProtoDeletMutations_bitstring >::_FHLinkedTraitIndex, FileHandler::_pop, ADLTx, ADULTS, 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(), FileServices::getGenerationReplicateFileName(), Individual::getHome(), Individual::getID(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getPedigreeClass(), FileServices::getSampledPop(), Individual::getTrait(), message(), OFFSPRG, OFFSx, and Patch::size().


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

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR