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

◆ ~TTQuantiFH()

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

Member Function Documentation

◆ FHread()

void TTQuantiFH::FHread ( string &  filename)
virtual

Implements FileHandler.

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

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

5699 {
5700  if (!_pop->isAlive()) return;
5701 
5702  if(!get_service()) fatal("TTQuantiFH: link to file services not set!!\n");
5703 
5704  // sets the pop ptr to a sub sampled pop, if sub sampling happened
5706 
5707  if(_output_option == "plink")
5708  write_PLINK();
5709  else
5710  write_TABLE();
5711 
5712 
5713  // reset to pop ptr to main pop:
5714  _pop = get_service()->get_pop_ptr();
5715 
5716 }
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:138
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:112
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:308
void write_PLINK()
Definition: ttquanti.cc:5884
void write_TABLE()
Definition: ttquanti.cc:5720
string _output_option
Definition: ttquanti.h:811

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

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

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

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

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

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

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.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR