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

6189 {
6190 // unsigned int nb_locus = _FHLinkedTrait->get_num_locus();
6191  unsigned int nb_trait = _FHLinkedTrait->get_num_traits();
6192  unsigned int seqLength = _FHLinkedTrait->get_seq_length();
6193  bool has_genotype = (!_FHLinkedTrait->get_env_var().empty());
6194  bool has_additive_genotype = (_FHLinkedTrait->get_dominance_model() != 0);
6195 
6196  unsigned int patchNbr = _pop->getPatchNbr();
6197 
6198  TTQuanti_continuous* trait;
6199  TTQuanti* DA_trait;
6200 
6201  ifstream FILE(filename.c_str(),ios::in);
6202 
6203  if(!FILE) fatal("could not open QUANTI input file \"%s\"\n",filename.c_str());
6204 
6205  unsigned int age, sex, ped, origin, dummy;
6206  unsigned int loc;
6207  age_idx stagex;
6208  unsigned int pop;
6209 // age_idx agex;
6210  Individual *ind;
6211  double all0, all1, pheno, geno;
6212  double *seq[2];
6213  seq[0] = new double [seqLength];
6214  seq[1] = new double [seqLength];
6215 
6216  unsigned char *binseq[2];
6217  binseq[0] = new unsigned char [seqLength];
6218  binseq[1] = new unsigned char [seqLength];
6219 
6220  int lnbr = 1;
6221 
6222  // swallow the header
6223  FILE.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
6224 
6225  // swallow the second line if it stores the dominance effects:
6226  if(has_additive_genotype)
6227  FILE.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
6228 
6229  string str;
6230 
6231  while(FILE>>pop) {
6232 
6233  if(FILE.bad()) {
6234  error("Reading input genotypes from \"%s\" failed at line %i.\n",filename.c_str(), lnbr);
6235  FILE.clear();
6236  FILE >> str;
6237  fatal("Expecting population number as first element on the line, but received this: %s \n", str.c_str());
6238  }
6239 
6240  if(pop > patchNbr)
6241  fatal("Patch number found in file exceeds number of patches in the population.\n");
6242 
6243  for(unsigned int k = 0; k < nb_trait; ++k) {
6244  for(unsigned int i = 0; i < _FHLinkedTrait->get_num_locus(k); ++i) {
6245 
6246  loc = _FHLinkedTrait->get_locus_seq_pos(i, k);
6247 
6248  FILE>>all0>>all1;
6249 
6250  if(FILE.bad())
6251  fatal("Reading input genotypes from \"%s\" failed at line %i.\n",filename.c_str(), lnbr);
6252 
6253  seq[0][loc] = all0;
6254  seq[1][loc] = all1;
6255  }
6256  }
6257 
6258 
6259  for(unsigned int k = 0; k < nb_trait; k++) {
6260  FILE >> pheno; //read phenotypic value
6261  if(has_genotype) FILE >> geno; // genotypic values, only present if trait is influenced by env. var.
6262  if(has_additive_genotype) FILE >> geno; // geno unused;
6263  }
6264 
6265  // read extra fields
6266  FILE >> age >> sex >> origin >> ped >> dummy >> dummy >> dummy >> dummy;
6267 
6268  stagex = age_idx(age);
6269 
6270  ind = _pop->makeNewIndividual(0, 0, sex_t(sex), origin - 1);
6271  ind->setPedigreeClass((unsigned char)ped);
6272  ind->setAge(age);
6273 
6274  if(_FHLinkedTrait->get_allele_model() > 2) { // non-diallelic loci
6275 
6276  trait = dynamic_cast<TTQuanti_continuous*> (ind->getTrait(_FHLinkedTraitIndex));
6277  trait->set_sequence((void**)seq);
6278  trait->set_value();
6279 
6280  } else { // diallelic loci
6281 
6282  DA_trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
6283 
6284  //have to make a binary sequence out of the data read:
6285  for (unsigned int l = 0; l < seqLength; ++l) {
6286 
6287  binseq[0][l] = (seq[0][l] != _FHLinkedTrait->get_seq_diallele_value(l, 0));
6288  binseq[1][l] = (seq[1][l] != _FHLinkedTrait->get_seq_diallele_value(l, 0));
6289 
6290  }
6291 
6292  DA_trait->set_sequence((void**)binseq);
6293  DA_trait->set_value();
6294  }
6295 
6296 
6297  // ind->show_up();
6298 
6299  _pop->getPatch(pop-1)->add(sex_t(sex), stagex, ind);
6300 
6301  lnbr++;
6302  }
6303 
6304 
6305  FILE.close();
6306 
6307  delete seq[0];
6308  delete seq[1];
6309  delete binseq[0];
6310  delete binseq[1];
6311 }
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:3297
TTQuanti.
Definition: ttquanti.h:60
virtual void set_value()
Definition: ttquanti.cc:3122
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 >.

5697 {
5698  if (!_pop->isAlive()) return;
5699 
5700  if(!get_service()) fatal("TTQuantiFH: link to file services not set!!\n");
5701 
5702  // sets the pop ptr to a sub sampled pop, if sub sampling happened
5704 
5705  if(_output_option == "plink")
5706  write_PLINK();
5707  else
5708  write_TABLE();
5709 
5710 
5711  // reset to pop ptr to main pop:
5712  _pop = get_service()->get_pop_ptr();
5713 
5714 }
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:5882
void write_TABLE()
Definition: ttquanti.cc:5718
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 
)
5814 {
5815  Individual* ind;
5816  TTQuanti* trait;
5817 
5818  double* Tval;
5819 
5820  unsigned int pos, nb_trait=_FHLinkedTrait->get_num_traits();
5821 
5822  for(unsigned int j = 0, size = patch->size(SEX, Ax); j < size; j++) {
5823 
5824  ind = patch->get(SEX, Ax, j);
5825  trait = dynamic_cast<TTQuanti*> (ind->getTrait(_FHLinkedTraitIndex));
5826 
5827  FH<<patch->getID() +1<<" ";
5828 
5829 
5830  if(print_gene) { // print the genotype values at each locus
5831 
5832  FH.precision(6);
5833 
5834  for(unsigned int k = 0; k < nb_trait; k++) {
5835  for(unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); l++) {
5836 
5837  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
5838 
5839  if(print_gene == 1) { // print the allelic values, not the allelic state
5840 
5841  FH << trait->get_allele_value(pos, FEM) <<" "
5842  << trait->get_allele_value(pos, MAL) <<" ";
5843 
5844  } else { // must be option 2 or more; print the genotype state, 0/1/2
5845 
5846  //SNP genotypes, for di-allelic loci only (checked already)
5847 
5848  if(print_gene == 2) {
5849  // SNP genotypes are 0/1/2 for 00/01/11 genotypes
5850  FH << trait->get_allele_bit(pos, FEM) + trait->get_allele_bit(pos, MAL) << " ";
5851  } else {
5852  // print the allele ID 0/1
5853  FH << trait->get_allele_bit(pos, FEM)<< " "
5854  << trait->get_allele_bit(pos, MAL) << " ";
5855  }
5856  }
5857  }
5858  }
5859  }
5860 
5861  FH.precision(4);
5862 
5863  Tval = (double*)trait->getValue();
5864 
5865  for(unsigned int k = 0; k < nb_trait; k++) {
5866  FH<<Tval[k]<<" ";
5867  if(print_genotype) FH << trait->get_full_genotype(k) << " ";
5868  if(print_additive_genotype) FH << trait->get_additive_genotype(k) << " ";
5869  }
5870 
5871  FH<<Ax<<" "<<ind->getSex()<<" "<<ind->getHome()+1<<" "<<ind->getPedigreeClass()<<" "
5872  << (ind->getFather() && ind->getMother() ?
5873  (ind->getFather()->getHome()!= patch->getID() ) + (ind->getMother()->getHome()!= patch->getID() ) : 0)
5874  <<" "<<ind->getFatherID()<<" "<<ind->getMotherID()<<" "<<ind->getID()<<std::endl;
5875  }
5876 
5877 }
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 
)
6114 {
6115  Individual *ind;
6116  unsigned int nb_trait = _FHLinkedTrait->get_num_traits();
6117 
6118  // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
6119  // .fam (PLINK sample information file)
6120  //
6121  // Sample information file accompanying a .bed binary genotype table.
6122  // Also generated by "--recode lgen" and "--recode rlist".
6123  //
6124  // A text file with no header line, and one line per sample with the following six fields:
6125  //
6126  // 1. Family ID ('FID')
6127  // 2. Within-family ID ('IID'; cannot be '0')
6128  // 3. Within-family ID of father ('0' if father isn't in dataset)
6129  // 4. Within-family ID of mother ('0' if mother isn't in dataset)
6130  // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
6131  // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
6132  //
6133  // If there are any numeric phenotype values other than {-9, 0, 1, 2}, the phenotype is interpreted as a
6134  // quantitative trait instead of case/control status. In this case, -9 normally still designates a missing
6135  // phenotype; use --missing-phenotype if this is problematic.
6136 
6137 
6138  // here, we save the phenotypic value of the first trait by default
6139  // the complete set of phenotypic values for all traits is saved in the .fam file
6140 
6141  for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
6142 
6143  ind = patch->get(FEM, Ax, j);
6144 
6145  FH<<"fam"<< ind->getHome()+1
6146  <<" "<< ind->getID();
6147 
6148  if(Ax == OFFSx)
6149  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6150  else
6151  FH<<" 0 0"; //parents not in file for adults
6152 
6153  FH<<" 2";
6154 
6155  for(unsigned int k = 0; k < nb_trait; ++k) {
6156  FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
6157  }
6158 
6159  FH <<std::endl;
6160 
6161  }
6162 
6163  for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
6164 
6165  ind = patch->get(MAL, Ax, j);
6166 
6167  FH<<"fam"<< ind->getHome()+1
6168  <<" "<< ind->getID();
6169 
6170  if(Ax == OFFSx)
6171  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6172  else
6173  FH<<" 0 0"; //parents not in file for adults
6174 
6175  FH<<" 1";
6176 
6177  for(unsigned int k = 0; k < nb_trait; ++k) {
6178  FH << " " << ((double*)ind->getTraitValue(_FHLinkedTraitIndex))[k];
6179  }
6180 
6181  FH<<std::endl;
6182 
6183  }
6184 }
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 
)
6017 {
6018  Individual *ind;
6019 // double** seq;
6020  TTQuanti* trait;
6021  char BASE[2] = {'A','G'};
6022 // const TMatrix& ref_all = _FHLinkedTrait->get_diallele_values();
6023  unsigned int nb_trait = _FHLinkedTrait->get_num_traits(), pos;
6024 
6025  // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
6026  // .fam (PLINK sample information file)
6027  //
6028  // Sample information file accompanying a .bed binary genotype table.
6029  // Also generated by "--recode lgen" and "--recode rlist".
6030  //
6031  // A text file with no header line, and one line per sample with the following six fields:
6032  //
6033  // 1. Family ID ('FID')
6034  // 2. Within-family ID ('IID'; cannot be '0')
6035  // 3. Within-family ID of father ('0' if father isn't in dataset)
6036  // 4. Within-family ID of mother ('0' if mother isn't in dataset)
6037  // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
6038  // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
6039  //
6040  // 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.
6041 
6042 
6043  // here, we save the phenotypic value of the first trait by default
6044  // the complete set of phenotypic values for all traits is saved in the .fam file
6045 
6046  for (unsigned int j = 0; j < patch->size(FEM, Ax); ++j) {
6047 
6048  ind = patch->get(FEM, Ax, j);
6049 
6050  FH<<"fam"<<ind->getHome()+1
6051  <<" "<<ind->getID(); // don't add +1 to keep IDs consistent across files
6052 
6053  if(Ax == OFFSx)
6054  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6055  else
6056  FH<<" 0 0"; //parents not in file for adults
6057 
6058  FH<<" 2 "
6059  <<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
6060 
6061  trait = dynamic_cast<TTQuanti*>(ind->getTrait(_FHLinkedTraitIndex));
6062 
6063  for(unsigned int k = 0; k < nb_trait; ++k) {
6064  for (unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); ++l) {
6065 
6066  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
6067 
6068 
6069  FH << BASE[ trait->get_allele_bit(pos, FEM)] << " "
6070  << BASE[ trait->get_allele_bit(pos, MAL)] << " ";
6071 
6072  }
6073  }
6074 
6075  FH <<std::endl;
6076 
6077  }
6078 
6079  for (unsigned int j = 0; j < patch->size(MAL, Ax); ++j) {
6080 
6081  ind = patch->get(MAL, Ax, j);
6082 
6083  FH<<"fam"<<ind->getHome()+1
6084  <<" "<<ind->getID();
6085 
6086  if(Ax == OFFSx)
6087  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
6088  else
6089  FH<<" 0 0"; //parents not in file for adults
6090 
6091  FH<<" 1 "
6092  <<((double*)ind->getTraitValue(_FHLinkedTraitIndex))[0]<<" ";
6093 
6094  trait = dynamic_cast<TTQuanti*>(ind->getTrait(_FHLinkedTraitIndex));
6095 
6096  for(unsigned int k = 0; k < nb_trait; ++k) {
6097  for (unsigned int l = 0; l < _FHLinkedTrait->get_num_locus(k); ++l) {
6098 
6099  pos = _FHLinkedTrait->get_locus_seq_pos(l, k);
6100 
6101  FH << BASE[ trait->get_allele_bit(pos, FEM)] << " "
6102  << BASE[ trait->get_allele_bit(pos, MAL)] << " ";
6103 
6104  }
6105  }
6106  FH<<std::endl;
6107 
6108  }
6109 }

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)
5675 {
5676  _output_option = opt;
5677 
5678  std::for_each(_output_option.begin(), _output_option.end(), [](char& c){c = ::tolower(c);});
5679 
5680  if( !(_output_option == "genotypes" || _output_option == "genotype" ||
5681  _output_option == "snp_genotypes" || _output_option == "snp_genotype" ||
5682  _output_option == "snp_id" || _output_option == "plink" ||
5683  _output_option == "1" || _output_option == "0")) {
5684  fatal("option \"%s\" to parameter \"quanti_output\" is not recognized\n", opt.c_str());
5685  }
5686 
5688 
5689  if(_output_option == "plink" && !_has_genetic_map)
5690  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");
5691 
5692 }
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:228
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 ( )
5883 {
5884  if(_FHLinkedTrait->get_allele_model() > 2)
5885  fatal("PLINK file output for the quanti trait is only possible for di-allelic loci.\n");
5886 
5887  unsigned int patchNbr = _pop->getPatchNbr();
5888  Patch* current_patch;
5889 
5890  std::string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.ped";
5891 
5892  // the PED file -------------------------------------------------------------------------
5893  ofstream PED (filename.c_str(), ios::out);
5894  std::ios_base::sync_with_stdio(false); // better for writing performances
5895 
5896  if(!PED) fatal("could not open plink .ped output file!!\n");
5897 
5898 #ifdef _DEBUG_
5899  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
5900 #endif
5901 
5902  for (unsigned int i = 0; i < patchNbr; ++i) {
5903 
5904  current_patch = _pop->getPatch(i);
5905 
5906  if( _pop->getCurrentAge() & OFFSPRG)
5907  print_PLINK_PED(PED, OFFSx, current_patch);
5908 
5909  if( _pop->getCurrentAge() & ADULTS) {
5910  for(unsigned int a = 1; a < _pop->getNumAgeClasses(); ++a)
5911  print_PLINK_PED(PED, age_idx(a), current_patch);
5912  }
5913 
5914  }
5915 
5916  PED.close();
5917 
5918  // the FAM file -------------------------------------------------------------------------
5919  // we write the .fam file only when more than one trait; phenotype columns are added here
5920 
5921  if(_FHLinkedTrait->get_num_traits() > 1) {
5922 
5923  filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.fam";
5924 
5925  ofstream FAM (filename.c_str(), ios::out);
5926  std::ios_base::sync_with_stdio(false); // better for writing performances
5927 
5928  if(!FAM) fatal("could not open plink .fam output file!!\n");
5929 
5930 #ifdef _DEBUG_
5931  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
5932 #endif
5933 
5934  for (unsigned int i = 0; i < patchNbr; ++i) {
5935 
5936  current_patch = _pop->getPatch(i);
5937 
5938  if( _pop->getCurrentAge() & OFFSPRG)
5939  print_PLINK_FAM(FAM, OFFSx, current_patch);
5940 
5941  if( _pop->getCurrentAge() & ADULTS){
5942  for(unsigned int a = 1; a < _pop->getNumAgeClasses(); ++a)
5943  print_PLINK_FAM(FAM, age_idx(a), current_patch);
5944  }
5945 
5946  }
5947 
5948  FAM.close();
5949  }
5950 
5951  // the MAP file -------------------------------------------------------------------------
5952  // !! careful here with pleiotropy, same locus will be registered for each trait it affects
5953  // output for pleiotropic locis has not be tested with PLINK
5954 
5955  filename = get_path() + this->get_service()->getGenerationReplicateFileName() + "-quanti.map";
5956 
5957  ofstream MAP (filename.c_str(), ios::out);
5958 
5959  if(!MAP) fatal("could not open plink .map output file!!\n");
5960 
5961 #ifdef _DEBUG_
5962  message("TTQuantiFH::write_PLINK (%s)\n",filename.c_str());
5963 #endif
5964 
5965 
5966  if( _has_genetic_map ) {
5967 
5968  unsigned int nb_locus = _FHLinkedTrait->get_num_locus();
5969 
5970  double *map[2];
5971  map[0] = new double [nb_locus]; // chromosome ID
5972  map[1] = new double [nb_locus]; // position
5973 
5975 
5976  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; ++k) {
5977  for (unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k); ++l) { // this will give the locus ID
5978 
5979  LOCUS = _FHLinkedTrait->get_locus_ID(l, k);
5980 
5981  // MAP FORMAT (PLINK1.9): chrmsm ID; Loc ID; position (cM); bp ID
5982  MAP <<map[0][ LOCUS ]+1
5983  <<" T"<< k + 1 <<"loc"<< LOCUS + 1 <<" "
5984  <<map[1][ LOCUS ]<<" "<< LOCUS + 1 <<endl;
5985 
5986  }
5987  }
5988 
5989 
5990  delete [] map[0];
5991  delete [] map[1];
5992 
5993  } else { // trait didn't register a genetic map, loci are unlinked (free recombination)
5994 
5995  // we're gonna set all loci on a single chrmsme, but 50M apart
5996  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; ++k) { //_FHLinkedTrait->get_num_traits()
5997  for (unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k); ++l) { // this will give the locus ID
5998 
5999  LOCUS = _FHLinkedTrait->get_locus_ID(l, k) + 1;
6000 
6001  // write: chromosome, locus name, map position, locus number
6002  MAP<< 1 <<" T"<<k+1<<"loc"<< LOCUS <<" "<< l*5000.0 + 1.0 <<" "<< LOCUS <<endl;
6003 
6004  }
6005  }
6006 
6007  }
6008  MAP.close();
6009 
6010  std::ios_base::sync_with_stdio(true); // reset
6011 
6012 }
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:924
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:6113
void print_PLINK_PED(ofstream &FH, age_idx Ax, Patch *patch)
Definition: ttquanti.cc:6016
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(), 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 ( )
5719 {
5720  std::string filename = get_filename();
5721 
5722  std::ofstream FILE (filename.c_str(), ios::out);
5723  std::ios_base::sync_with_stdio(false); // better for writing performances
5724 
5725 
5726  if(!FILE) fatal("could not open \"%s\" output file!!\n",filename.c_str());
5727 
5728 #ifdef _DEBUG_
5729  message("TTQuantiFH::write_TABLE (%s)\n", filename.c_str());
5730 #endif
5731 
5732  //print the genotype at each locus
5733  unsigned int print_gene = 0;
5734 
5735  if(_output_option == "genotypes" || _output_option == "genotype")
5736  print_gene = 1;
5737  else if(_output_option == "snp_genotypes" || _output_option == "snp_genotype")
5738  print_gene = 2;
5739  else if(_output_option == "snp_id")
5740  print_gene = 3;
5741 
5742 
5743  //print the genotypic value of the individual in sus of the phenotype
5744  bool print_genotype = (!_FHLinkedTrait->get_env_var().empty()) || print_gene != 0;
5745 
5746  bool print_additive_genotype = (_FHLinkedTrait->get_dominance_model() != 0);
5747 
5748  // NOTE: it is not possible to separate total genotypic value from pure additive value in the epistatic case
5749 
5750  // First column is the patch ID:
5751  FILE<<"pop ";
5752 
5753  // print the allelic values?
5754  if(print_gene) {
5755 
5756  // we print allelic values ordered trait:locus, alleles at loci affecting one trait are grouped
5757  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits() ; k++) {
5758  for(unsigned int l = 0, LOCUS; l < _FHLinkedTrait->get_num_locus(k) ; l++) {
5759 
5760  LOCUS = _FHLinkedTrait->get_locus_ID(l, k) + 1;
5761 
5762  if(print_gene == 1 || print_gene == 3) { // print two values per locus
5763  // "x" maternally inherited, "y" paternally inherited
5764  FILE<<"t"<<k+1<<"l"<< LOCUS <<"x "<<"t"<<k+1<<"l"<< LOCUS <<"y ";
5765 
5766  } else { // means > 1; print snp_genotype 0/1/2, instead of alleles state/value
5767 
5768  //check allele model:
5769  if(_FHLinkedTrait->get_allele_model() > 2)
5770  fatal("trait quant output::SNP genotypes can only be printed for di-allelic loci.\n");
5771 
5772  // snp-encoded genotypes: 0, 1, 2
5773  FILE<<"t"<<k+1<<"l"<< LOCUS <<" ";
5774  }
5775  }
5776  }
5777  }
5778 
5779  for(unsigned int k = 0; k < _FHLinkedTrait->get_num_traits(); k++) {
5780  FILE<<"P"<<k+1<< " ";
5781  if(print_genotype) FILE<<"G"<<k+1<< " ";
5782  if(print_additive_genotype) FILE<<"A"<<k+1<< " ";
5783  }
5784 
5785  FILE<<"age sex home ped isMigrant father mother ID\n";
5786 
5787 
5788  Patch* current_patch;
5789 
5790  for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
5791 
5792  current_patch = _pop->getPatch(i);
5793 
5794  if( current_patch->size(OFFSx) != 0 ) {
5795  print(FILE, current_patch, FEM, OFFSx, print_gene, print_genotype, print_additive_genotype);
5796  print(FILE, current_patch, MAL, OFFSx, print_gene, print_genotype, print_additive_genotype);
5797  }
5798 
5799  if( current_patch->size(ADLTx) != 0 ) {
5800  print(FILE, current_patch, FEM, ADLTx, print_gene, print_genotype, print_additive_genotype);
5801  print(FILE, current_patch, MAL, ADLTx, print_gene, print_genotype, print_additive_genotype);
5802  }
5803 
5804  }
5805 
5806  FILE.close();
5807  std::ios_base::sync_with_stdio(true); // reset
5808 
5809 }
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:5813
@ 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.1 by  doxygen 1.9.1

Catalogued on GSR