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

FileHandler to write joint genotype files for multiple mappable traits. More...

#include <servicenotifiers.h>

+ Inheritance diagram for GenotyperFH:
+ Collaboration diagram for GenotyperFH:

Public Member Functions

 GenotyperFH (LCE_FileServicesNotifier *event)
 
virtual ~GenotyperFH ()
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
void setTraits (vector< trait_t > &traits)
 
void setTraitIndex (vector< unsigned int > &indices)
 
void setFormat (string format)
 
void setLogtime (string logtime)
 
void set_isDiallelic (bool test)
 
void set_trimFixedLoci (bool test, double maf)
 
void prepare_data_table (map< unsigned int, vector< unsigned int > > &trait_locus, vector< string > &col_names)
 
void print_genotypes (ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
 
void print_snp_genotypes (ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
 
void print_snp_id (ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
 
void print_PLINK (string file, map< unsigned int, vector< unsigned int > > &table)
 
void print_map_positions (ofstream &FH, vector< unsigned int > &positions, vector< string > &col_names)
 
- Public Member Functions inherited from EventFileHandler< LCE_FileServicesNotifier >
 EventFileHandler (LCE_FileServicesNotifier *event, const char *ext)
 
virtual ~EventFileHandler ()
 
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, LCE_FileServicesNotifier *event)
 
- 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

vector< trait_t_traits
 
vector< unsigned int > _trait_index
 
string _format
 
string _logtime
 
bool _is_diallelic
 
bool _trim_loci
 
double _trim_maf
 

Additional Inherited Members

- Protected Attributes inherited from EventFileHandler< LCE_FileServicesNotifier >
LCE_FileServicesNotifier_FHLinkedEvent
 
- Protected Attributes inherited from FileHandler
Metapop_pop
 Pointer to the current metapop, set during initialization within the init function. More...
 

Detailed Description

FileHandler to write joint genotype files for multiple mappable traits.

Constructor & Destructor Documentation

◆ GenotyperFH()

GenotyperFH::GenotyperFH ( LCE_FileServicesNotifier event)
inline
120 : EventFileHandler(event, "") , _is_diallelic(0), _trim_loci(0), _trim_maf(0) {}
EventFileHandler(LCE_FileServicesNotifier *event, const char *ext)
Definition: filehandler.h:271
bool _is_diallelic
Definition: servicenotifiers.h:115
double _trim_maf
Definition: servicenotifiers.h:117
bool _trim_loci
Definition: servicenotifiers.h:116

◆ ~GenotyperFH()

virtual GenotyperFH::~GenotyperFH ( )
inlinevirtual
122 {}

Member Function Documentation

◆ FHread()

virtual void GenotyperFH::FHread ( string &  filename)
inlinevirtual

Implements FileHandler.

125 {}

◆ FHwrite()

void GenotyperFH::FHwrite ( )
virtual

Implements EventFileHandler< LCE_FileServicesNotifier >.

402 {
403  if(!_pop->isAlive()) return;
404 
405  // reset the pop ptr from the file services, will be the main metapop without sub sampling
406  // or a sub sampled pop otherwise:
407 
408  vector< string > file_header;
409  map< unsigned int, vector<unsigned int> > table_trait_locus;
410 
412 
413  // prepare the table receiving the allelic info. Sets the right number of columns and individual info
414  prepare_data_table(table_trait_locus, file_header);
415 
416  // WRITE data to file
417  string filename = this->get_filename();
418 
419 
420  if(_format == "plink") {
421 
422  print_PLINK(filename, table_trait_locus);
423 
424  } else {
425 
426  ofstream FILE(filename, ios::out | ios::trunc);
427  std::ios_base::sync_with_stdio(false); // better for writing performances
428 
429  if(!FILE) fatal("Genotyper::could not open genotype output file \"%s\"\n",filename.c_str());
430 
431  // print the header
432  auto concat = [] (string a, string b){return a + " " + b;};
433 
434  FILE << std::accumulate(file_header.begin()+1, file_header.end(), *file_header.begin(), concat) << endl;
435 
436  if(_format == "genotype") {
437 
438  print_genotypes(FILE, table_trait_locus);
439 
440  } else if (_format == "snp_genotype") {
441 
442  print_snp_genotypes(FILE, table_trait_locus);
443 
444  } else {
445 
446  print_snp_id(FILE, table_trait_locus);
447 
448  }
449 
450  FILE.close();
451  std::ios_base::sync_with_stdio(true); // reset
452 
453  }
454 
455 
456  // --------------------------------------------------------------------------------------
457  // write the map position of the loci to a separate file.
458  // For the "plink" format, print_PLINK() already wrote the .map in PLINK1.9
459  // column order; skip this generic writer so we don't overwrite it.
460  if(_format != "plink") {
461 
462  filename = get_path() + this->get_service()->getGenerationReplicateFileName() + ".map";
463 
464  ofstream MAP(filename, ios::out | ios::trunc);
465  std::ios_base::sync_with_stdio(false); // better for writing performances
466 
467  double *map[2];
468  TraitPrototype* tproto;
469 
470  // write the file header:
471 
472  MAP<<"trait.locus chromosome position locus"<<endl;
473 
474  for(auto trait : _traits) {
475 
476  tproto = SIMenv::MainSim->get_pop()->getTraitPrototype(trait);
477 
478  unsigned int num_locus = tproto->get_locus_number();
479 
480  map[0] = new double [num_locus]; // chromosome ID
481  map[1] = new double [num_locus]; // position
482 
483  // _map is a single static GeneticMap shared by all mappable traits and is
484  // keyed by trait type, so no instance/cast is needed to reach it.
485  bool found = TTProtoWithMap::_map.getGeneticMap(trait, map, num_locus);
486 
487  vector<unsigned int> & loc_list = table_trait_locus[tproto->get_index()];
488 
489  if( found ) {
490 
491  // MAP FORMAT : LOC NAME; chrmsm ID; position; Loc ID;
492  for(unsigned int k = 0; k < loc_list.size(); ++k) {
493  MAP<<trait<<"."<<loc_list[k]+1<<" "<<map[0][loc_list[k]]+1<<" "
494  <<map[1][loc_list[k]]<<" "<<loc_list[k]+1<<endl;
495  }
496 
497  } else { // trait didn't register a genetic map, loci are unlinked (free recombination)
498 
499  warning("genotyper::no genetic map found for trait %s, we'll assume the loci are unlinked,"
500  " separated by 50M and on a single chromosome\n", trait.c_str());
501 
502  // we're gonna set all loci on a single chrmsme, but 50M apart
503  for(unsigned int k = 0; k < loc_list.size(); ++k) {
504  MAP<<trait<<"."<<loc_list[k]+1<<" "<<map[0][loc_list[k]]+1<<" "
505  <<loc_list[k]*5000.0 + 1.0<<" "<<loc_list[k]+1<<endl;
506 }
507  }
508 
509  delete [] map [0];
510  delete [] map [1];
511  }
512 
513  MAP.close();
514  std::ios_base::sync_with_stdio(true); // reset
515 
516  } // end if(_format != "plink")
517 
518  // reset the pop ptr to the main pop
520 
521 }
std::string & get_path()
Definition: filehandler.h:142
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:150
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:102
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
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:466
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:112
bool getGeneticMap(trait_t trait, double **table, unsigned int table_length)
Definition: ttrait_with_map.cc:924
void prepare_data_table(map< unsigned int, vector< unsigned int > > &trait_locus, vector< string > &col_names)
Definition: servicenotifiers.cc:525
void print_PLINK(string file, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:747
string _format
Definition: servicenotifiers.h:113
vector< trait_t > _traits
Definition: servicenotifiers.h:111
void print_snp_genotypes(ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:656
void print_genotypes(ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:610
void print_snp_id(ofstream &FH, map< unsigned int, vector< unsigned int > > &table)
Definition: servicenotifiers.cc:702
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:139
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:308
static SimRunner * MainSim
Definition: simenv.h:41
Metapop * get_pop()
Accessor to the pop ptr.
Definition: simulation.h:177
static GeneticMap _map
Definition: ttrait_with_map.h:228
TTrait setter.
Definition: ttrait.h:130
virtual int get_locus_number()=0
Returns the number of locus.
virtual int get_index()
Index getter.
Definition: ttrait.h:151
void fatal(const char *str,...)
Definition: output.cc:99
void warning(const char *str,...)
Definition: output.cc:57

References _format, TTProtoWithMap::_map, FileHandler::_pop, _traits, fatal(), FileHandler::get_filename(), TraitPrototype::get_index(), TraitPrototype::get_locus_number(), FileHandler::get_path(), SimRunner::get_pop(), FileServices::get_pop_ptr(), FileHandler::get_service(), FileServices::getGenerationReplicateFileName(), GeneticMap::getGeneticMap(), FileServices::getSampledPop(), IndFactory::getTraitPrototype(), Metapop::isAlive(), SIMenv::MainSim, prepare_data_table(), print_genotypes(), print_PLINK(), print_snp_genotypes(), print_snp_id(), and warning().

◆ prepare_data_table()

void GenotyperFH::prepare_data_table ( map< unsigned int, vector< unsigned int > > &  trait_locus,
vector< string > &  col_names 
)
526 {
527  // write each trait separately, first fill-in the big table
528  // data table has as many rows as number of individuals in the pop
529  // number of columns is equal to tot number of loci + pathc-ID + sex + age + stage + ID
530  unsigned int num_locus = 0;
531  unsigned int num_ind = _pop->size();
532  unsigned int num_patch = _pop->getPatchNbr();
533  TraitPrototype* Tproto = 0;
534  TTrait* trait = 0;
535  Patch* patch = 0;
536  age_idx age_classes[2] = {OFFSx, ADLTx};
537  unsigned int trait_index;
538  double divider = 1.0/(num_ind * 2.0);
539  double p = 0;
540 
541 
542 
543  col_names.clear();
544 
545  // add header for first column = patch-id
546  col_names.push_back("pop");
547 
548 // // add 4 columns with individual info:
549  col_names.push_back("sex");
550  col_names.push_back("age");
551  col_names.push_back("stage");
552  col_names.push_back("ID");
553 
554  // create columns for number of loci per trait, prune loci with p < maf
555  for(auto trait_type : _traits) {
556 
557  Tproto = SIMenv::MainSim->get_pop()->getTraitPrototype(trait_type);
558 
559  if(!Tproto) fatal("Genotyper::could not access trait prototype in (sampled) pop for trait \"%s\"\n", trait_type.c_str() );
560 
561  num_locus = Tproto->get_locus_number();
562  trait_index = Tproto->get_index();
563 
564  // check allele frequencies in the population
565  for(unsigned int l = 0; l < num_locus; ++l) {
566 
567  // compute allele frequency in the whole population
568  p = 0;
569  for(unsigned int i = 0; i < num_patch; ++ i) {
570 
571  patch = _pop->getPatch(i);
572 
573  for(unsigned int a = 0; a < 2; ++a) {
574  for(unsigned int s = 0; s < 2; ++s) {
575  for(unsigned int j = 0; j < patch->size(sex_t(s),age_idx(age_classes[a])); ++j){
576 
577  trait = patch->get(sex_t(s), age_idx(age_classes[a]), j)->getTrait(trait_index);
578  // count the 1's
579  p += trait->get_allele(l, 1);
580  p += trait->get_allele(l, 0);
581  }
582  }
583  }
584  }
585 
586  p *= divider;
587 
588  if(p > _trim_maf && p < 1.0 - _trim_maf) {
589 
590  // add this locus to the list of polymorphic loci
591  trait_locus[trait_index].push_back(l);
592 
593  // add that locus to the table
594  if(_format == "snp_genotype") {
595  // write locus data in one column 0/1/2
596  col_names.push_back(trait_type + "." + to_string(l+1));
597  } else {
598  col_names.push_back(trait_type + "." + to_string(l+1) + "x");
599  col_names.push_back(trait_type + "." + to_string(l+1) + "y");
600  }
601  }
602  }
603  }
604 
605 
606 }
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:276
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
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
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
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
Interface for all trait types, declares all basic trait operations.
Definition: ttrait.h:45
virtual unsigned int get_allele(int loc, int all) const =0
Called to read the allele identity at a locus.
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
@ OFFSx
Definition: types.h:41
@ ADLTx
Definition: types.h:41

References _format, FileHandler::_pop, _traits, _trim_maf, ADLTx, fatal(), Patch::get(), TTrait::get_allele(), TraitPrototype::get_index(), TraitPrototype::get_locus_number(), SimRunner::get_pop(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), IndFactory::getTraitPrototype(), SIMenv::MainSim, OFFSx, Metapop::size(), and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ print_genotypes()

void GenotyperFH::print_genotypes ( ofstream &  FH,
map< unsigned int, vector< unsigned int > > &  table 
)
611 {
612 //cout<< ">>>>>> GenotyperFH::fill_genotypes\n";
613 
614  unsigned int num_patch = _pop->getPatchNbr();
615  TTrait* trait = 0;
616  Patch* patch;
617  Individual* ind;
618  age_idx age_classes[2] = {OFFSx, ADLTx};
619 
620  for(unsigned int i = 0; i < num_patch; ++ i) {
621 
622  patch = _pop->getPatch(i);
623 
624  for(unsigned int a = 0; a < 2; ++a) {
625 
626  for(unsigned int s = 0; s < 2; ++s) {
627 
628  for(unsigned int j = 0; j < patch->size(sex_t(s),age_idx(age_classes[a])); ++j){
629 
630  ind = patch->get(sex_t(s), age_idx(age_classes[a]), j);
631 
632  FH << patch->getID()+1 << " " << ind->getSex() << " " << ind->getAge() << " " << age_classes[a] << " " <<ind->getID();
633 
634  for(auto trait_index : _trait_index) {
635 
636  trait = ind->getTrait(trait_index);
637 
638  vector<unsigned int> & loc_list = table[trait_index];
639 
640  // write locus genotypes
641  for(unsigned int l = 0; l < loc_list.size(); ++l) {
642  FH << " " << trait->get_allele_value(loc_list[l], FEM);
643  FH << " " << trait->get_allele_value(loc_list[l], MAL);
644  } // end of loc loop
645  } // end for traits
646  FH << "\n";
647  } // end ind loop
648  } // end s loop
649  } // end a loop
650  } // end patch loop
651 
652 }
vector< unsigned int > _trait_index
Definition: servicenotifiers.h:112
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
unsigned long getID()
Definition: individual.h:121
unsigned short getAge()
Definition: individual.h:122
sex_t getSex()
Definition: individual.h:128
unsigned int getID()
Definition: metapop.h:480
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 FileHandler::_pop, _trait_index, ADLTx, FEM, Patch::get(), TTrait::get_allele_value(), Individual::getAge(), Individual::getID(), Patch::getID(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getSex(), Individual::getTrait(), MAL, OFFSx, and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ print_map_positions()

void GenotyperFH::print_map_positions ( ofstream &  FH,
vector< unsigned int > &  positions,
vector< string > &  col_names 
)

◆ print_PLINK()

void GenotyperFH::print_PLINK ( string  file,
map< unsigned int, vector< unsigned int > > &  table 
)
748 {
749  char BASE[2] = {'A','G'};
750  unsigned int num_patch = _pop->getPatchNbr();
751  TTrait* trait = 0;
752  Patch* patch;
753  Individual* ind;
754  age_idx age_classes[2] = {OFFSx, ADLTx};
755 
756 
757  ofstream FH(file, ios::out | ios::trunc);
758  std::ios_base::sync_with_stdio(false); // better for writing performances
759 
760  if(!FH) fatal("Genotyper::could not open genotype output file \"%s\"\n",file.c_str());
761 
762  // SPECIFICATION FOR THE .fam FILE = 6 first values in .ped files:
763 // .fam (PLINK sample information file)
764 //
765 // Sample information file accompanying a .bed binary genotype table.
766 // Also generated by "--recode lgen" and "--recode rlist".
767 //
768 // A text file with no header line, and one line per sample with the following six fields:
769 //
770 // 1. Family ID ('FID')
771 // 2. Within-family ID ('IID'; cannot be '0')
772 // 3. Within-family ID of father ('0' if father isn't in dataset)
773 // 4. Within-family ID of mother ('0' if mother isn't in dataset)
774 // 5. Sex code ('1' = male, '2' = female, '0' = unknown)
775 // 6. Phenotype value ('1' = control, '2' = case, '-9'/'0'/non-numeric = missing data if case/control)
776 //
777 // 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.
778 
779  for(unsigned int i = 0; i < num_patch; ++ i) {
780 
781  patch = _pop->getPatch(i);
782 
783  for(unsigned int a = 0; a < 2; ++a) {
784 
785  for(unsigned int s = 0; s < 2; ++s) {
786 
787  for(unsigned int j = 0; j < patch->size(sex_t(s),age_idx(age_classes[a])); ++j){
788 
789  ind = patch->get(sex_t(s), age_idx(age_classes[a]), j);
790 
791  FH<<"fam"<<ind->getHome()+1 <<" "<<ind->getID();
792 
793  if(age_idx(a) == OFFSx)
794  FH<<" "<<ind->getFatherID()<<" "<<ind->getMotherID(); //parents may be in file for offspring, although not guaranteed
795  else
796  FH<<" 0 0"; //parents not in file for adults
797 
798  // check if the quantitative trait is one of the traits called,
799  // if present, print the trait value (phenotype)
800  double phenotype = -9;
801 
802  for(auto trait_index : _trait_index) {
803 
804  trait = ind->getTrait(trait_index);
805 
806  if(trait->get_type() == "quant")
807  phenotype = ((double*)trait->getValue())[0];
808  }
809 
810  FH <<" 2 "<< phenotype;
811 
812  // now add the allele values for all traits
813  for(auto trait_index : _trait_index) {
814 
815  trait = ind->getTrait(trait_index);
816 
817  vector<unsigned int> & loc_list = table[trait_index];
818 
819  for(unsigned int l = 0; l < loc_list.size(); ++l) {
820  FH<<" "<< BASE[ trait->get_allele(loc_list[l], FEM) ]<<" "
821  << BASE[ trait->get_allele(loc_list[l], MAL) ]; // the maternally inherited allele comes first
822  }
823 
824  }
825  FH <<std::endl;
826  }
827  }
828  }
829  }
830 
831  FH.close();
832 
833  // the MAP file -------------------------------------------------------------------------
834  string filename = get_path() + this->get_service()->getGenerationReplicateFileName() + ".map";
835 
836  ofstream MAP (filename.c_str(), ios::out);
837 
838  if(!MAP) fatal("could not open plink .map output file!!\n");
839 
840  double *map[2];
841  TraitPrototype* tproto;
842 
843  // iterate the requested traits by name (like FHwrite); avoids relying on the
844  // 'ind' pointer left over from the individual-writing loop above.
845  for(auto trait : _traits) {
846 
847  tproto = SIMenv::MainSim->get_pop()->getTraitPrototype(trait);
848 
849  unsigned int num_locus = tproto->get_locus_number();
850 
851  map[0] = new double [num_locus];
852  map[1] = new double [num_locus];
853 
854  // _map is a single static GeneticMap shared by all mappable traits and is
855  // keyed by trait type, so no instance/cast is needed to reach it.
856  bool found = TTProtoWithMap::_map.getGeneticMap(trait, map, num_locus);
857 
858  vector<unsigned int> & loc_list = table[tproto->get_index()];
859 
860  if( found ) {
861 
862  // MAP FORMAT (PLINK1.9): chrmsm ID; Loc ID; position (cM); bp ID
863  for(unsigned int k = 0; k < loc_list.size(); ++k) {
864  MAP<<map[0][loc_list[k]]+1<<" "<<trait<<"."<<loc_list[k]+1
865  <<" "<<map[1][loc_list[k]]<<" "<<loc_list[k]+1<<endl;
866  }
867  } else { // trait didn't register a genetic map, loci are unlinked (free recombination)
868 
869  warning("PLINK .map file: no genetic map found for trait %s, we'll assume loci are unlinked, "
870  " separated by 50M and on a single chromosome\n", trait.c_str());
871  // we're gonna set all loci on a single chrmsme, but 50M apart
872  for(unsigned int k = 0; k < loc_list.size(); ++k) {
873  MAP<<"1 "<<trait<<"."<<loc_list[k]+1<<" "<< loc_list[k]*5000.0 + 1.0<<" "<<loc_list[k]+1<<endl;
874  }
875  }
876 
877  delete [] map [0];
878  delete [] map [1];
879  }
880 
881  MAP.close();
882  std::ios_base::sync_with_stdio(true); // reset
883 }
unsigned short getHome()
Definition: individual.h:127
unsigned long getMotherID()
Definition: individual.h:124
unsigned long getFatherID()
Definition: individual.h:123
virtual void * getValue() const =0
Genotype to phenotype mapper.
virtual trait_t get_type() const =0
type accessor.

References TTProtoWithMap::_map, FileHandler::_pop, _trait_index, _traits, ADLTx, fatal(), FEM, Patch::get(), TTrait::get_allele(), TraitPrototype::get_index(), TraitPrototype::get_locus_number(), FileHandler::get_path(), SimRunner::get_pop(), FileHandler::get_service(), TTrait::get_type(), Individual::getFatherID(), FileServices::getGenerationReplicateFileName(), GeneticMap::getGeneticMap(), Individual::getHome(), Individual::getID(), Individual::getMotherID(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getTrait(), IndFactory::getTraitPrototype(), TTrait::getValue(), SIMenv::MainSim, MAL, OFFSx, Patch::size(), and warning().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ print_snp_genotypes()

void GenotyperFH::print_snp_genotypes ( ofstream &  FH,
map< unsigned int, vector< unsigned int > > &  table 
)
657 {
658 // cout<< ">>>>>> GenotyperFH::fill_snp_genotypes\n";
659  unsigned int num_patch = _pop->getPatchNbr();
660  TTrait* trait = 0;
661  Patch* patch;
662  Individual* ind;
663  age_idx age_classes[2] = {OFFSx, ADLTx};
664 
665  for(unsigned int i = 0; i < num_patch; ++ i) {
666 
667  patch = _pop->getPatch(i);
668 
669  for(unsigned int a = 0; a < 2; ++a) {
670 
671  for(unsigned int s = 0; s < 2; ++s) {
672 
673  for(unsigned int j = 0; j < patch->size(sex_t(s),age_idx(age_classes[a])); ++j){
674 
675  ind = patch->get(sex_t(s), age_idx(age_classes[a]), j);
676 
677  FH << patch->getID()+1 << " " << ind->getSex() << " " << ind->getAge() << " " << age_classes[a] << " " <<ind->getID();
678 
679  for(auto trait_index : _trait_index) {
680 
681  trait = ind->getTrait(trait_index);
682 
683  vector<unsigned int> & loc_list = table[trait_index];
684 
685  // write locus snp genotype 0/1/2
686  for(unsigned int l = 0, a, b; l < loc_list.size(); ++l) {
687  a = trait->get_allele(loc_list[l], FEM);
688  b = trait->get_allele(loc_list[l], MAL);
689  FH << " " << a + b;
690  } // end of loc loop
691  } // end for traits
692  FH << "\n";
693  } // end ind loop
694  } // end s loop
695  } // end a loop
696  } // end patch loop
697 
698 }

References FileHandler::_pop, _trait_index, ADLTx, FEM, Patch::get(), TTrait::get_allele(), Individual::getAge(), Individual::getID(), Patch::getID(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getSex(), Individual::getTrait(), MAL, OFFSx, and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ print_snp_id()

void GenotyperFH::print_snp_id ( ofstream &  FH,
map< unsigned int, vector< unsigned int > > &  table 
)
703 {
704 // cout<< ">>>>>> GenotyperFH::fill_snp_id\n";
705  unsigned int num_patch = _pop->getPatchNbr();
706  TTrait* trait = 0;
707  Patch* patch;
708  Individual* ind;
709  age_idx age_classes[2] = {OFFSx, ADLTx};
710 
711  for(unsigned int i = 0; i < num_patch; ++ i) {
712 
713  patch = _pop->getPatch(i);
714 
715  for(unsigned int a = 0; a < 2; ++a) {
716 
717  for(unsigned int s = 0; s < 2; ++s) {
718 
719  for(unsigned int j = 0; j < patch->size(sex_t(s),age_idx(age_classes[a])); ++j){
720 
721  ind = patch->get(sex_t(s), age_idx(age_classes[a]), j);
722 
723  FH << patch->getID()+1 << " " << ind->getSex() << " " << ind->getAge() << " " << age_classes[a] << " " <<ind->getID();
724 
725  for(auto trait_index : _trait_index) {
726 
727  trait = ind->getTrait(trait_index);
728 
729  vector<unsigned int> & loc_list = table[trait_index];
730 
731  // write locus genotypes
732  for(unsigned int l = 0; l < loc_list.size(); ++l) {
733  FH << " " << trait->get_allele(loc_list[l], FEM);
734  FH << " " << trait->get_allele(loc_list[l], MAL);
735  } // end of loc loop
736  } // end for traits
737  FH << "\n";
738  } // end ind loop
739  } // end s loop
740  } // end a loop
741  } // end patch loop
742 }

References FileHandler::_pop, _trait_index, ADLTx, FEM, Patch::get(), TTrait::get_allele(), Individual::getAge(), Individual::getID(), Patch::getID(), Metapop::getPatch(), Metapop::getPatchNbr(), Individual::getSex(), Individual::getTrait(), MAL, OFFSx, and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ set_isDiallelic()

void GenotyperFH::set_isDiallelic ( bool  test)
inline
135 {_is_diallelic = test;}

References _is_diallelic.

Referenced by LCE_FileServicesNotifier::setGenotyperParameters().

+ Here is the caller graph for this function:

◆ set_trimFixedLoci()

void GenotyperFH::set_trimFixedLoci ( bool  test,
double  maf 
)
inline
137 {_trim_loci = test; _trim_maf = maf;}

References _trim_loci, and _trim_maf.

Referenced by LCE_FileServicesNotifier::setGenotyperParameters().

+ Here is the caller graph for this function:

◆ setFormat()

void GenotyperFH::setFormat ( string  format)
inline
131 {_format = format;}

References _format.

Referenced by LCE_FileServicesNotifier::setGenotyperParameters().

+ Here is the caller graph for this function:

◆ setLogtime()

void GenotyperFH::setLogtime ( string  logtime)
inline
133 {_logtime = logtime;}
string _logtime
Definition: servicenotifiers.h:114

References _logtime.

◆ setTraitIndex()

void GenotyperFH::setTraitIndex ( vector< unsigned int > &  indices)
395 {
396  _trait_index.assign(traits.begin(), traits.end());
397 }

References _trait_index.

Referenced by LCE_FileServicesNotifier::setGenotyperParameters().

+ Here is the caller graph for this function:

◆ setTraits()

void GenotyperFH::setTraits ( vector< trait_t > &  traits)
388 {
389  _traits.assign(traits.begin(), traits.end());
390 }

References _traits.

Referenced by LCE_FileServicesNotifier::setGenotyperParameters().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _format

string GenotyperFH::_format
private

◆ _is_diallelic

bool GenotyperFH::_is_diallelic
private

Referenced by set_isDiallelic().

◆ _logtime

string GenotyperFH::_logtime
private

Referenced by setLogtime().

◆ _trait_index

vector< unsigned int > GenotyperFH::_trait_index
private

◆ _traits

vector< trait_t > GenotyperFH::_traits
private

◆ _trim_loci

bool GenotyperFH::_trim_loci
private

Referenced by set_trimFixedLoci().

◆ _trim_maf

double GenotyperFH::_trim_maf
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