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

TTQFreqExtractor. More...

#include <ttquanti.h>

+ Inheritance diagram for TTQFreqExtractor:
+ Collaboration diagram for TTQFreqExtractor:

Public Member Functions

 TTQFreqExtractor (TProtoQuanti *T)
 
void resetTable ()
 
virtual ~TTQFreqExtractor ()
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
- Public Member Functions inherited from TraitFileHandler< TProtoQuanti >
 TraitFileHandler (TProtoQuanti *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, TProtoQuanti *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 ()
 

Private Attributes

vector< string > _records
 

Additional Inherited Members

- Protected Attributes inherited from TraitFileHandler< TProtoQuanti >
TProtoQuanti_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

Constructor & Destructor Documentation

◆ TTQFreqExtractor()

TTQFreqExtractor::TTQFreqExtractor ( TProtoQuanti T)
inline
363: TraitFileHandler<TProtoQuanti>(T,".qfreq") {}
Template class for the trait's FileHandler.
Definition: filehandler.h:217

◆ ~TTQFreqExtractor()

virtual TTQFreqExtractor::~TTQFreqExtractor ( )
inlinevirtual
367{}

Member Function Documentation

◆ FHread()

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

Implements FileHandler.

369{}

◆ FHwrite()

void TTQFreqExtractor::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoQuanti >.

3533{
3534 // make sure we don't use a sub-sampled pop
3535 Metapop* pop = get_service()->get_pop_ptr();
3536 int patchNbr = pop->getPatchNbr();
3537 Patch* current_patch;
3538 Individual* ind;
3539 // TTQuanti* trait;
3540 // double* Tval;
3541 double **genes;
3542 int total_size = 0;
3543
3544 double *snp_tab;
3545 // double *snp_tab2;
3546
3547 double **snp_allele = _FHLinkedTrait->get_allele_values();
3548
3549
3550 unsigned int loc, rec;
3551 unsigned int nb_trait = _FHLinkedTrait->get_nb_traits();
3552 unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
3553
3554
3555 snp_tab = new double [ (nb_trait * nb_locus) ];
3556
3557 // snp_allele = new double [ (nb_trait * nb_locus)];
3558
3559
3560 ostringstream REC;
3561 string current;
3562
3563 //first generation to record, build the record table;
3564
3565 if(pop->getCurrentGeneration() == this->get_GenerationOccurrence() ||
3566 pop->getCurrentGeneration() == 1) {
3567
3568 resetTable();
3569
3570 //create header
3571 _records.push_back("pop trait locus allele g" + tstring::int2str(pop->getCurrentGeneration()));
3572
3573 rec = 1;
3574 for(int i = 0; i < patchNbr; i++)
3575 for(unsigned int k = 0; k < nb_trait; k++) {
3576 for(unsigned int l = 0; l < nb_locus; l++) {
3577
3578 REC<<i+1<<" "<<k+1<<" "<<l+1<<" "<<snp_allele[l][0]; //only '+' or 'A' allele
3579
3580 _records.push_back(REC.str());
3581
3582 REC.str("");
3583
3584 }
3585 }
3586
3587 } else { //add a 'column' for each generation recorded
3588
3589 current = _records[0];
3590
3591 _records[0] = current + " g" + tstring::int2str(pop->getCurrentGeneration());
3592 }
3593
3594
3595 //ONLY IMPLEMENTED FOR DIALLELIC LOCI!
3596
3597 rec = 1;
3598 for(int i = 0; i < patchNbr; i++) {
3599
3600
3601 current_patch = pop->getPatch(i);
3602
3603 // fill the SNP_alleles with the first individual's haplotype, for comparison purposes:
3604 // ind = current_patch->get(FEM, ADLTx, 0);
3605 // genes = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
3606
3607 for(unsigned int k = 0; k < nb_trait; k++) {
3608 for(unsigned int l = 0; l < nb_locus; l++) {
3609 loc = l * nb_trait + k;
3610 snp_tab [loc] = 0;
3611 }
3612 }
3613
3614 total_size = current_patch->size(FEM, ADLTx) + current_patch->size(MAL, ADLTx);
3615
3616
3617 for(unsigned int j = 0, size = current_patch->size(FEM, ADLTx); j < size; j++) {
3618
3619 ind = current_patch->get(FEM, ADLTx, j);
3620
3621 genes = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
3622
3623
3624 for(unsigned int k = 0; k < nb_trait; k++) {
3625 for(unsigned int l = 0; l < nb_locus; l++) {
3626 loc = l * nb_trait + k;
3627
3628 if (genes[0][loc] == snp_allele[l][0]){
3629 snp_tab [loc] += 1;
3630 }
3631
3632 if (genes[1][loc] == snp_allele[l][0]){
3633 snp_tab [loc] += 1;
3634 }
3635
3636 }
3637 }
3638
3639
3640 }
3641
3642
3643 for(unsigned int j = 0, size = current_patch->size(MAL, ADLTx); j < size; j++) {
3644
3645 ind = current_patch->get(MAL, ADLTx, j);
3646
3647 genes = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
3648
3649 for(unsigned int k = 0; k < nb_trait; k++) {
3650 for(unsigned int l = 0; l < nb_locus; l++) {
3651 loc = l * nb_trait + k;
3652
3653 if (genes[0][loc] == snp_allele[l][0]){
3654 snp_tab [loc] += 1;
3655 }
3656 if (genes[1][loc] == snp_allele[l][0]){
3657 snp_tab [loc] += 1;
3658 }
3659 }
3660 }
3661
3662
3663 }
3664
3665 //calculate and record frequencies
3666 for(unsigned int k = 0; k < nb_trait; k++) {
3667 for(unsigned int l = 0; l < nb_locus; l++) {
3668
3669 loc = l * nb_trait + k;
3670 //rec = i*nb_trait*nb_locus + k*nb_locus + l;
3671
3672 assert(rec < _records.size());
3673
3674 current = _records[ rec ];
3675
3676 _records[ rec ] = _records[ rec ] + " " + tstring::dble2str( (snp_tab[loc] / (2 * total_size)) );
3677
3678 rec++;
3679 }
3680 }
3681 }
3682
3683
3684 delete [] snp_tab;
3685
3686 if(pop->getCurrentGeneration() == pop->getGenerations() ) { //have we reached the last generation?
3687
3688 std::string filename = get_path() + get_service()->getReplicateFileName() + get_extension();
3689 std::ofstream FILE ;
3690
3691 //open for writing
3692 FILE.open(filename.c_str(), ios::out);
3693
3694 if(!FILE) fatal("Trait quanti could not open output file: \"%s\"\n",filename.c_str());
3695
3696 for(unsigned int i = 0; i < _records.size(); ++i)
3697 FILE<<_records[i]<<endl;
3698
3699 FILE.close();
3700 }
3701}
std::string & get_extension()
Definition: filehandler.h:143
std::string & get_path()
Definition: filehandler.h:139
unsigned int get_GenerationOccurrence()
Definition: filehandler.h:162
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
string & getReplicateFileName()
Accessor to the current replicate file name.
Definition: fileservices.cc:381
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:111
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:80
unsigned int getGenerations()
Definition: metapop.h:273
unsigned int getPatchNbr()
Definition: metapop.h:276
unsigned int getCurrentGeneration()
Definition: metapop.h:294
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
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
unsigned int get_nb_locus()
Definition: ttquanti.h:122
unsigned int get_nb_traits()
Definition: ttquanti.h:121
double ** get_allele_values() const
Definition: ttquanti.h:131
vector< string > _records
Definition: ttquanti.h:360
void resetTable()
Definition: ttquanti.cc:3525
virtual void ** get_sequence() const =0
sequence accessor.
int _FHLinkedTraitIndex
Definition: filehandler.h:220
TProtoQuanti * _FHLinkedTrait
Definition: filehandler.h:219
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:95
static string dble2str(const double d)
Writes a floating-point value into a string.
Definition: tstring.h:115
void fatal(const char *str,...)
Definition: output.cc:96
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37
@ ADLTx
Definition: types.h:42

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, _records, ADLTx, tstring::dble2str(), fatal(), FEM, Patch::get(), TProtoQuanti::get_allele_values(), FileHandler::get_extension(), FileHandler::get_GenerationOccurrence(), TProtoQuanti::get_nb_locus(), TProtoQuanti::get_nb_traits(), FileHandler::get_path(), FileServices::get_pop_ptr(), TTrait::get_sequence(), FileHandler::get_service(), Metapop::getCurrentGeneration(), Metapop::getGenerations(), Metapop::getPatch(), Metapop::getPatchNbr(), FileServices::getReplicateFileName(), Individual::getTrait(), tstring::int2str(), MAL, resetTable(), and Patch::size().

◆ resetTable()

void TTQFreqExtractor::resetTable ( )
3526{
3527 if(_records.size() != 0) _records.clear();
3528}

References _records.

Referenced by FHwrite(), and TProtoQuanti::loadFileServices().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _records

vector< string > TTQFreqExtractor::_records
private

Referenced by FHwrite(), and resetTable().


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