Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
FHPedigreeReader Class Reference

A class to read a pedigree from a file. More...

#include <LCEmisc.h>

+ Inheritance diagram for FHPedigreeReader:
+ Collaboration diagram for FHPedigreeReader:

Public Member Functions

 FHPedigreeReader (LCE_Cross *event)
 
virtual ~FHPedigreeReader ()
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
vector< unsigned long * > & getPedigree ()
 
- Public Member Functions inherited from EventFileHandler< LCE_Cross >
 EventFileHandler (LCE_Cross *event, const char *ext)
 
virtual ~EventFileHandler ()
 
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, LCE_Cross *event)
 
- 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 ()
 

Private Attributes

vector< unsigned long * > _pedigree
 

Additional Inherited Members

- Protected Attributes inherited from EventFileHandler< LCE_Cross >
LCE_Cross_FHLinkedEvent
 
- Protected Attributes inherited from FileHandler
Metapop_pop
 Pointer to the current metapop, set during initialization within the init function. More...
 

Detailed Description

A class to read a pedigree from a file.

Constructor & Destructor Documentation

◆ FHPedigreeReader()

FHPedigreeReader::FHPedigreeReader ( LCE_Cross event)
721  :
722  EventFileHandler< LCE_Cross > (event, ".ped")
723 {
724 
725 }

◆ ~FHPedigreeReader()

virtual FHPedigreeReader::~FHPedigreeReader ( )
inlinevirtual
204 {}

Member Function Documentation

◆ FHread()

void FHPedigreeReader::FHread ( string &  filename)
virtual

Implements FileHandler.

727 {
728  ifstream FILE(filename.c_str(),ios::in);
729 
730  if(!FILE) fatal("could not open pedigree input file \"%s\"\n",filename.c_str());
731 
732  string ID, sire, dam;
733 
734  unsigned int line = 0;
735 
736  unsigned long * record = 0;
737 
738  _pedigree.clear();
739 
740  message("\n++++ reading pedigree file: %s\n",filename.c_str());
741 
742  while(FILE){
743 
744  line++;
745 
746  FILE >> ID >> sire >> dam;
747 
748  if(!FILE || FILE.eof()) break;
749 
750  record = new unsigned long [3];
751 
752  if(tstring::isanumber(ID)) record[0] = tstring::str2ulong(ID);
753  else if(tstring::isNA(ID)) record[0] = 0;
754  else {
755  error("%s: ID on line %i is not a number\n",filename.c_str(),line);
756  delete [] record; record = 0;
757  continue;
758  }
759 
760  if(tstring::isanumber(sire)) record[1] = tstring::str2ulong(sire);
761  else if(tstring::isNA(sire)) record[1] = 0;
762  else {
763  error("%s: 'sire' on line %i is not a number\n",filename.c_str(),line);
764  delete [] record; record = 0;
765  continue;
766  }
767 
768  if(tstring::isanumber(dam)) record[2] = tstring::str2ulong(dam);
769  else if(tstring::isNA(dam)) record[2] = 0;
770  else {
771  error("%s: 'dam' on line %i is not a number\n",filename.c_str(),line);
772  delete [] record; record = 0;
773  continue;
774  }
775 // cout<<line<<": "<<ID<<" "<<sire<<" "<<dam<<endl;
776 
777  _pedigree.push_back(record);
778  }
779 
780  if(FILE) FILE.close();
781 
782  message("++++ pedigree has %i valid records\n", _pedigree.size());
783 }
vector< unsigned long * > _pedigree
Definition: LCEmisc.h:212
static unsigned long str2ulong(const string &str)
Converts a string into an unsigned integer.
Definition: tstring.h:60
static bool isNA(const string &str)
Check whether the string is NA | NaN.
Definition: tstring.h:424
static bool isanumber(const string &str)
Check whether the string is a number.
Definition: tstring.h:408
void fatal(const char *str,...)
Definition: output.cc:98
int error(const char *str,...)
Definition: output.cc:77
void message(const char *message,...)
Definition: output.cc:38

References _pedigree, error(), fatal(), tstring::isanumber(), tstring::isNA(), message(), and tstring::str2ulong().

Referenced by LCE_Cross::generatePedigree().

+ Here is the caller graph for this function:

◆ FHwrite()

virtual void FHPedigreeReader::FHwrite ( )
inlinevirtual

Implements EventFileHandler< LCE_Cross >.

206 {}

◆ getPedigree()

vector< unsigned long * >& FHPedigreeReader::getPedigree ( )
inline
209 {return _pedigree;}

References _pedigree.

Referenced by LCE_Cross::generatePedigree().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _pedigree

vector< unsigned long * > FHPedigreeReader::_pedigree
private

Referenced by FHread(), and getPedigree().


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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR