Nemo  2.4.2
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
814  : TraitFileHandler<TProtoQuanti>(T,".quanti"),
815  _has_genetic_map(0) {}
bool _has_genetic_map
Definition: ttquanti.h:811

◆ ~TTQuantiFH()

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

Member Function Documentation

◆ FHread()

void TTQuantiFH::FHread ( string &  filename)
virtual

Implements FileHandler.

6188 {
6189 // unsigned int nb_locus = _FHLinkedTrait->get_num_locus();
6190  unsigned int nb_trait = _FHLinkedTrait->get_num_traits();
6191  unsigned int seqLength = _FHLinkedTrait->get_seq_length();
6192  bool has_genotype = (!_FHLinkedTrait->get_env_var().empty());
6193  bool has_additive_genotype = (_FHLinkedTrait->get_dominance_model() != 0);
6194 
6195  unsigned int patchNbr = _pop->getPatchNbr();
6196 
6197  TTQuanti_continuous* trait;
6198  TTQuanti* DA_trait;
6199 
6200  ifstream FILE(filename.c_str(),ios::in);
6201 
6202  if(!FILE) fatal("could not open QUANTI input file \"%s\"\n",filename.c_str());
6203 
6204  unsigned int age, sex, ped, origin, dummy;
6205  unsigned int loc;
6206  age_idx stagex;
6207  unsigned int pop;
6208 // age_idx agex;
6209  Individual *ind;
6210  double all0, all1, pheno, geno;
6211  double *seq[2];
6212  seq[0] = new double [seqLength];
6213  seq[1] = new double [seqLength];
6214 
6215  unsigned char *binseq[2];
6216  binseq[0] = new unsigned char [seqLength];
6217  binseq[1] = new unsigned char [seqLength];
6218 
6219  int lnbr = 1;
6220 
6221  // swallow the header
6222  FILE.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
6223 
6224  // swallow the second line if it stores the dominance effects:
6225  if(has_additive_genotype)
6226  FILE.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
6227 
6228  string str;
6229 
6230  while(FILE>>pop) {
6231 
6232  if(FILE.bad()) {
6233  error("Reading input genotypes from \"%s\" failed at line %i.\n",filename.c_str(), lnbr);
6234  FILE.clear();
6235  FILE >> str;
6236  fatal("Expecting population number as first element on the line, but received this: %s \n", str.c_str());
6237  }
6238 
6239  if(pop > patchNbr)
6240  fatal("Patch number found in file exceeds number of patches in the population.\n");
6241 
6242  for(unsigned int k = 0; k < nb_trait; ++k) {
6243  for(unsigned int i = 0; i < _FHLinkedTrait->get_num_locus(k); ++i) {
6244 
6245  loc = _FHLinkedTrait->get_locus_seq_pos(i, k);
6246 
6247  FILE>>all0>>all1;
6248 
6249  if(FILE.bad())
6250  fatal("Reading input genotypes from \"%s\" failed at line %i.\n",filename.c_str(), lnbr);
6251 
6252  seq[0][loc] = all0;
6253  seq[1][loc] = all1;
6254  }
6255  }
6256 
6257 
6258  for(unsigned int k = 0; k < nb_trait; k++) {
6259  FILE >> pheno; //read phenotypic value
6260  if(has_genotype) FILE >> geno; // genotypic values, only present if trait is influenced by env. var.
6261  if(has_additive_genotype) FILE >> geno; // geno unused;
6262  }
6263 
6264  // read extra fields
6265  FILE >> age >> sex >> origin >> ped >> dummy >> dummy >> dummy >> dummy;
6266 
6267  stagex = age_idx(age);
6268 
6269  ind = _pop->makeNewIndividual(0, 0, sex_t(sex), origin - 1);
6270  ind->setPedigreeClass((unsigned char)ped);
6271  ind->setAge(age);
6272 
6273  if(_FHLinkedTrait->get_allele_model() > 2) { // non-diallelic loci
6274 
6275  trait = dynamic_cast<TTQuanti_continuous*> (ind->getTrait(_FHLinkedTraitIndex));
6276  trait->set_sequence((void**)seq);
6277  trait->set_value();
6278 
6279  } else { // diallelic loci
6280 
6281  DA_trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
6282 
6283  //have to make a binary sequence out of the data read:
6284  for (unsigned int l = 0; l < seqLength; ++l) {
6285 
6286  binseq[0][l] = (seq[0][l] != _FHLinkedTrait->get_seq_diallele_value(l, 0));
6287  binseq[1][l] = (seq[1][l] != _FHLinkedTrait->get_seq_diallele_value(l, 0));
6288 
6289  }
6290 
6291  DA_trait->set_sequence((void**)binseq);
6292  DA_trait->set_value();
6293  }
6294 
6295 
6296  // ind->show_up();
6297 
6298  _pop->getPatch(pop-1)->add(sex_t(sex), stagex, ind);
6299 
6300  lnbr++;
6301  }
6302 
6303 
6304  FILE.close();
6305 
6306  delete seq[0];
6307  delete seq[1];
6308  delete binseq[0];
6309  delete binseq[1];
6310 }
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:101
Individual * makeNewIndividual(Individual *newind, Individual *mother, Individual *father, sex_t sex, unsigned short homepatch)
Creates an individual from existing pointer with new ID.
Definition: indfactory.cc:150
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
void setPedigreeClass(Individual *mother, Individual *father)
Definition: individual.h:113
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:275
void setAge(unsigned short value)
Definition: individual.h:103
unsigned int getPatchNbr()
Definition: metapop.h:274
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:255
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
double get_seq_diallele_value(unsigned int position, unsigned int allele)
Definition: ttquanti.h:436
unsigned int get_allele_model()
Definition: ttquanti.h:432
unsigned int get_locus_seq_pos(unsigned int loc, unsigned int trait)
Definition: ttquanti.h:451
unsigned int get_num_locus()
Definition: ttquanti.h:422
unsigned int get_seq_length()
Definition: ttquanti.h:425
unsigned int get_num_traits()
Definition: ttquanti.h:421
unsigned int get_dominance_model()
Definition: ttquanti.h:476
vector< double > get_env_var()
Definition: ttquanti.h:428
TTQuanti_continuous.
Definition: ttquanti.h:112
virtual void set_sequence(void **seq)
Definition: ttquanti.cc:3296
TTQuanti.
Definition: ttquanti.h:59
virtual void set_value()
Definition: ttquanti.cc:3121
virtual void set_sequence(void **seq)=0
Called to set the sequence pointer to an existing trait.
int _FHLinkedTraitIndex
Definition: filehandler.h:222
TProtoQuanti * _FHLinkedTrait
Definition: filehandler.h:221
void fatal(const char *str,...)
Definition: output.cc:98
int error(const char *str,...)
Definition: output.cc:77
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:39

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 >.

5696 {
5697  if (!_pop->isAlive()) return;
5698 
5699  if(!get_service()) fatal("TTQuantiFH: link to file services not set!!\n");
5700 
5701  // sets the pop ptr to a sub sampled pop, if sub sampling happened
5703 
5704  if(_output_option == "plink")
5705  write_PLINK();
5706  else
5707  write_TABLE();
5708 
5709 
5710  // reset to pop ptr to main pop:
5711  _pop = get_service()->get_pop_ptr();
5712 
5713 }
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:137
Metapop * getSampledPop()
Sets the down-sampled population and provides accessor to file handlers.
Definition: fileservices.cc:196
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:5881
void write_TABLE()
Definition: ttquanti.cc:5717
string _output_option
Definition: ttquanti.h:810

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 
)
5813 {
5814  Individual* ind;
5815  TTQuanti* trait;
5816 
5817  double* Tval;
5818 
5819  unsigned int pos, nb_trait=_FHLinkedTrait->get_num_traits();
5820 
5821  for(unsigned int j = 0, size = patch->size(SEX, Ax); j < size; j++) {
5822 
5823  ind = patch->get(SEX, Ax, j);
5824  trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
5825 
5826  FH<<patch->getID() +1<<" ";
5827 
5828 
5829  if(print_gene) { // print the genotype values at each locus
5830 
5831  FH.precision(6);
5832 
5833  for(unsigned int k = 0; k < nb_trait; k++) {
5834  for(unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); l++) {
5835 
5836  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
5837 
5838  if(print_gene == 1) { // print the allelic values, not the allelic state
5839 
5840  FH << trait->get_allele_value(pos, FEM) <<" "
5841  << trait->get_allele_value(pos, MAL) <<" ";
5842 
5843  } else { // must be option 2 or more; print the genotype state, 0/1/2
5844 
5845  //SNP genotypes, for di-allelic loci only (checked already)
5846 
5847  if(print_gene == 2) {
5848  // SNP genotypes are 0/1/2 for 00/01/11 genotypes
5849  FH << trait->get_allele_bit(pos, FEM) + trait->get_allele_bit(pos, MAL) << " ";
5850  } else {
5851  // print the allele ID 0/1
5852  FH << trait->get_allele_bit(pos, FEM)<< " "
5853  << trait->get_allele_bit(pos, MAL) << " ";
5854  }
5855  }
5856  }
5857  }
5858  }
5859 
5860  FH.precision(4);
5861 
5862  Tval = (double*)trait->getValue();
5863 
5864  for(unsigned int k = 0; k < nb_trait; k++) {
5865  FH<<Tval[k]<<" ";
5866  if(print_genotype) FH << trait->get_full_genotype(k) << " ";
5867  if(print_additive_genotype) FH << trait->get_additive_genotype(k) << " ";
5868  }
5869 
5870  FH<<Ax<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
5871  << (ind->getFather() && ind->getMother() ?
5872  (ind->getFather()->getHome()!= patch->getID() ) + (ind->getMother()->getHome()!= patch->getID() ) : 0)
5873  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
5874  }
5875 
5876 }
unsigned long getID()
Definition: individual.h:120
unsigned short getHome()
Definition: individual.h:126
Individual * getMother()
Definition: individual.h:125
unsigned long getMotherID()
Definition: individual.h:123
Individual * getFather()
Definition: individual.h:124
sex_t getSex()
Definition: individual.h:127
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:177
unsigned long getFatherID()
Definition: individual.h:122
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 getID()
Definition: metapop.h:479
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 the value of the allele at a particular locus.
@ FEM
Definition: types.h:35
@ MAL
Definition: types.h:35

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().

