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

TTQuantiFH. More...

#include <ttquanti.h>

+ Inheritance diagram for TTQuantiFH:
+ Collaboration diagram for TTQuantiFH:

Public Member Functions

 TTQuantiFH (TProtoQuanti *T)
 
virtual ~TTQuantiFH ()
 
void setOutputOption (string opt)
 
virtual void FHwrite ()
 
void write_TABLE ()
 
void print (ofstream &FH, sex_t SEX, age_idx Ax, unsigned int print_gene, bool print_genotype, bool print_additive_genotype)
 
void write_PLINK ()
 
void print_PLINK_PED (ofstream &FH, age_idx Ax, Patch *patch)
 
void print_PLINK_FAM (ofstream &FH, age_idx Ax, Patch *patch)
 
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

string _output_option
 

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

◆ TTQuantiFH()

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

◆ ~TTQuantiFH()

virtual TTQuantiFH::~TTQuantiFH ( )
inlinevirtual
340{}

Member Function Documentation

◆ FHread()

void TTQuantiFH::FHread ( string &  filename)
virtual

Implements FileHandler.

3435{
3436 unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
3437 unsigned int nb_trait = _FHLinkedTrait->get_nb_traits();
3438 bool has_genotype = (!_FHLinkedTrait->get_env_var().empty());
3439
3440 unsigned int patchNbr = _pop->getPatchNbr();
3441
3442 TTQuanti* trait;
3443
3444 ifstream FILE(filename.c_str(),ios::in);
3445
3446 if(!FILE) fatal("could not open QUANTI input file \"%s\"\n",filename.c_str());
3447
3448 unsigned int age, sex, ped, origin, dummy;
3449 unsigned int loc;
3450 age_idx stagex;
3451 unsigned int pop;
3452 age_idx agex;
3453 Individual *ind;
3454 double all0, all1, pheno, geno;
3455 double *seq[2];
3456 seq[0] = new double [nb_locus*nb_trait];
3457 seq[1] = new double [nb_locus*nb_trait];
3458
3459 int lnbr = 1;
3460
3461 // swallow the header
3462 FILE.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
3463
3464 string str;
3465
3466 while(FILE>>pop) {
3467
3468 if(FILE.bad()) {
3469 error("Reading input genotypes from \"%s\" failed at line %i.\n",filename.c_str(), lnbr);
3470 FILE.clear();
3471 FILE >> str;
3472 fatal("Expecting population number as first element on the line, but received this: %s \n", str.c_str());
3473 }
3474
3475 if(pop > patchNbr)
3476 fatal("Patch number found in file exceeds number of patches in the population.\n");
3477
3478 for(unsigned int k = 0; k < nb_trait; ++k) {
3479 for(unsigned int i = 0; i < nb_locus; ++i) {
3480
3481 loc = i * nb_trait + k;
3482
3483 FILE>>all0>>all1;
3484
3485 seq[0][loc] = all0;
3486 seq[1][loc] = all1;
3487 }
3488 }
3489
3490
3491 for(unsigned int k = 0; k < nb_trait; k++) {
3492 FILE >> pheno; //read phenotypic value
3493 if(has_genotype) FILE >> geno; // genotypic values, only present if trait is influenced by env. var.
3494 }
3495
3496 // read extra fields
3497 FILE >> age >> sex >> origin >> ped >> dummy >> dummy >> dummy >> dummy;
3498
3499 stagex = age_idx(age);
3500
3501 ind = _pop->makeNewIndividual(0, 0, sex_t(sex), origin - 1);
3502 ind->setPedigreeClass((unsigned char)ped);
3503 ind->setAge(age);
3504 trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
3505 trait->set_sequence((void**)seq);
3506 trait->set_value();
3507
3508 // ind->show_up();
3509
3510 _pop->getPatch(pop-1)->add(sex_t(sex), stagex, ind);
3511
3512 lnbr++;
3513 }
3514
3515
3516 FILE.close();
3517
3518 delete seq[0];
3519 delete seq[1];
3520}
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:103
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
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:115
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
void setAge(unsigned short value)
Definition: individual.h:105
unsigned int getPatchNbr()
Definition: metapop.h:276
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
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:549
vector< double > get_env_var()
Definition: ttquanti.h:124
unsigned int get_nb_locus()
Definition: ttquanti.h:122
unsigned int get_nb_traits()
Definition: ttquanti.h:121
TTQuanti.
Definition: ttquanti.h:56
virtual void set_value()
Definition: ttquanti.cc:1646
virtual void set_sequence(void **seq)
Definition: ttquanti.cc:1469
int _FHLinkedTraitIndex
Definition: filehandler.h:220
TProtoQuanti * _FHLinkedTrait
Definition: filehandler.h:219
void fatal(const char *str,...)
Definition: output.cc:96
int error(const char *str,...)
Definition: output.cc:77
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, FileHandler::_pop, Patch::add(), error(), fatal(), TProtoQuanti::get_env_var(), TProtoQuanti::get_nb_locus(), TProtoQuanti::get_nb_traits(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), IndFactory::makeNewIndividual(), TTQuanti::set_sequence(), TTQuanti::set_value(), Individual::setAge(), and Individual::setPedigreeClass().

