Nemo  2.3.46
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 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 bool 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

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

Member Function Documentation

void TTDeletMutBitstrFH::FHread ( string &  filename)
virtual

Implements TraitFileHandler< TProtoDeletMutations_bitstring >.

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(), message(), OFFSx, bitstring::set(), TTDeletMutations_bitstring::set_sequence(), Individual::setAge(), Individual::setPedigreeClass(), Individual::show_up(), and Metapop::size().

1066 {
1067  unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
1068  unsigned int patchNbr = _pop->getPatchNbr();
1070 
1071  ifstream FILE(filename.c_str(),ios::in);
1072 
1073  if(!FILE) fatal("could not open DELET input file \"%s\"\n",filename.c_str());
1074 
1075  unsigned int genot, age, sex, ped, origin, xline = 0;
1076  int pop;
1077  age_idx agex;
1078  Individual *ind;
1079  unsigned char all0, all1;
1080  bitstring *seq[2];
1081  seq[0] = new bitstring(nb_locus);
1082  seq[1] = new bitstring(nb_locus);
1083 
1084  double* effects[2];
1085  int lnbr = 2;
1086 
1087  effects[0] = new double [nb_locus];
1088  effects[1] = new double [nb_locus];
1089 
1090  cout<<"file state: "<<FILE<<endl;
1091 
1092  string str;
1093  for (unsigned int i = 0; i < nb_locus+5; ++i) {
1094  FILE>>str;
1095  }
1096  cout<<"str: "<<str<<endl;
1097  while(FILE>>pop) {
1098  //FILE;
1099  cout<<"pop "<<pop<<endl;
1100  if(pop > (int)patchNbr)
1101  fatal("Patch number found in file exceeds number of patches in the population.\n");
1102 
1103  if(pop == -1) {
1104 
1105  for(unsigned int i = 0; i < nb_locus; ++i) {
1106  FILE>>effects[xline][i];
1107  }
1108 
1109  for(unsigned int i = 0; i < 4; ++i)
1110  FILE>>str;
1111 
1112  cout<<"read effects line "<<xline<<" last was "<<effects[xline][nb_locus-1]<<endl;
1113  xline++;
1114  }
1115  else {
1116 
1117  for(unsigned int i = 0; i < nb_locus; ++i) {
1118  FILE>>genot;
1119 
1120  all0 = (unsigned char) genot/10;
1121  all1 = (unsigned char) genot%10;
1122 
1123  if(all0 <= 2) {
1124  if(all0) seq[0]->set(i);
1125  } else {
1126  error("in DELET input file at line %i, locus %i : \
1127  first allele value %d is greater than 2!\n", lnbr, i+1, all0);
1128  fatal("Please check the input file.\n");
1129  }
1130 
1131  if(all1 <= 2){
1132  if(all1) seq[1]->set(i);
1133  } else {
1134  error("in DELET input file at line %i, locus %i : \
1135  second allele value %i is greater than 2!\n", lnbr, i+1, all1);
1136  fatal("Please check the input file.\n");
1137  }
1138  }
1139 
1140  FILE >> age >> sex >> ped >> origin;
1141 
1142  message("age %i sex %i ped %i origin %i\n", age , sex , ped , origin);
1143 
1144  agex = (age == ADULTS ? ADLTx : OFFSx);
1145 
1146  ind = _pop->makeNewIndividual(0, 0, static_cast<sex_t> (sex), origin - 1);
1147  ind->setPedigreeClass((unsigned char)ped);
1148  ind->setAge(age);
1149  trait = dynamic_cast<TTDeletMutations_bitstring*> (ind->getTrait(_FHLinkedTraitIndex));
1150  trait->set_sequence(seq);
1151 
1152  ind->show_up();
1153 
1154  _pop->getPatch(pop-1)->add(static_cast<sex_t> (sex), agex, ind);
1155  }
1156  lnbr++;
1157 
1158  }
1159  cout<<"pop size after loading: "<<_pop->size()<<endl;
1160  FILE.close();
1161 
1162  delete seq[0];
1163  delete seq[1];
1164  delete [] effects[0];
1165  delete [] effects[1];
1166 }
void message(const char *message,...)
Definition: output.cc:40
TProtoDeletMutations_bitstring * _FHLinkedTrait
Definition: filehandler.h:219
#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
void show_up()
Write some info to stdout.
Definition: individual.cc:132
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
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
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:115
void fatal(const char *str,...)
Definition: output.cc:90
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
Definition: output.cc:73
void set(size_t n)
Set a bit to 1.
Definition: bitstring.h:235
Definition: types.h:42
Bitstring implementation of TTDeletMutations with recombination.
Definition: ttdeletmutations_bitstring.h:47
Definition: types.h:42
int get_nb_locus()
Definition: ttdeletmutations_bitstring.h:188
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
void setAge(unsigned short value)
Definition: individual.h:105
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
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:540
int _FHLinkedTraitIndex
Definition: filehandler.h:220
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:103
void set_sequence(bitstring **seq)
Definition: ttdeletmutations_bitstring.cc:551
void TTDeletMutBitstrFH::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoDeletMutations_bitstring >.

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