+ Here is the caller graph for this function:

◆ print_PLINK_FAM()

void TTQuantiFH::print_PLINK_FAM ( ofstream &  FH,
age_idx  Ax,
Patch patch 
)
6113 {
6114  Individual *ind;
6115  unsigned int nb_trait = _FHLinkedTrait->get_num_traits();
6116 
6117  // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
6118  // .fam (PLINK sample information file)
6119  //
6120  // Sample information file accompanying a .bed binary genotype table.
6121  // Also generated by "--recode lgen" and "--recode rlist".
6122  //
6123  // A text file with no header line, and one line per sample with the following six fields:
6124  //
6125  // 1. Family ID ('FID')
6126  // 2. Within-family ID ('IID'; cannot be '0')
6127  // 3. Within-family ID of father ('0' if father isn't in dataset)
6128  // 4. Within-family ID of mother ('0' if mother isn't in dataset)
6129  // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
6130  // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
6131  //
6132  // If there are any numeric phenotype values other than {-9, 0, 1, 2}, the phenotype is interpreted as a
6133  // quantitative trait instead of case/control status. In this case, -9 normally still designates a missing
6134  // phenotype; use --missing-phenotype if this is problematic.
6135 
6136 
6137  // here, we save the phenotypic value of the first trait by default
6138  // the complete set of phenotypic values for all traits is saved in the .fam file
6139 
6140  for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
6141 
6142  ind = patch->get(FEM, Ax, j);
6143 
6144  FH<<"fam"<< ind->getHome()+1
6145  <<" "<< ind->getID();
6146 
6147  if(Ax == OFFSx)
6148  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6149  else
6150  FH<<" 0 0"; //parents not in file for adults
6151 
6152  FH<<" 2";
6153 
6154  for(unsigned int k = 0; k < nb_trait; ++k) {
6155  FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
6156  }
6157 
6158  FH <<std::endl;
6159 
6160  }
6161 
6162  for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
6163 
6164  ind = patch->get(MAL, Ax, j);
6165 
6166  FH<<"fam"<< ind->getHome()+1
6167  <<" "<< ind->getID();
6168 
6169  if(Ax == OFFSx)
6170  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6171  else
6172  FH<<" 0 0"; //parents not in file for adults
6173 
6174  FH<<" 1";
6175 
6176  for(unsigned int k = 0; k < nb_trait; ++k) {
6177  FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
6178  }
6179 
6180  FH<<std::endl;
6181 
6182  }
6183 }
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:269
@ OFFSx
Definition: types.h:40

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().

+ Here is the caller graph for this function:

◆ print_PLINK_PED()

void TTQuantiFH::print_PLINK_PED ( ofstream &  FH,
age_idx  Ax,
Patch patch 
)
6016 {
6017  Individual *ind;
6018 // double** seq;
6019  TTQuanti* trait;
6020  char BASE[2] = {'A','G'};
6021 // const TMatrix& ref_all = _FHLinkedTrait->get_diallele_values();
6022  unsigned int nb_trait = _FHLinkedTrait->get_num_traits(), pos;
6023 
6024  // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
6025  // .fam (PLINK sample information file)
6026  //
6027  // Sample information file accompanying a .bed binary genotype table.
6028  // Also generated by "--recode lgen" and "--recode rlist".
6029  //
6030  // A text file with no header line, and one line per sample with the following six fields:
6031  //
6032  // 1. Family ID ('FID')
6033  // 2. Within-family ID ('IID'; cannot be '0')
6034  // 3. Within-family ID of father ('0' if father isn't in dataset)
6035  // 4. Within-family ID of mother ('0' if mother isn't in dataset)
6036  // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
6037  // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
6038  //
6039  // 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.
6040 
6041 
6042  // here, we save the phenotypic value of the first trait by default
6043  // the complete set of phenotypic values for all traits is saved in the .fam file
6044 
6045  for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
6046 
6047  ind = patch->get(FEM, Ax, j);
6048 
6049  FH<<"fam"<<ind->getHome()+1
6050  <<" "<<ind->getID(); // don't add +1 to keep IDs consistent across files
6051 
6052  if(Ax == OFFSx)
6053  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6054  else
6055  FH<<" 0 0"; //parents not in file for adults
6056 
6057  FH<<" 2 "
6058  <<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
6059 
6060  trait = dynamic_cast<TTQuanti*>(ind->getTrait(_FHLinkedTraitIndex));
6061 
6062  for(unsigned int k = 0; k < nb_trait; ++k) {
6063  for (unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); ++l) {
6064 
6065  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
6066 
6067 
6068  FH << BASE[ trait->get_allele_bit(pos, FEM)] << " "
6069  << BASE[ trait->get_allele_bit(pos, MAL)] << " ";
6070 
6071  }
6072  }
6073 
6074  FH <<std::endl;
6075 
6076  }
6077 
6078  for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
6079 
6080  ind = patch->get(MAL, Ax, j);
6081 
6082  FH<<"fam"<<ind->getHome()+1
6083  <<" "<<ind->getID();
6084 
6085  if(Ax == OFFSx)
6086  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6087  else
6088  FH<<" 0 0"; //parents not in file for adults
6089 
6090  FH<<" 1 "
6091  <<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
6092 
6093  trait = dynamic_cast<TTQuanti*>(ind->getTrait(_FHLinkedTraitIndex));
6094 
6095  for(unsigned int k = 0; k < nb_trait; ++k) {
6096  for (unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); ++l) {
6097 
6098  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
6099 
6100  FH << BASE[ trait->get_allele_bit(pos, FEM)] << " "
6101  << BASE[ trait->get_allele_bit(pos, MAL)] << " ";
6102 
6103  }
6104  }
6105  FH<<std::endl;
6106 
6107  }
6108 }

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().

+ Here is the caller graph for this function:

◆ setOutputOption()

void TTQuantiFH::setOutputOption ( string  opt)
5674 {
5675  _output_option = opt;
5676 
5677  std::for_each(_output_option.begin(), _output_option.end(), [](char& c){c = ::tolower(c);});
5678 
5679  if( !(_output_option == "genotypes" || _output_option == "genotype" ||
5680  _output_option == "snp_genotypes" || _output_option == "snp_genotype" ||
5681  _output_option == "snp_id" || _output_option == "plink" ||
5682  _output_option == "1" || _output_option == "0")) {
5683  fatal("option \"%s\" to parameter \"quanti_output\" is not recognized\n", opt.c_str());
5684  }
5685 
5687 
5688  if(_output_option == "plink" && !_has_genetic_map)
5689  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");
5690 
5691 }
bool checkRegisteredTrait(trait_t trait)
Returns true if trait 'trait' has registered a genetic map, false otherwise.
Definition: ttrait_with_map.cc:672
virtual trait_t get_type() const
Definition: ttquanti.h:574
static GeneticMap _map
Definition: ttrait_with_map.h:227
void warning(const char *str,...)
Definition: output.cc:56
std::string trait_t
Trait types.
Definition: types.h:61

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

Referenced by TProtoQuanti::loadFileServices().

+ Here is the caller graph for this function:

◆ write_PLINK()

void TTQuantiFH::write_PLINK ( )
5882 {
5883  if(_FHLinkedTrait->get_allele_model() > 2)
5884  fatal("PLINK file output for the quanti trait is only possible for di-allelic loci.\n");
5885 
5886  unsigned int patchNbr = _pop->getPatchNbr();
5887  Patch* current_patch;
5888 
5889  std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.ped";
5890 
5891  // the PED file -------------------------------------------------------------------------
5892  ofstream PED (filename.c_str(), ios::out);
5893  std::ios_base::sync_with_stdio(false); // better for writing performances
5894 
5895  if(!PED) fatal("could not open plink .ped output file!!\n");
5896 
5897 #ifdef _DEBUG_
5898  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
5899 #endif
5900 
5901  for (unsigned int i = 0; i < patchNbr; ++i) {
5902 
5903  current_patch = _pop->getPatch(i);
5904 
5905  if( _pop->getCurrentAge() & OFFSPRG)
5906  print_PLINK_PED(PED, OFFSx, current_patch);
5907 
5908  if( _pop->getCurrentAge() & ADULTS) {
5909  for(unsigned int a = 1; a < _pop->getNumAgeClasses(); ++a)
5910  print_PLINK_PED(PED, age_idx(a), current_patch);
5911  }
5912 
5913  }
5914 
5915  PED.close();
5916 
5917  // the FAM file -------------------------------------------------------------------------
5918  // we write the .fam file only when more than one trait; phenotype columns are added here
5919 
5920  if(_FHLinkedTrait->get_num_traits() > 1) {
5921 
5922  filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.fam";
5923 
5924  ofstream FAM (filename.c_str(), ios::out);
5925  std::ios_base::sync_with_stdio(false); // better for writing performances
5926 
5927  if(!FAM) fatal("could not open plink .fam output file!!\n");
5928 
5929 #ifdef _DEBUG_
5930  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
5931 #endif
5932 
5933  for (unsigned int i = 0; i < patchNbr; ++i) {
5934 
5935  current_patch = _pop->getPatch(i);
5936 
5937  if( _pop->getCurrentAge() & OFFSPRG)
5938  print_PLINK_FAM(FAM, OFFSx, current_patch);
5939 
5940  if( _pop->getCurrentAge() & ADULTS){
5941  for(unsigned int a = 1; a < _pop->getNumAgeClasses(); ++a)
5942  print_PLINK_FAM(FAM, age_idx(a), current_patch);
5943  }
5944 
5945  }
5946 
5947  FAM.close();
5948  }
5949 
5950  // the MAP file -------------------------------------------------------------------------
5951  // !! careful here with pleiotropy, same locus will be registered for each trait it affects
5952  // output for pleiotropic locis has not be tested with PLINK
5953 
5954  filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.map";
5955 
5956  ofstream MAP (filename.c_str(), ios::out);
5957 
5958  if(!MAP) fatal("could not open plink .map output file!!\n");
5959 
5960 #ifdef _DEBUG_
5961  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
5962 #endif
5963 
5964 
5965  if( _has_genetic_map ) {
5966 
5967  unsigned int nb_locus = _FHLinkedTrait->get_num_locus();
5968 
5969  double *map[2];
5970  map[0] = new double [nb_locus]; // chromosome ID
5971  map[1] = new double [nb_locus]; // position
5972 
5974 
5975  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; ++k) {
5976  for (unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k); ++l) { // this will give the locus ID
5977 
5978  LOCUS = _FHLinkedTrait->get_locus_ID(l, k);
5979 
5980  // MAP FORMAT (PLINK1.9): chrmsm ID; Loc ID; position (cM); bp ID
5981  MAP <<map[0][ LOCUS ]+1
5982  <<" T"<< k + 1 <<"loc"<< LOCUS + 1 <<" "
5983  <<map[1][ LOCUS ]<<" "<< LOCUS + 1 <<endl;
5984 
5985  }
5986  }
5987 
5988 
5989  delete [] map[0];
5990  delete [] map[1];
5991 
5992  } else { // trait didn't register a genetic map, loci are unlinked (free recombination)
5993 
5994  // we're gonna set all loci on a single chrmsme, but 50M apart
5995  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; ++k) { //_FHLinkedTrait->get_num_traits()
5996  for (unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k); ++l) { // this will give the locus ID
5997 
5998  LOCUS = _FHLinkedTrait->get_locus_ID(l, k) + 1;
5999 
6000  // write: chromosome, locus name, map position, locus number
6001  MAP<< 1 <<" T"<<k+1<<"loc"<< LOCUS <<" "<< l*5000.0 + 1.0 <<" "<< LOCUS <<endl;
6002 
6003  }
6004  }
6005 
6006  }
6007  MAP.close();
6008 
6009  std::ios_base::sync_with_stdio(true); // reset
6010 
6011 }
std::string & get_path()
Definition: filehandler.h:141
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:465
bool getGeneticMap(trait_t trait, double **table, unsigned int table_length)
Definition: ttrait_with_map.cc:923
unsigned int getNumAgeClasses()
Definition: metapop.h:288
age_t getCurrentAge()
Definition: metapop.h:297
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
unsigned int get_locus_ID(unsigned int locus, unsigned int trait)
Definition: ttquanti.h:453
void print_PLINK_FAM(ofstream &FH, age_idx Ax, Patch *patch)
Definition: ttquanti.cc:6112
void print_PLINK_PED(ofstream &FH, age_idx Ax, Patch *patch)
Definition: ttquanti.cc:6015
void message(const char *message,...)
Definition: output.cc:38
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:52
#define OFFSPRG
Offspring age class flag.
Definition: types.h:48

References TraitFileHandler< TProtoQuanti >::_FHLinkedTrait, _has_genetic_map, TTProtoWithMap::_map, FileHandler::_pop, ADULTS, fatal(), 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::getNumAgeClasses(), Metapop::getPatch(), Metapop::getPatchNbr(), message(), OFFSPRG, OFFSx, print_PLINK_FAM(), and print_PLINK_PED().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ write_TABLE()

void TTQuantiFH::write_TABLE ( )
5718 {
5719  std::string filename = get_filename();
5720 
5721  std::ofstream FILE (filename.c_str(), ios::out);
5722  std::ios_base::sync_with_stdio(false); // better for writing performances
5723 
5724 
5725  if(!FILE) fatal("could not open \"%s\" output file!!\n",filename.c_str());
5726 
5727 #ifdef _DEBUG_
5728  message("TTQuantiFH::write_TABLE (%s)\n", filename.c_str());
5729 #endif
5730 
5731  //print the genotype at each locus
5732  unsigned int print_gene = 0;
5733 
5734  if(_output_option == "genotypes" || _output_option == "genotype")
5735  print_gene = 1;
5736  else if(_output_option == "snp_genotypes" || _output_option == "snp_genotype")
5737  print_gene = 2;
5738  else if(_output_option == "snp_id")
5739  print_gene = 3;
5740 
5741 
5742  //print the genotypic value of the individual in sus of the phenotype
5743  bool print_genotype = (!_FHLinkedTrait->get_env_var().empty()) || print_gene != 0;
5744 
5745  bool print_additive_genotype = (_FHLinkedTrait->get_dominance_model() != 0);
5746 
5747  // NOTE: it is not possible to separate total genotypic value from pure additive value in the epistatic case
5748 
5749  // First column is the patch ID:
5750  FILE<<"pop ";
5751 
5752  // print the allelic values?
5753  if(print_gene) {
5754 
5755  // we print allelic values ordered trait:locus, alleles at loci affecting one trait are grouped
5756  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; k++) {
5757  for(unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k) ; l++) {
5758 
5759  LOCUS = _FHLinkedTrait->get_locus_ID(l, k) + 1;
5760 
5761  if(print_gene == 1 || print_gene == 3) { // print two values per locus
5762  // "x" maternally inherited, "y" paternally inherited
5763  FILE<<"t"<<k+1<<"l"<< LOCUS <<"x "<<"t"<<k+1<<"l"<< LOCUS <<"y ";
5764 
5765  } else { // means > 1; print snp_genotype 0/1/2, instead of alleles state/value
5766 
5767  //check allele model:
5768  if(_FHLinkedTrait->get_allele_model() > 2)
5769  fatal("trait quant output::SNP genotypes can only be printed for di-allelic loci.\n");
5770 
5771  // snp-encoded genotypes: 0, 1, 2
5772  FILE<<"t"<<k+1<<"l"<< LOCUS <<" ";
5773  }
5774  }
5775  }
5776  }
5777 
5778  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits(); k++) {
5779  FILE<<"P"<<k+1<< " ";
5780  if(print_genotype) FILE<<"G"<<k+1<< " ";
5781  if(print_additive_genotype) FILE<<"A"<<k+1<< " ";
5782  }
5783 
5784  FILE<<"age sex home ped isMigrant father mother ID\n";
5785 
5786 
5787  Patch* current_patch;
5788 
5789  for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
5790 
5791  current_patch = _pop->getPatch(i);
5792 
5793  if( current_patch->size(OFFSx) != 0 ) {
5794  print(FILE, current_patch, FEM, OFFSx, print_gene, print_genotype, print_additive_genotype);
5795  print(FILE, current_patch, MAL, OFFSx, print_gene, print_genotype, print_additive_genotype);
5796  }
5797 
5798  if( current_patch->size(ADLTx) != 0 ) {
5799  print(FILE, current_patch, FEM, ADLTx, print_gene, print_genotype, print_additive_genotype);
5800  print(FILE, current_patch, MAL, ADLTx, print_gene, print_genotype, print_additive_genotype);
5801  }
5802 
5803  }
5804 
5805  FILE.close();
5806  std::ios_base::sync_with_stdio(true); // reset
5807 
5808 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:149
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:5812
@ ADLTx
Definition: types.h:40

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().

+ Here is the caller graph for this function:

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.2 by  doxygen 1.9.1

Catalogued on GSR