Nemo  2.4.0b
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, Patch *patch, 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 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)
 
virtual void set_multi (bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, 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 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

string _output_option
 
bool _has_genetic_map
 

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
803  : TraitFileHandler<TProtoQuanti>(T,".quanti"),
804  _has_genetic_map(0) {}
bool _has_genetic_map
Definition: ttquanti.h:800

◆ ~TTQuantiFH()

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

Member Function Documentation

◆ FHread()

void TTQuantiFH::FHread ( string &  filename)
virtual

Implements FileHandler.

6433 {
6434 // unsigned int nb_locus = _FHLinkedTrait->get_num_locus();
6435  unsigned int nb_trait = _FHLinkedTrait->get_num_traits();
6436  unsigned int seqLength = _FHLinkedTrait->get_seq_length();
6437  bool has_genotype = (!_FHLinkedTrait->get_env_var().empty());
6438  bool has_additive_genotype = (_FHLinkedTrait->get_dominance_model() != 0);
6439 
6440  unsigned int patchNbr = _pop->getPatchNbr();
6441 
6442  TTQuanti_continuous* trait;
6443  TTQuanti* DA_trait;
6444 
6445  ifstream FILE(filename.c_str(),ios::in);
6446 
6447  if(!FILE) fatal("could not open QUANTI input file \"%s\"\n",filename.c_str());
6448 
6449  unsigned int age, sex, ped, origin, dummy;
6450  unsigned int loc;
6451  age_idx stagex;
6452  unsigned int pop;
6453 // age_idx agex;
6454  Individual *ind;
6455  double all0, all1, pheno, geno;
6456  double *seq[2];
6457  seq[0] = new double [seqLength];
6458  seq[1] = new double [seqLength];
6459 
6460  unsigned char *binseq[2];
6461  binseq[0] = new unsigned char [seqLength];
6462  binseq[1] = new unsigned char [seqLength];
6463 
6464  int lnbr = 1;
6465 
6466  // swallow the header
6467  FILE.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
6468 
6469  // swallow the second line if it stores the dominance effects:
6470  if(has_additive_genotype)
6471  FILE.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
6472 
6473  string str;
6474 
6475  while(FILE>>pop) {
6476 
6477  if(FILE.bad()) {
6478  error("Reading input genotypes from \"%s\" failed at line %i.\n",filename.c_str(), lnbr);
6479  FILE.clear();
6480  FILE >> str;
6481  fatal("Expecting population number as first element on the line, but received this: %s \n", str.c_str());
6482  }
6483 
6484  if(pop > patchNbr)
6485  fatal("Patch number found in file exceeds number of patches in the population.\n");
6486 
6487  for(unsigned int k = 0; k < nb_trait; ++k) {
6488  for(unsigned int i = 0; i < _FHLinkedTrait->get_num_locus(k); ++i) {
6489 
6490  loc = _FHLinkedTrait->get_locus_seq_pos(i, k);
6491 
6492  FILE>>all0>>all1;
6493 
6494  if(FILE.bad())
6495  fatal("Reading input genotypes from \"%s\" failed at line %i.\n",filename.c_str(), lnbr);
6496 
6497  seq[0][loc] = all0;
6498  seq[1][loc] = all1;
6499  }
6500  }
6501 
6502 
6503  for(unsigned int k = 0; k < nb_trait; k++) {
6504  FILE >> pheno; //read phenotypic value
6505  if(has_genotype) FILE >> geno; // genotypic values, only present if trait is influenced by env. var.
6506  if(has_additive_genotype) FILE >> geno; // geno unused;
6507  }
6508 
6509  // read extra fields
6510  FILE >> age >> sex >> origin >> ped >> dummy >> dummy >> dummy >> dummy;
6511 
6512  stagex = age_idx(age);
6513 
6514  ind = _pop->makeNewIndividual(0, 0, sex_t(sex), origin - 1);
6515  ind->setPedigreeClass((unsigned char)ped);
6516  ind->setAge(age);
6517 
6518  if(_FHLinkedTrait->get_allele_model() > 2) { // non-diallelic loci
6519 
6520  trait = dynamic_cast<TTQuanti_continuous*> (ind->getTrait(_FHLinkedTraitIndex));
6521  trait->set_sequence((void**)seq);
6522  trait->set_value();
6523 
6524  } else { // diallelic loci
6525 
6526  DA_trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
6527 
6528  //have to make a binary sequence out of the data read:
6529  for (unsigned int l = 0; l < seqLength; ++l) {
6530 
6531  binseq[0][l] = (seq[0][l] != _FHLinkedTrait->get_seq_diallele_value(l, 0));
6532  binseq[1][l] = (seq[1][l] != _FHLinkedTrait->get_seq_diallele_value(l, 0));
6533 
6534  }
6535 
6536  DA_trait->set_sequence((void**)binseq);
6537  DA_trait->set_value();
6538  }
6539 
6540 
6541  // ind->show_up();
6542 
6543  _pop->getPatch(pop-1)->add(sex_t(sex), stagex, ind);
6544 
6545  lnbr++;
6546  }
6547 
6548 
6549  FILE.close();
6550 
6551  delete seq[0];
6552  delete seq[1];
6553  delete binseq[0];
6554  delete binseq[1];
6555 }
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:551
double get_seq_diallele_value(unsigned int position, unsigned int allele)
Definition: ttquanti.h:432
unsigned int get_allele_model()
Definition: ttquanti.h:428
unsigned int get_locus_seq_pos(unsigned int loc, unsigned int trait)
Definition: ttquanti.h:440
unsigned int get_num_locus()
Definition: ttquanti.h:418
unsigned int get_seq_length()
Definition: ttquanti.h:421
unsigned int get_num_traits()
Definition: ttquanti.h:417
unsigned int get_dominance_model()
Definition: ttquanti.h:461
vector< double > get_env_var()
Definition: ttquanti.h:424
TTQuanti_continuous.
Definition: ttquanti.h:110
virtual void set_sequence(void **seq)
Definition: ttquanti.cc:3245
TTQuanti.
Definition: ttquanti.h:59
virtual void set_value()
Definition: ttquanti.cc:3091
virtual void set_sequence(void **seq)=0
Called to set the sequence pointer to an existing trait.
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_allele_model(), TProtoQuanti::get_dominance_model(), TProtoQuanti::get_env_var(), TProtoQuanti::get_locus_seq_pos(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_num_traits(), TProtoQuanti::get_seq_diallele_value(), TProtoQuanti::get_seq_length(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), IndFactory::makeNewIndividual(), TTQuanti_continuous::set_sequence(), TTrait::set_sequence(), TTQuanti::set_value(), Individual::setAge(), and Individual::setPedigreeClass().

◆ FHwrite()

void TTQuantiFH::FHwrite ( )
virtual

Implements TraitFileHandler< TProtoQuanti >.

5934 {
5935  if (!_pop->isAlive()) return;
5936 
5937  if(!get_service()) fatal("TTQuantiFH: link to file services not set!!\n");
5938 
5939  // sets the pop ptr to a sub sampled pop, if sub sampling happened
5941 
5942  if(_output_option == "plink")
5943  write_PLINK();
5944  else
5945  write_TABLE();
5946 
5947 
5948  // reset to pop ptr to main pop:
5949  _pop = get_service()->get_pop_ptr();
5950 
5951 }
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
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:309
void write_PLINK()
Definition: ttquanti.cc:6134
void write_TABLE()
Definition: ttquanti.cc:5955
string _output_option
Definition: ttquanti.h:799

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,
Patch patch,
sex_t  SEX,
age_idx  Ax,
unsigned int  print_gene,
bool  print_genotype,
bool  print_additive_genotype 
)
6066 {
6067  Individual* ind;
6068  TTQuanti* trait;
6069  TTQuanti* DA_trait;
6070 
6071  double* Tval;
6072 
6073  unsigned int pos, nb_trait=_FHLinkedTrait->get_num_traits();
6074 
6075  for(unsigned int j = 0, size = patch->size(SEX, Ax); j < size; j++) {
6076 
6077  ind = patch->get(SEX, Ax, j);
6078  trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
6079 
6080  FH<<patch->getID() +1<<" ";
6081 
6082 
6083  if(print_gene) { // print the genotype values at each locus
6084 
6085  FH.precision(6);
6086 
6087  for(unsigned int k = 0; k < nb_trait; k++) {
6088  for(unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); l++) {
6089 
6090  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
6091 
6092  if(print_gene == 1) { // print the allelic values, not the allelic state
6093 
6094  FH << trait->get_allele_value(pos, FEM) <<" "
6095  << trait->get_allele_value(pos, MAL) <<" ";
6096 
6097  } else { // must be option 2 or more; print the genotype state, 0/1/2
6098 
6099  //SNP genotypes, for di-allelic loci only (checked already)
6100 
6101  //cast to diallelic trait
6102 
6103  DA_trait = dynamic_cast<TTQuanti*>(trait);
6104 
6105  // SNP genotypes are 0/1/2 for 00/01/11 genotypes
6106  FH << DA_trait->get_allele_bit(pos, FEM) + DA_trait->get_allele_bit(pos, MAL) << " ";
6107 
6108  }
6109  }
6110  }
6111  }
6112 
6113  FH.precision(4);
6114 
6115  Tval = (double*)trait->getValue();
6116 
6117  for(unsigned int k = 0; k < nb_trait; k++) {
6118  FH<<Tval[k]<<" ";
6119  if(print_genotype) FH << trait->get_full_genotype(k) << " ";
6120  if(print_additive_genotype) FH << trait->get_additive_genotype(k) << " ";
6121  }
6122 
6123  FH<<Ax<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
6124  << (ind->getFather() && ind->getMother() ?
6125  (ind->getFather()->getHome()!= patch->getID() ) + (ind->getMother()->getHome()!= patch->getID() ) : 0)
6126  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
6127  }
6128 
6129 }
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
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
virtual bool get_allele_bit(unsigned int position, unsigned int allele) const =0
virtual double get_additive_genotype(const unsigned int trait) const =0
virtual void * getValue() const
Definition: ttquanti.h:77
virtual double get_full_genotype(unsigned int trait)=0
virtual double get_allele_value(int loc, int all) const =0
Called to read one allele value at a particular locus.
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, FEM, Patch::get(), TTQuanti::get_additive_genotype(), TTQuanti::get_allele_bit(), TTrait::get_allele_value(), TTQuanti::get_full_genotype(), TProtoQuanti::get_locus_seq_pos(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_num_traits(), Individual::getFather(), Individual::getFatherID(), Individual::getHome(), Individual::getID(), Patch::getID(), Individual::getMother(), Individual::getMotherID(), Individual::getPedigreeClass(), Individual::getSex(), Individual::getTrait(), TTQuanti::getValue(), MAL, and Patch::size().

Referenced by write_TABLE().

◆ print_PLINK_FAM()

void TTQuantiFH::print_PLINK_FAM ( ofstream &  FH,
age_idx  Ax,
Patch patch 
)
6359 {
6360  Individual *ind;
6361  unsigned int nb_trait = _FHLinkedTrait->get_num_traits();
6362 
6363  // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
6364  // .fam (PLINK sample information file)
6365  //
6366  // Sample information file accompanying a .bed binary genotype table.
6367  // Also generated by "--recode lgen" and "--recode rlist".
6368  //
6369  // A text file with no header line, and one line per sample with the following six fields:
6370  //
6371  // 1. Family ID ('FID')
6372  // 2. Within-family ID ('IID'; cannot be '0')
6373  // 3. Within-family ID of father ('0' if father isn't in dataset)
6374  // 4. Within-family ID of mother ('0' if mother isn't in dataset)
6375  // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
6376  // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
6377  //
6378  // If there are any numeric phenotype values other than {-9, 0, 1, 2}, the phenotype is interpreted as a
6379  // quantitative trait instead of case/control status. In this case, -9 normally still designates a missing
6380  // phenotype; use --missing-phenotype if this is problematic.
6381 
6382 
6383  // here, we save the complete set of phenotypic values for all traits
6384 
6385  for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
6386 
6387  ind = patch->get(FEM, Ax, j);
6388 
6389  FH<<"fam"<< ind->getHome()+1
6390  <<" "<< ind->getID();
6391 
6392  if(Ax == OFFSx)
6393  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6394  else
6395  FH<<" 0 0"; //parents not in file for adults
6396 
6397  FH<<" 2";
6398 
6399  for(unsigned int k = 0; k < nb_trait; ++k) {
6400  FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
6401  }
6402 
6403  FH <<std::endl;
6404 
6405  }
6406 
6407  for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
6408 
6409  ind = patch->get(MAL, Ax, j);
6410 
6411  FH<<"fam"<< ind->getHome()+1
6412  <<" "<< ind->getID();
6413 
6414  if(Ax == OFFSx)
6415  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6416  else
6417  FH<<" 0 0"; //parents not in file for adults
6418 
6419  FH<<" 1";
6420 
6421  for(unsigned int k = 0; k < nb_trait; ++k) {
6422  FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
6423  }
6424 
6425  FH<<std::endl;
6426 
6427  }
6428 }
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271
@ OFFSx
Definition: types.h:42

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

Referenced by write_PLINK().

◆ print_PLINK_PED()

void TTQuantiFH::print_PLINK_PED ( ofstream &  FH,
age_idx  Ax,
Patch patch 
)
6262 {
6263  Individual *ind;
6264 // double** seq;
6265  TTQuanti* trait;
6266  char BASE[2] = {'A','G'};
6267 // const TMatrix& ref_all = _FHLinkedTrait->get_diallele_values();
6268  unsigned int nb_trait = _FHLinkedTrait->get_num_traits(), pos;
6269 
6270  // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
6271  // .fam (PLINK sample information file)
6272  //
6273  // Sample information file accompanying a .bed binary genotype table.
6274  // Also generated by "--recode lgen" and "--recode rlist".
6275  //
6276  // A text file with no header line, and one line per sample with the following six fields:
6277  //
6278  // 1. Family ID ('FID')
6279  // 2. Within-family ID ('IID'; cannot be '0')
6280  // 3. Within-family ID of father ('0' if father isn't in dataset)
6281  // 4. Within-family ID of mother ('0' if mother isn't in dataset)
6282  // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
6283  // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
6284  //
6285  // 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.
6286 
6287 
6288  // here, we save the phenotypic value of the first trait by default
6289  // the complete set of phenotypic values for all traits is saved in the .fam file
6290 
6291  for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
6292 
6293  ind = patch->get(FEM, Ax, j);
6294 
6295  FH<<"fam"<<ind->getHome()+1
6296  <<" "<<ind->getID(); // don't add +1 to keep IDs consistent across files
6297 
6298  if(Ax == OFFSx)
6299  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6300  else
6301  FH<<" 0 0"; //parents not in file for adults
6302 
6303  FH<<" 2 "
6304  <<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
6305 
6306  trait = dynamic_cast<TTQuanti*>(ind->getTrait(_FHLinkedTraitIndex));
6307 
6308  for(unsigned int k = 0; k < nb_trait; ++k) {
6309  for (unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); ++l) {
6310 
6311  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
6312 
6313 
6314  FH << BASE[ trait->get_allele_bit(pos, FEM)] << " "
6315  << BASE[ trait->get_allele_bit(pos, MAL)] << " ";
6316 
6317  }
6318  }
6319 
6320  FH <<std::endl;
6321 
6322  }
6323 
6324  for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
6325 
6326  ind = patch->get(MAL, Ax, j);
6327 
6328  FH<<"fam"<<ind->getHome()+1
6329  <<" "<<ind->getID();
6330 
6331  if(Ax == OFFSx)
6332  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6333  else
6334  FH<<" 0 0"; //parents not in file for adults
6335 
6336  FH<<" 1 "
6337  <<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
6338 
6339  trait = dynamic_cast<TTQuanti*>(ind->getTrait(_FHLinkedTraitIndex));
6340 
6341  for(unsigned int k = 0; k < nb_trait; ++k) {
6342  for (unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); ++l) {
6343 
6344  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
6345 
6346  FH << BASE[ trait->get_allele_bit(pos, FEM)] << " "
6347  << BASE[ trait->get_allele_bit(pos, MAL)] << " ";
6348 
6349  }
6350  }
6351  FH<<std::endl;
6352 
6353  }
6354 }

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, TraitFileHandler< TProtoQuanti >::_FHLinkedTraitIndex, FEM, Patch::get(), TProtoQuanti::get_locus_seq_pos(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_num_traits(), Individual::getFatherID(), Individual::getHome(), Individual::getID(), Individual::getMotherID(), Individual::getTrait(), Individual::getTraitValue(), MAL, OFFSx, and Patch::size().

Referenced by write_PLINK().

◆ setOutputOption()

void TTQuantiFH::setOutputOption ( string  opt)
5913 {
5914  _output_option = opt;
5915 
5916  std::for_each(_output_option.begin(), _output_option.end(), [](char& c){c = ::tolower(c);});
5917 
5918  if( !(_output_option == "genotypes" || _output_option == "genotype" ||
5919  _output_option == "snp_genotypes" || _output_option == "snp_genotype" ||
5920  _output_option == "plink" ||
5921  _output_option == "1" || _output_option == "0"))
5922  fatal("option \"%s\" to parameter \"quanti_output\" is not recognized\n", opt.c_str());
5923 
5925 
5926  if(_output_option == "plink" && !_has_genetic_map)
5927  warning("PLINK .map file for quant trait: no genetic map found for QTL, we assume they are unlinked, separated by 50M and on a single chromosome.\n");
5928 
5929 }
bool checkRegisteredTrait(trait_t trait)
Returns true if trait 'trait' has registered a genetic map, false otherwise.
Definition: ttrait_with_map.cc:648
virtual trait_t get_type() const
Definition: ttquanti.h:555
static GeneticMap _map
Definition: ttrait_with_map.h:209
void warning(const char *str,...)
Definition: output.cc:58
std::string trait_t
Trait types.
Definition: types.h:63

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, _has_genetic_map, TTProtoWithMap::_map, _output_option, GeneticMap::checkRegisteredTrait(), fatal(), TProtoQuanti::get_type(), and warning().

Referenced by TProtoQuanti::loadFileServices().

◆ write_PLINK()

void TTQuantiFH::write_PLINK ( )
6135 {
6136  if(_FHLinkedTrait->get_allele_model() > 2)
6137  fatal("PLINK file output for the quanti trait is only possible for di-allelic loci.\n");
6138 
6139  unsigned int patchNbr = _pop->getPatchNbr();
6140  Patch* current_patch;
6141 
6142  std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.ped";
6143 
6144  // the PED file -------------------------------------------------------------------------
6145  ofstream PED (filename.c_str(), ios::out);
6146 
6147  if(!PED) fatal("could not open plink .ped output file!!\n");
6148 
6149 #ifdef _DEBUG_
6150  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
6151 #endif
6152 
6153  for (unsigned int i = 0; i < patchNbr; ++i) {
6154 
6155  current_patch = _pop->getPatch(i);
6156 
6157  if( _pop->getCurrentAge() & OFFSPRG)
6158  print_PLINK_PED(PED, OFFSx, current_patch);
6159 
6160  if( _pop->getCurrentAge() & ADULTS)
6161  print_PLINK_PED(PED, ADLTx, current_patch);
6162 
6163  }
6164 
6165  PED.close();
6166 
6167  // the FAM file -------------------------------------------------------------------------
6168  // we write the .fam file only when more than one trait; phenotype columns are added here
6169 
6170  if(_FHLinkedTrait->get_num_traits() > 1) {
6171 
6172  filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.fam";
6173 
6174  ofstream FAM (filename.c_str(), ios::out);
6175 
6176  if(!FAM) fatal("could not open plink .fam output file!!\n");
6177 
6178 #ifdef _DEBUG_
6179  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
6180 #endif
6181 
6182  for (unsigned int i = 0; i < patchNbr; ++i) {
6183 
6184  current_patch = _pop->getPatch(i);
6185 
6186  if( _pop->getCurrentAge() & OFFSPRG)
6187  print_PLINK_FAM(FAM, OFFSx, current_patch);
6188 
6189  if( _pop->getCurrentAge() & ADULTS)
6190  print_PLINK_FAM(FAM, ADLTx, current_patch);
6191 
6192  }
6193 
6194  FAM.close();
6195  }
6196 
6197  // the MAP file -------------------------------------------------------------------------
6198  // !! careful here with pleiotropy, same locus will be registered for each trait it affects
6199  // output for pleiotropic locis has not be tested with PLINK
6200 
6201  filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.map";
6202 
6203  ofstream MAP (filename.c_str(), ios::out);
6204 
6205  if(!MAP) fatal("could not open plink .map output file!!\n");
6206 
6207 #ifdef _DEBUG_
6208  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
6209 #endif
6210 
6211 
6212  if( _has_genetic_map ) {
6213 
6214  unsigned int nb_locus = _FHLinkedTrait->get_num_locus();
6215 
6216  double **map;
6217  map = new double* [nb_locus];
6218  for(unsigned int k = 0; k < nb_locus; ++k)
6219  map[k] = new double[2]; // [0]: chr; [1]: map pos in cM
6220 
6222 
6223  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; ++k) {
6224  for (unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k); ++l) { // this will give the locus ID
6225 
6226  LOCUS = _FHLinkedTrait->get_locus_ID(l, k);
6227 
6228  // MAP FORMAT (PLINK1.9): chrmsm ID; Loc ID; position (cM); bp ID
6229  MAP <<map[ LOCUS ][FEM]+1
6230  <<" T"<< k + 1 <<"loc"<< LOCUS + 1 <<" "
6231  <<map[LOCUS][MAL]<<" "<< LOCUS + 1 <<endl;
6232 
6233  }
6234  }
6235 
6236 
6237  for(unsigned int k = 0; k < nb_locus; ++k) delete [] map[k];
6238  delete [] map;
6239 
6240  } else { // trait didn't register a genetic map, loci are unlinked (free recombination)
6241 
6242  // we're gonna set all loci on a single chrmsme, but 50M apart
6243  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; ++k) { //_FHLinkedTrait->get_num_traits()
6244  for (unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k); ++l) { // this will give the locus ID
6245 
6246  LOCUS = _FHLinkedTrait->get_locus_ID(l, k) + 1;
6247 
6248  // write: chromosome, locus name, map position, locus number
6249  MAP<< 1 <<" T"<<k+1<<"loc"<< LOCUS <<" "<< l*5000.0 + 1.0 <<" "<< LOCUS <<endl;
6250 
6251  }
6252  }
6253 
6254  }
6255  MAP.close();
6256 
6257 }
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:438
bool getGeneticMap(trait_t trait, double **table, unsigned int table_length)
Definition: ttrait_with_map.cc:889
age_t getCurrentAge()
Definition: metapop.h:299
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
unsigned int get_locus_ID(unsigned int locus, unsigned int trait)
Definition: ttquanti.h:442
void print_PLINK_FAM(ofstream &FH, age_idx Ax, Patch *patch)
Definition: ttquanti.cc:6358
void print_PLINK_PED(ofstream &FH, age_idx Ax, Patch *patch)
Definition: ttquanti.cc:6261
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
@ ADLTx
Definition: types.h:42

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

Referenced by FHwrite().

◆ write_TABLE()

void TTQuantiFH::write_TABLE ( )
5956 {
5957  std::string filename = get_filename();
5958 
5959  std::ofstream FILE (filename.c_str(), ios::out);
5960 
5961  if(!FILE) fatal("could not open \"%s\" output file!!\n",filename.c_str());
5962 
5963 #ifdef _DEBUG_
5964  message("TTQuantiFH::write_TABLE (%s)\n", filename.c_str());
5965 #endif
5966 
5967  //print the genotype at each locus
5968  unsigned int print_gene = 0;
5969 
5970  if(_output_option == "genotypes" || _output_option == "genotype")
5971  print_gene = 1;
5972  else if(_output_option == "snp_genotypes" || _output_option == "snp_genotype")
5973  print_gene = 2;
5974 
5975 
5976  //print the genotypic value of the individual in sus of the phenotype
5977  bool print_genotype = (!_FHLinkedTrait->get_env_var().empty());
5978 
5979  bool print_additive_genotype = (_FHLinkedTrait->get_dominance_model() != 0);
5980 
5981  // NOTE: it is not possible to separate total genotypic value from pure additive value in the epistatic case
5982 
5983  // First column is the patch ID:
5984  FILE<<"pop ";
5985 
5986  // print the allelic values?
5987  if(print_gene) {
5988 
5989  // we print allelic values ordered trait:locus, alleles at loci affecting one trait are grouped
5990  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; k++) {
5991  for(unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k) ; l++) {
5992 
5993  LOCUS = _FHLinkedTrait->get_locus_ID(l, k) + 1;
5994 
5995  if(print_gene == 1) {
5996  // "x" maternally inherited, "y" paternally inherited
5997  FILE<<"t"<<k+1<<"l"<< LOCUS <<"x "<<"t"<<k+1<<"l"<< LOCUS <<"y ";
5998 
5999  } else { // means > 1; print snp_genotype
6000 
6001  //check allele model:
6002  if(_FHLinkedTrait->get_allele_model() > 2)
6003  fatal("trait quant output::SNP genotypes can only be printed for di-allelic loci.\n");
6004 
6005  // snp-encoded genotypes: 0, 1, 2
6006  FILE<<"t"<<k+1<<"l"<< LOCUS <<" ";
6007  }
6008  }
6009  }
6010  }
6011 
6012  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits(); k++) {
6013  FILE<<"P"<<k+1<< " ";
6014  if(print_genotype) FILE<<"G"<<k+1<< " ";
6015  if(print_additive_genotype) FILE<<"A"<<k+1<< " ";
6016  }
6017 
6018  FILE<<"age sex home ped isMigrant father mother ID\n";
6019 
6020  // add the dominance effects if any:
6021 // if(_FHLinkedTrait->get_dominance_model() != 0 && print_gene) {
6022 // FILE<< "NA ";
6023 // for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits(); k++) {
6024 // for(unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k); l++) {
6025 //
6026 // LOCUS = _FHLinkedTrait->get_locus_ID(l, k);
6027 //
6028 // if(print_gene == 1) {
6029 // FILE << _FHLinkedTrait->get_dominance(LOCUS, k) << " NA ";
6030 // } else {
6031 // FILE << _FHLinkedTrait->get_dominance(LOCUS, k) << " ";
6032 // }
6033 // }
6034 // }
6035 //
6036 // FILE << "NA "; //phenotype
6037 // if(print_genotype) FILE<<"NA ";
6038 // if(print_additive_genotype) FILE<<"NA ";
6039 // FILE << "NA NA NA NA NA NA NA NA\n";
6040 // }
6041 
6042  Patch* current_patch;
6043 
6044  for(unsigned int i = 0; i < _pop->getPatchNbr(); i++) {
6045 
6046  current_patch = _pop->getPatch(i);
6047 
6048  if( current_patch->size(OFFSx) != 0 ) {
6049  print(FILE, current_patch, FEM, OFFSx, print_gene, print_genotype, print_additive_genotype);
6050  print(FILE, current_patch, MAL, OFFSx, print_gene, print_genotype, print_additive_genotype);
6051  }
6052 
6053  if( current_patch->size(ADLTx) != 0 ) {
6054  print(FILE, current_patch, FEM, ADLTx, print_gene, print_genotype, print_additive_genotype);
6055  print(FILE, current_patch, MAL, ADLTx, print_gene, print_genotype, print_additive_genotype);
6056  }
6057 
6058  }
6059 
6060  FILE.close();
6061 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:151
void print(ofstream &FH, Patch *patch, sex_t SEX, age_idx Ax, unsigned int print_gene, bool print_genotype, bool print_additive_genotype)
Definition: ttquanti.cc:6065

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, _output_option, FileHandler::_pop, ADLTx, fatal(), FEM, TProtoQuanti::get_allele_model(), TProtoQuanti::get_dominance_model(), TProtoQuanti::get_env_var(), FileHandler::get_filename(), TProtoQuanti::get_locus_ID(), TProtoQuanti::get_num_locus(), TProtoQuanti::get_num_traits(), Metapop::getPatch(), Metapop::getPatchNbr(), MAL, message(), OFFSx, print(), and Patch::size().

Referenced by FHwrite().

Member Data Documentation

◆ _has_genetic_map

bool TTQuantiFH::_has_genetic_map
private

Referenced by setOutputOption(), and write_PLINK().

◆ _output_option

string TTQuantiFH::_output_option
private

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