Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
TTBDMI_FH Class Reference

FileHandler for the DBMI trait. More...

#include <ttbdmi.h>

+ Inheritance diagram for TTBDMI_FH:
+ Collaboration diagram for TTBDMI_FH:

Public Member Functions

 TTBDMI_FH (TProtoBDMI *TP)
 
virtual ~TTBDMI_FH ()
 
void write_haplo (Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
 
void write_diplo (Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
- Public Member Functions inherited from TraitFileHandler< TProtoBDMI >
 TraitFileHandler (TProtoBDMI *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, TProtoBDMI *trait_proto)
 
virtual void set_multi (bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path, TProtoBDMI *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< TProtoBDMI >
TProtoBDMI_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

FileHandler for the DBMI trait.

Records the complete genotype in a text file.

Constructor & Destructor Documentation

◆ TTBDMI_FH()

TTBDMI_FH::TTBDMI_FH ( TProtoBDMI TP)
inline

◆ ~TTBDMI_FH()

virtual TTBDMI_FH::~TTBDMI_FH ( )
inlinevirtual
234 { }

Member Function Documentation

◆ FHread()

virtual void TTBDMI_FH::FHread ( string &  filename)
inlinevirtual

Implements FileHandler.

240 {}

◆ FHwrite()

void TTBDMI_FH::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoBDMI >.

704 {
705  if(!_pop->isAlive()) return;
706 
707  // get sub sampled pop, if pop was sub sampled, otherwise points to main pop
709 
710  string filename = get_filename();
711 
712  ofstream FILE (filename.c_str(), ios::out);
713 
714  if(!FILE) fatal("could not open DMI output file\n");
715 
716 
717  Patch* current_patch;
718  int patchNbr = _pop->getPatchNbr();
719 
720  FILE<<"pop ";
721 
722  for(int i = 0; i < _FHLinkedTrait->get_num_locus(); i++)
723  FILE<<"loc"<<i+1<<" ";
724 
725  FILE<<"W age sex home ped isMigrant father mother ID\n";
726 
727  for (int i = 0; i < patchNbr; ++i) {
728 
729  current_patch = _pop->getPatch(i);
730 
731  if(_FHLinkedTrait->isHaploid()) {
732  write_haplo(current_patch, FEM, OFFSx, FILE);
733  write_haplo(current_patch, MAL, OFFSx, FILE);
734  write_haplo(current_patch, FEM, ADLTx, FILE);
735  write_haplo(current_patch, MAL, ADLTx, FILE);
736  } else {
737  write_diplo(current_patch, FEM, OFFSx, FILE);
738  write_diplo(current_patch, MAL, OFFSx, FILE);
739  write_diplo(current_patch, FEM, ADLTx, FILE);
740  write_diplo(current_patch, MAL, ADLTx, FILE);
741  }
742  }
743 
744  // reset main ptr to main pop
746 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:151
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:103
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:198
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:111
unsigned int getPatchNbr()
Definition: metapop.h:276
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:309
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
int get_num_locus()
Definition: ttbdmi.h:82
bool isHaploid()
Definition: ttbdmi.h:84
void write_haplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:750
void write_diplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:779
TProtoBDMI * _FHLinkedTrait
Definition: filehandler.h:219
void fatal(const char *str,...)
Definition: output.cc:96
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References TraitFileHandler< TProtoBDMI >::_FHLinkedTrait, FileHandler::_pop, ADLTx, fatal(), FEM, FileHandler::get_filename(), TProtoBDMI::get_num_locus(), FileServices::get_pop_ptr(), FileHandler::get_service(), Metapop::getPatch(), Metapop::getPatchNbr(), FileServices::getSampledPop(), Metapop::isAlive(), TProtoBDMI::isHaploid(), MAL, OFFSx, write_diplo(), and write_haplo().

◆ write_diplo()

void TTBDMI_FH::write_diplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
ofstream &  FH 
)
780 {
781  const bitstring* seq;
782  Individual *ind;
783  TT_BDMI* trait;
784  for (unsigned int j = 0, size = patch->size(SEX, AGE); j < size; ++j) {
785 
786  FH<<patch->getID()+1<<" ";
787  ind = patch->get(SEX, AGE, j);
788  trait = dynamic_cast<TT_BDMI*>(ind->getTrait(_FHLinkedTraitIndex));
789  seq = trait->get_genome_sequence();
790 
791  for(int k = 0; k < _FHLinkedTrait->get_num_locus(); ++k)
792  FH<<seq[0][k]<<seq[1][k]<<" ";
793 
794  FH <<*(double*)trait->getValue()<<" "<<AGE<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
795  << (ind->getFather() && ind->getMother() ?
796  (ind->getFather()->getHome()!= patch->getID() ) + (ind->getMother()->getHome()!= patch->getID() ) : 0)
797  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
798 //
799 // << (AGE == OFFSx ? OFFSPRG : ADULTS) << " " << SEX << " "
800 // << ind->getPedigreeClass() << " " << ind->getHome()+1<<endl;
801  }
802 
803 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
unsigned long getID()
Definition: individual.h:122
unsigned short getHome()
Definition: individual.h:128
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
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
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
Definition: ttbdmi.h:141
const bitstring * get_genome_sequence() const
Definition: ttbdmi.h:188
virtual void * getValue() const
Definition: ttbdmi.h:200
int _FHLinkedTraitIndex
Definition: filehandler.h:220
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:57

References TraitFileHandler< TProtoBDMI >::_FHLinkedTrait, TraitFileHandler< TProtoBDMI >::_FHLinkedTraitIndex, Patch::get(), TT_BDMI::get_genome_sequence(), TProtoBDMI::get_num_locus(), Individual::getFather(), Individual::getFatherID(), Individual::getHome(), Individual::getID(), Patch::getID(), Individual::getMother(), Individual::getMotherID(), Individual::getPedigreeClass(), Individual::getSex(), Individual::getTrait(), TT_BDMI::getValue(), and Patch::size().

Referenced by FHwrite().

◆ write_haplo()

void TTBDMI_FH::write_haplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
ofstream &  FH 
)
751 {
752  const bitstring* seq;
753  Individual *ind;
754  TT_BDMI* trait;
755 
756  for (unsigned int j = 0, size = patch->size(SEX, AGE); j < size; ++j) {
757 
758  FH<<patch->getID()+1<<" ";
759  ind = patch->get(SEX, AGE, j);
760  trait = dynamic_cast<TT_BDMI*>(ind->getTrait(_FHLinkedTraitIndex));
761  seq = trait->get_genome_sequence();
762 
763  for(int k = 0; k < _FHLinkedTrait->get_num_locus(); ++k)
764  FH<<seq[0][k]<<" ";
765 
766  FH <<*(double*)trait->getValue()<<" "<<AGE<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
767  << (ind->getFather() && ind->getMother() ?
768  (ind->getFather()->getHome()!= patch->getID() ) + (ind->getMother()->getHome()!= patch->getID() ) : 0)
769  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
770 
771 // << (AGE == OFFSx ? OFFSPRG : ADULTS) << " " << SEX << " "
772 // << ind->getPedigreeClass() << " " << ind->getHome()+1<<endl;
773  }
774 
775 }

References TraitFileHandler< TProtoBDMI >::_FHLinkedTrait, TraitFileHandler< TProtoBDMI >::_FHLinkedTraitIndex, Patch::get(), TT_BDMI::get_genome_sequence(), TProtoBDMI::get_num_locus(), Individual::getFather(), Individual::getFatherID(), Individual::getHome(), Individual::getID(), Patch::getID(), Individual::getMother(), Individual::getMotherID(), Individual::getPedigreeClass(), Individual::getSex(), Individual::getTrait(), TT_BDMI::getValue(), and Patch::size().

Referenced by FHwrite().


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