◆ FHwrite()

void TTQuantiFH::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoQuanti >.

3002{
3003 if (!_pop->isAlive()) return;
3004
3005 if(!get_service()) fatal("link to file services not set!!\n");
3006
3007 // sets the pop ptr to a sub sampled pop, if sub sampling happened
3009
3010 if(_output_option == "PLINK" || _output_option == "plink")
3011 write_PLINK();
3012 else
3013 write_TABLE();
3014
3015
3016 // reset to pop ptr to main pop:
3018
3019}
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
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:307
void write_PLINK()
Definition: ttquanti.cc:3177
void write_TABLE()
Definition: ttquanti.cc:3023
string _output_option
Definition: ttquanti.h:336

References _output_option, FileHandler::_pop, fatal(), FileServices::get_pop_ptr(), FileHandler::get_service(), FileServices::getSampledPop(), Metapop::isAlive(), write_PLINK(), and write_TABLE().

◆ print()

void TTQuantiFH::print ( ofstream &  FH,
sex_t  SEX,
age_idx  Ax,
unsigned int  print_gene,
bool  print_genotype,
bool  print_additive_genotype 
)
3115{
3116 int patchNbr = _pop->getPatchNbr();
3117 Patch* current_patch;
3118 Individual* ind;
3119 TTQuanti* trait;
3120 double* Tval;
3121 double **genes;
3122 double **allele_values = _FHLinkedTrait->get_allele_values(); //
3123 unsigned int loc, nb_trait=_FHLinkedTrait->get_nb_traits(), nb_locus = _FHLinkedTrait->get_nb_locus();
3124
3125 for(int i = 0; i < patchNbr; i++) {
3126
3127 current_patch = _pop->getPatch(i);
3128
3129 for(unsigned int j = 0, size = current_patch->size(SEX, Ax); j < size; j++) {
3130
3131 ind = current_patch->get(SEX, Ax, j);
3132 trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
3133
3134 FH<<current_patch->getID() +1<<" ";
3135 Tval = (double*)trait->getValue();
3136
3137 if(print_gene){
3138 genes = (double**)trait->get_sequence();
3139
3140 FH.precision(6);
3141
3142 for(unsigned int k = 0; k < nb_trait; k++) {
3143 for(unsigned int l = 0; l < nb_locus; l++) {
3144 loc = l * nb_trait + k;
3145
3146 if(print_gene == 1) {
3147
3148 FH<<genes[FEM][loc]<<" "<<genes[MAL][loc]<<" ";
3149
3150 } else {
3151
3152 FH << int(genes[0][loc] != allele_values[l][0]) + int(genes[1][loc] != allele_values[l][0]) <<" ";
3153
3154 }
3155 }
3156 }
3157 }
3158
3159 FH.precision(4);
3160 for(unsigned int k = 0; k < nb_trait; k++) {
3161 FH<<Tval[k]<<" ";
3162 if(print_genotype) FH << trait->get_full_genotype(k) << " ";
3163 if(print_additive_genotype) FH << trait->get_additive_genotype(k) << " ";
3164 }
3165
3166 FH<<Ax<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
3167 << (ind->getFather() && ind->getMother() ?
3168 (ind->getFather()->getHome()!= current_patch->getID() ) + (ind->getMother()->getHome()!= current_patch->getID() ) : 0)
3169 <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
3170 }
3171 }
3172}
Individual * getFather()
Definition: individual.h:126
unsigned long getID()
Definition: individual.h:122
unsigned short getHome()
Definition: individual.h:128
Individual * getMother()
Definition: individual.h:127
unsigned long getMotherID()
Definition: individual.h:125
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
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
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
double ** get_allele_values() const
Definition: ttquanti.h:131
virtual void * getValue() const
Definition: ttquanti.h:77
virtual void ** get_sequence() const
Definition: ttquanti.h:79
double get_full_genotype(unsigned int trait)
Definition: ttquanti.cc:1671
double get_additive_genotype(unsigned int trait)
Definition: ttquanti.cc:1664
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, FileHandler::_pop, FEM, Patch::get(), TTQuanti::get_additive_genotype(), TProtoQuanti::get_allele_values(), TTQuanti::get_full_genotype(), TProtoQuanti::get_nb_locus(), TProtoQuanti::get_nb_traits(), TTQuanti::get_sequence(), Individual::getFather(), Individual::getFatherID(), Individual::getHome(), Individual::getID(), Patch::getID(), Individual::getMother(), Individual::getMotherID(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getPedigreeClass(), Individual::getSex(), Individual::getTrait(), TTQuanti::getValue(), MAL, and Patch::size().

Referenced by write_TABLE().

+ Here is the caller graph for this function:

◆ print_PLINK_FAM()

void TTQuantiFH::print_PLINK_FAM ( ofstream &  FH,
age_idx  Ax,
Patch patch 
)
3370{
3371 Individual *ind;
3372 unsigned int nb_trait = _FHLinkedTrait->get_nb_traits();
3373
3374 // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
3375 // .fam (PLINK sample information file)
3376 //
3377 // Sample information file accompanying a .bed binary genotype table.
3378 // Also generated by "--recode lgen" and "--recode rlist".
3379 //
3380 // A text file with no header line, and one line per sample with the following six fields:
3381 //
3382 // 1. Family ID ('FID')
3383 // 2. Within-family ID ('IID'; cannot be '0')
3384 // 3. Within-family ID of father ('0' if father isn't in dataset)
3385 // 4. Within-family ID of mother ('0' if mother isn't in dataset)
3386 // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
3387 // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
3388 //
3389 // If there are any numeric phenotype values other than {-9, 0, 1, 2}, the phenotype is interpreted as a
3390 // quantitative trait instead of case/control status. In this case, -9 normally still designates a missing
3391 // phenotype; use --missing-phenotype if this is problematic.
3392
3393
3394 // here, we save the phenotypic value of the first trait by default
3395 // the complete set of phenotypic values for all traits is saved in the .fam file
3396
3397 for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
3398
3399 ind = patch->get(FEM, Ax, j);
3400
3401 FH<<"fam"<< ind->getHome()+1
3402 <<" "<< ind->getID()+1
3403 <<" 0 0" //<<ind->getFatherID()<<" "<<ind->getMotherID() //not in file for adults
3404 <<" 2";
3405
3406 for(unsigned int k = 0; k < nb_trait; ++k) {
3407 FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
3408 }
3409
3410 FH <<std::endl;
3411
3412 }
3413
3414 for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
3415
3416 ind = patch->get(MAL, Ax, j);
3417
3418 FH<<"fam"<< ind->getHome()+1
3419 <<" "<< ind->getID()+1
3420 <<" 0 0" //<<ind->getFatherID()<<" "<<ind->getMotherID()
3421 <<" 1";
3422
3423 for(unsigned int k = 0; k < nb_trait; ++k) {
3424 FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
3425 }
3426
3427 FH<<std::endl;
3428
3429 }
3430}
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, FEM, Patch::get(), TProtoQuanti::get_nb_traits(), Individual::getHome(), Individual::getID(), Individual::getTraitValue(), MAL, and Patch::size().

Referenced by write_PLINK().

+ Here is the caller graph for this function:

◆ print_PLINK_PED()

void TTQuantiFH::print_PLINK_PED ( ofstream &  FH,
age_idx  Ax,
Patch patch 
)
3293{
3294 Individual *ind;
3295 double** seq;
3296 char BASE[2] = {'A','G'};
3297 double** ref_all = _FHLinkedTrait->get_allele_values();
3298 unsigned int loc;
3299 unsigned int nb_trait = _FHLinkedTrait->get_nb_traits();
3300 unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
3301
3302 // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
3303 // .fam (PLINK sample information file)
3304 //
3305 // Sample information file accompanying a .bed binary genotype table.
3306 // Also generated by "--recode lgen" and "--recode rlist".
3307 //
3308 // A text file with no header line, and one line per sample with the following six fields:
3309 //
3310 // 1. Family ID ('FID')
3311 // 2. Within-family ID ('IID'; cannot be '0')
3312 // 3. Within-family ID of father ('0' if father isn't in dataset)
3313 // 4. Within-family ID of mother ('0' if mother isn't in dataset)
3314 // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
3315 // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
3316 //
3317 // If there are any numeric phenotype values other than {-9, 0, 1, 2}, the phenotype is interpreted as a quantitative trait instead of case/control status. In this case, -9 normally still designates a missing phenotype; use --missing-phenotype if this is problematic.
3318
3319
3320 // here, we save the phenotypic value of the first trait by default
3321 // the complete set of phenotypic values for all traits is saved in the .fam file
3322
3323 for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
3324
3325 ind = patch->get(FEM, Ax, j);
3326
3327 FH<<"fam"<<ind->getHome()+1<<" "<<ind->getID()+1<<" 0 0" //<<ind->getFatherID()<<" "<<ind->getMotherID() //not in file for adults
3328 <<" 2 "<<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
3329
3330 seq = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
3331
3332 for(unsigned int k = 0; k < nb_trait; ++k) {
3333 for (unsigned int l = 0; l < nb_locus; ++l) {
3334
3335 loc = l * nb_trait + k;
3336
3337 FH<< BASE[ (seq[FEM][loc] == ref_all[l][1]) ]<<" "<< BASE[ (seq[MAL][loc] == ref_all[l][1]) ]<<" ";
3338 }
3339 }
3340
3341 FH <<std::endl;
3342
3343 }
3344
3345 for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
3346
3347 ind = patch->get(MAL, Ax, j);
3348
3349 FH<<"fam"<<ind->getHome()+1<<" "<<ind->getID()+1<<" 0 0" //<<ind->getFatherID()<<" "<<ind->getMotherID()
3350 <<" 1 "<<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
3351
3352 seq = (double**)ind->getTrait(_FHLinkedTraitIndex)->get_sequence();
3353
3354 for(unsigned int k = 0; k < nb_trait; ++k) {
3355 for (unsigned int l = 0; l < nb_locus; ++l) {
3356
3357 loc = l * nb_trait + k;
3358
3359 FH<< BASE[ (seq[FEM][loc] == ref_all[l][1]) ]<<" "<< BASE[ (seq[MAL][loc] == ref_all[l][1]) ]<<" ";
3360 }
3361 }
3362 FH<<std::endl;
3363
3364 }
3365}
virtual void ** get_sequence() const =0
sequence accessor.

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, FEM, Patch::get(), TProtoQuanti::get_allele_values(), TProtoQuanti::get_nb_locus(), TProtoQuanti::get_nb_traits(), TTrait::get_sequence(), Individual::getHome(), Individual::getID(), Individual::getTrait(), Individual::getTraitValue(), MAL, and Patch::size().

Referenced by write_PLINK().

+ Here is the caller graph for this function:

◆ setOutputOption()

void TTQuantiFH::setOutputOption ( string  opt)
2989{
2990 _output_option = opt;
2991
2992 if( !(_output_option == "genotypes" ||
2993 _output_option == "genotype" ||
2994 _output_option == "snp_genotypes" ||
2995 _output_option == "snp_genotype" || _output_option == "1" || _output_option == "0"))
2996 fatal("option \"%s\" to parameter \"quanti_output\" is not recognized\n", opt.c_str());
2997}

References _output_option, and fatal().

Referenced by TProtoQuanti::loadFileServices().

+ Here is the caller graph for this function:

◆ write_PLINK()

void TTQuantiFH::write_PLINK ( )
3178{
3180 fatal("PLINK file output for the quanti trait is only possible for di-allelic loci (for now)\n");
3181
3182 unsigned int patchNbr = _pop->getPatchNbr();
3183 Patch* current_patch;
3184
3185 std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + ".ped";
3186
3187 // the PED file -------------------------------------------------------------------------
3188 ofstream PED (filename.c_str(), ios::out);
3189
3190 if(!PED) fatal("could not open plink .ped output file!!\n");
3191
3192#ifdef _DEBUG_
3193 message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
3194#endif
3195
3196 for (unsigned int i = 0; i < patchNbr; ++i) {
3197
3198 current_patch = _pop->getPatch(i);
3199
3200 if( _pop->getCurrentAge() & ADULTS)
3201 print_PLINK_PED(PED, ADLTx, current_patch);
3202
3203 if( _pop->getCurrentAge() & OFFSPRG)
3204 print_PLINK_PED(PED, OFFSx, current_patch);
3205
3206 }
3207
3208
3209 PED.close();
3210 // the FAM file -------------------------------------------------------------------------
3211 // we write the .fam file only when more than one trait; phenotype columns are added here
3212
3213 if(_FHLinkedTrait->get_nb_traits() > 1) {
3214
3215 filename = get_path() + this->get_service()->getGenerationReplicateFileName() + ".fam";
3216
3217 ofstream FAM (filename.c_str(), ios::out);
3218
3219 if(!FAM) fatal("could not open plink .fam output file!!\n");
3220
3221#ifdef _DEBUG_
3222 message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
3223#endif
3224
3225 for (unsigned int i = 0; i < patchNbr; ++i) {
3226
3227 current_patch = _pop->getPatch(i);
3228
3229 if( _pop->getCurrentAge() & ADULTS)
3230 print_PLINK_FAM(FAM, ADLTx, current_patch);
3231
3232 if( _pop->getCurrentAge() & OFFSPRG)
3233 print_PLINK_FAM(FAM, OFFSx, current_patch);
3234 }
3235
3236 FAM.close();
3237 }
3238
3239 // the MAP file -------------------------------------------------------------------------
3240 filename = get_path() + this->get_service()->getGenerationReplicateFileName() + ".map";
3241
3242 ofstream MAP (filename.c_str(), ios::out);
3243
3244 if(!MAP) fatal("could not open plink .map output file!!\n");
3245
3246#ifdef _DEBUG_
3247 message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
3248#endif
3249
3250 unsigned int nb_locus = _FHLinkedTrait->get_nb_locus();
3251
3252 double **map;
3253 map = new double* [nb_locus];
3254 for(unsigned int k = 0; k < nb_locus; ++k)
3255 map[k] = new double[2]; // [0]: chr; [1]: map pos in cM
3256
3257 bool found = _FHLinkedTrait->_map.getGeneticMap(_FHLinkedTrait->get_type(), map, nb_locus);
3258
3259 if( found ) {
3260
3261 for(unsigned int k = 0; k < _FHLinkedTrait->get_nb_traits() ; ++k) { //_FHLinkedTrait->get_nb_traits()
3262 for (unsigned int l = 0; l < nb_locus; ++l) { // this will give the locus ID
3263
3264 // MAP FORMAT (PLINK1.9): chrmsm ID; Loc ID; position (cM); bp ID
3265 MAP<<map[l][0]+1<<" T"<<k+1<<"loc"<<l+1<<" "<<map[l][1]<<" "<<l+1<<endl;
3266
3267 }
3268 }
3269 } else { // trait didn't register a genetic map, loci are unlinked (free recombination)
3270
3271 warning("PLINK .map file: we assume QTL are unlinked, separated by 50M and on a single chromosome\n");
3272
3273 // we're gonna set all loci on a single chrmsme, but 50M apart
3274 for(unsigned int k = 0; k < _FHLinkedTrait->get_nb_traits() ; ++k) { //_FHLinkedTrait->get_nb_traits()
3275 for (unsigned int l = 0; l < nb_locus; ++l) { // this will give the locus ID
3276
3277 // write: chromosome, locus name, map position, locus number
3278 MAP<< 1 <<" T"<<k+1<<"loc"<<l+1<<" "<< l*5000.0 + 1.0 <<" "<<l+1<<endl;
3279
3280 }
3281 }
3282
3283 }
3284 MAP.close();
3285
3286 for(unsigned int k = 0; k < nb_locus; ++k) delete [] map[k];
3287 delete [] map;
3288}
std::string & get_path()
Definition: filehandler.h:139
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:390
bool getGeneticMap(trait_t trait, double **table, unsigned int table_length)
Definition: ttrait_with_map.cc:874
age_t getCurrentAge()
Definition: metapop.h:297
unsigned int get_allele_model()
Definition: ttquanti.h:130
virtual trait_t get_type() const
Definition: ttquanti.h:179
static GeneticMap _map
Definition: ttrait_with_map.h:201
void print_PLINK_FAM(ofstream &FH, age_idx Ax, Patch *patch)
Definition: ttquanti.cc:3369
void print_PLINK_PED(ofstream &FH, age_idx Ax, Patch *patch)
Definition: ttquanti.cc:3292
void warning(const char *str,...)
Definition: output.cc:58
void message(const char *message,...)
Definition: output.cc:40
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TTProtoWithMap::_map, FileHandler::_pop, ADLTx, ADULTS, fatal(), TProtoQuanti::get_allele_model(), TProtoQuanti::get_nb_locus(), TProtoQuanti::get_nb_traits(), FileHandler::get_path(), FileHandler::get_service(), TProtoQuanti::get_type(), Metapop::getCurrentAge(), FileServices::getGenerationReplicateFileName(), GeneticMap::getGeneticMap(), Metapop::getPatch(), Metapop::getPatchNbr(), message(), OFFSPRG, OFFSx, print_PLINK_FAM(), print_PLINK_PED(), and warning().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ write_TABLE()

void TTQuantiFH::write_TABLE ( )
3024{
3025 std::string filename = get_filename();
3026
3027 std::ofstream FILE (filename.c_str(), ios::out);
3028
3029 if(!FILE) fatal("could not open \"%s\" output file!!\n",filename.c_str());
3030
3031#ifdef _DEBUG_
3032 message("TTQuantiFH::write_TABLE (%s)\n", filename.c_str());
3033#endif
3034
3035 //print the genotype at each locus
3036 unsigned int print_gene = 0;
3037
3038 if(_output_option == "genotypes" || _output_option == "genotype")
3039 print_gene = 1;
3040 else if(_output_option == "snp_genotypes" || _output_option == "snp_genotype")
3041 print_gene = 2;
3042
3043
3044 //print the genotypic value of the individual in sus of the phenotype
3045 bool print_genotype = (!_FHLinkedTrait->get_env_var().empty());
3046
3047 bool print_additive_genotype = (_FHLinkedTrait->get_dominance_model() != 0);
3048
3049 // First column is the patch ID:
3050 FILE<<"pop ";
3051
3052 // print the allelic values?
3053 if(print_gene) {
3054
3055 // we print allelic values ordered trait:locus, alleles at loci affecting one trait are grouped
3056 for(unsigned int k = 0; k < _FHLinkedTrait->get_nb_traits(); k++)
3057 for(unsigned int l = 0; l < _FHLinkedTrait->get_nb_locus(); l++)
3058
3059 if(print_gene == 1) {
3060 // "x" maternally inherited, "y" paternally inherited
3061 FILE<<"t"<<k+1<<"l"<<l+1<<"x "<<"t"<<k+1<<"l"<<l+1<<"y ";
3062
3063 } else {
3064 // snp-encoded genotypes: 0, 1, 2
3065 FILE<<"t"<<k+1<<"l"<<l+1<<" ";
3066 }
3067 }
3068
3069 for(unsigned int k = 0; k < _FHLinkedTrait->get_nb_traits(); k++) {
3070 FILE<<"P"<<k+1<< " ";
3071 if(print_genotype) FILE<<"G"<<k+1<< " ";
3072 if(print_additive_genotype) FILE<<"A"<<k+1<< " ";
3073 }
3074
3075 FILE<<"age sex home ped isMigrant father mother ID\n";
3076
3077 // add the dominance effects if any:
3078 if(_FHLinkedTrait->get_dominance_model() != 0 && print_gene) {
3079 FILE<< "NA ";
3080 for(unsigned int k = 0; k < _FHLinkedTrait->get_nb_traits(); k++)
3081 for(unsigned int l = 0; l < _FHLinkedTrait->get_nb_locus(); l++)
3082
3083 if(print_gene == 1) {
3084 FILE << _FHLinkedTrait->get_dominance(l, k) << " NA ";
3085 } else {
3086 FILE << _FHLinkedTrait->get_dominance(l, k) << " ";
3087 }
3088 FILE << "NA "; //phenotype
3089 if(print_genotype) FILE<<"NA ";
3090 if(print_additive_genotype) FILE<<"NA ";
3091 FILE << "NA NA NA NA NA NA NA NA\n";
3092 }
3093
3094 age_t pop_age = _pop->getCurrentAge(); //flag telling which age class should contain individuals
3095
3096 //we print anything that is present in the pop:
3097 if( (pop_age & OFFSPRG) != 0) {
3098 print(FILE, FEM, OFFSx, print_gene, print_genotype, print_additive_genotype);
3099 print(FILE, MAL, OFFSx, print_gene, print_genotype, print_additive_genotype);
3100 }
3101 if( (pop_age & ADULTS) != 0) {
3102 print(FILE, FEM, ADLTx, print_gene, print_genotype, print_additive_genotype);
3103 print(FILE, MAL, ADLTx, print_gene, print_genotype, print_additive_genotype);
3104 }
3105
3106 FILE.close();
3107
3108 // reset to pop ptr to main pop:
3110}
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:151
double get_dominance(unsigned int locus, unsigned int trait)
Definition: ttquanti.h:147
unsigned int get_dominance_model()
Definition: ttquanti.h:146
void print(ofstream &FH, sex_t SEX, age_idx Ax, unsigned int print_gene, bool print_genotype, bool print_additive_genotype)
Definition: ttquanti.cc:3114
unsigned int age_t
Age class flags.
Definition: types.h:46

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, _output_option, FileHandler::_pop, ADLTx, ADULTS, fatal(), FEM, TProtoQuanti::get_dominance(), TProtoQuanti::get_dominance_model(), TProtoQuanti::get_env_var(), FileHandler::get_filename(), TProtoQuanti::get_nb_locus(), TProtoQuanti::get_nb_traits(), FileServices::get_pop_ptr(), FileHandler::get_service(), Metapop::getCurrentAge(), MAL, message(), OFFSPRG, OFFSx, and print().

Referenced by FHwrite().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _output_option

string TTQuantiFH::_output_option
private

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