Nemo  2.3.56
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 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, 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 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< 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
248{ }

Member Function Documentation

◆ FHread()

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

Implements FileHandler.

254{}

◆ FHwrite()

void TTBDMI_FH::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoBDMI >.

588{
589 if(!_pop->isAlive()) return;
590
591 // get sub sampled pop, if pop was sub sampled, otherwise points to main pop
593
594 string filename = get_filename();
595
596 ofstream FILE (filename.c_str(), ios::out);
597
598 if(!FILE) fatal("could not open DMI output file\n");
599
600
601 Patch* current_patch;
602 int patchNbr = _pop->getPatchNbr();
603
604 FILE<<"pop ";
605
606 for(int i = 0; i < _FHLinkedTrait->get_nb_locus(); i++)
607 FILE<<"loc"<<i+1<<" ";
608
609 FILE<<"age sex ped origin"<<endl;
610
611 for (int i = 0; i < patchNbr; ++i) {
612
613 current_patch = _pop->getPatch(i);
614
616 write_haplo(current_patch, FEM, OFFSx, FILE);
617 write_haplo(current_patch, MAL, OFFSx, FILE);
618 write_haplo(current_patch, FEM, ADLTx, FILE);
619 write_haplo(current_patch, MAL, ADLTx, FILE);
620 } else {
621 write_diplo(current_patch, FEM, OFFSx, FILE);
622 write_diplo(current_patch, MAL, OFFSx, FILE);
623 write_diplo(current_patch, FEM, ADLTx, FILE);
624 write_diplo(current_patch, MAL, ADLTx, FILE);
625 }
626 }
627
628 // reset main ptr to main pop
630}
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:197
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:307
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:430
int get_nb_locus()
Definition: ttbdmi.h:77
bool isHaploid()
Definition: ttbdmi.h:79
void write_haplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:634
void write_diplo(Patch *patch, sex_t SEX, age_idx AGE, ofstream &FH)
Definition: ttbdmi.cc:655
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_nb_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 
)
656{
657 bitstring** seq;
658 Individual *ind;
659 for (unsigned int j = 0, size = patch->size(SEX, AGE); j < size; ++j) {
660
661 FH<<patch->getID()+1<<" ";
662 ind = patch->get(SEX, AGE, j);
664
665 for(int k = 0; k < _FHLinkedTrait->get_nb_locus(); ++k)
666 FH<<(int)((*seq[0])[k])<<(int)((*seq[1])[k])<<" ";
667
668 FH << (AGE == OFFSx ? OFFSPRG : ADULTS) << " " << SEX << " "
669 << ind->getPedigreeClass() << " " << ind->getHome()+1<<endl;
670 }
671
672}
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
unsigned short getHome()
Definition: individual.h:128
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
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
unsigned int getID()
Definition: metapop.h:478
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
virtual void ** get_sequence() const =0
sequence accessor.
int _FHLinkedTraitIndex
Definition: filehandler.h:220
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:56
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50

References TraitFileHandler< TProtoBDMI >::_FHLinkedTrait, TraitFileHandler< TProtoBDMI >::_FHLinkedTraitIndex, ADULTS, Patch::get(), TProtoBDMI::get_nb_locus(), TTrait::get_sequence(), Individual::getHome(), Patch::getID(), Individual::getPedigreeClass(), Individual::getTrait(), OFFSPRG, OFFSx, and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ write_haplo()

void TTBDMI_FH::write_haplo ( Patch patch,
sex_t  SEX,
age_idx  AGE,
ofstream &  FH 
)
635{
636 bitstring** seq;
637 Individual *ind;
638 for (unsigned int j = 0, size = patch->size(SEX, AGE); j < size; ++j) {
639
640 FH<<patch->getID()+1<<" ";
641 ind = patch->get(SEX, AGE, j);
643
644 for(int k = 0; k < _FHLinkedTrait->get_nb_locus(); ++k)
645 FH<<(int)((*seq[0])[k])<<" ";
646
647 FH << (AGE == OFFSx ? OFFSPRG : ADULTS) << " " << SEX << " "
648 << ind->getPedigreeClass() << " " << ind->getHome()+1<<endl;
649 }
650
651}

References TraitFileHandler< TProtoBDMI >::_FHLinkedTrait, TraitFileHandler< TProtoBDMI >::_FHLinkedTraitIndex, ADULTS, Patch::get(), TProtoBDMI::get_nb_locus(), TTrait::get_sequence(), Individual::getHome(), Patch::getID(), Individual::getPedigreeClass(), Individual::getTrait(), OFFSPRG, OFFSx, and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

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