960 {
961  if(!get_pop_ptr()->isAlive()) return;
962 
963  int nb_locus = this->_FHLinkedTrait->get_nb_locus();
964  int patchNbr = get_pop_ptr()->getPatchNbr();
965  bitstring** seq;
966  Patch* current_patch;
967  Individual *ind;
968 
969  std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + get_extension();
970 
971 #ifdef _DEBUG_
972  message("TTNeutralGenesFH::FHwrite (%s)\n",filename.c_str());
973 #endif
974 
975  ofstream FILE (filename.c_str(), ios::out);
976 
977  if(!FILE) fatal("could not open DELET output file!!\n");
978 
979  //FILE<<patchNbr<<" "<<nb_locus<<" "<<2<<" "<<1<<"\n";
980 
981  FILE<<"pop ";
982 
983  for(int i = 0; i < nb_locus; i++)
984  FILE<<"loc"<<i+1<<" ";
985 
986  FILE<<"age sex ped origin ID"<<endl;
987 
989  float *s = _FHLinkedTrait->get_s_continous();
990  float *hs = _FHLinkedTrait->get_hs_continous();
991  FILE<<"-1 ";
992  for(int i = 0; i < nb_locus; i++)
993  FILE<< s[i] << " " ;
994  FILE<<"-1 -1 -1 -1"<< endl;
995 
996  FILE<<"-1 ";
997  for(int i = 0; i < nb_locus; i++)
998  FILE<< hs[i] << " " ;
999  FILE<<"-1 -1 -1 -1"<< endl;
1000  }
1001 
1002  for (int i = 0; i < patchNbr; ++i) {
1003 
1004  current_patch = get_pop_ptr()->getPatch(i);
1005 
1006  for (unsigned int j = 0, size = current_patch->size(FEM, OFFSx); j < size; ++j) {
1007 
1008  FILE<<i+1<<" ";
1009  ind = current_patch->get(FEM, OFFSx, j);
1011 
1012  for(int k = 0; k < nb_locus; ++k)
1013  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1014 
1015  FILE << OFFSPRG << " " << FEM << " " << ind->getPedigreeClass() << " "
1016  << ind->getHome()<<" "<<ind->getID()<<endl;
1017  }
1018 
1019  for (unsigned int j = 0, size = current_patch->size(MAL, OFFSx); j < size; ++j) {
1020 
1021  FILE<<i+1<<" ";
1022  ind = current_patch->get(MAL, OFFSx, j);
1024 
1025  for(int k = 0; k < nb_locus; ++k)
1026  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1027 
1028  FILE << OFFSPRG << " " << MAL << " " << ind->getPedigreeClass() << " "
1029  << ind->getHome()<<" "<<ind->getID()<<endl;
1030  }
1031 
1032  for (unsigned int j = 0; j < current_patch->size(FEM, ADLTx); ++j) {
1033 
1034  FILE<<i+1<<" ";
1035  ind = current_patch->get(FEM, ADLTx, j);
1037 
1038  for(int k = 0; k < nb_locus; ++k)
1039  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1040 
1041  FILE << ADULTS << " " << FEM << " " << ind->getPedigreeClass() << " "
1042  << ind->getHome()<<" "<<ind->getID()<<endl;
1043  }
1044 
1045  for (unsigned int j = 0; j < current_patch->size(MAL, ADLTx); ++j) {
1046 
1047  FILE<<i+1<<" ";
1048  ind = current_patch->get(MAL, ADLTx, j);
1050 
1051  for(int k = 0; k < nb_locus; ++k)
1052  FILE<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
1053 
1054  FILE << ADULTS << " " << MAL << " " << ind->getPedigreeClass() << " "
1055  << ind->getHome()<<" "<<ind->getID()<<endl;
1056  }
1057  }
1058 
1059  FILE.close();
1060 
1061 }
float * get_s_continous()
Definition: ttdeletmutations_bitstring.h:199
void message(const char *message,...)
Definition: output.cc:40
TProtoDeletMutations_bitstring * _FHLinkedTrait
Definition: filehandler.h:219
float * get_hs_continous()
Definition: ttdeletmutations_bitstring.h:200
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
unsigned long getID()
Definition: individual.h:122
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:218
std::string & get_extension()
Definition: filehandler.h:143
void fatal(const char *str,...)
Definition: output.cc:90
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
unsigned int getPatchNbr()
Definition: metapop.h:270
Definition: types.h:42
Metapop * get_pop_ptr()
Returns the pointer to the current metapop through the FileServices interface.
Definition: filehandler.h:131
virtual void ** get_sequence() const =0
sequence accessor.
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
unsigned short getHome()
Definition: individual.h:128
Definition: types.h:37
Definition: types.h:42
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:523
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
bool get_iscontinuous()
Definition: ttdeletmutations_bitstring.h:193
int get_nb_locus()
Definition: ttdeletmutations_bitstring.h:188
std::string & get_path()
Definition: filehandler.h:139
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
Definition: types.h:37
int _FHLinkedTraitIndex
Definition: filehandler.h:220

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

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR