Nemo  2.4.2
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
119 : EventFileHandler(event, "") , _is_diallelic(0), _trim_loci(0), _trim_maf(0) {}
EventFileHandler(LCE_FileServicesNotifier *event, const char *ext)
Definition: filehandler.h:270
bool _is_diallelic
Definition: servicenotifiers.h:114
double _trim_maf
Definition: servicenotifiers.h:116
bool _trim_loci
Definition: servicenotifiers.h:115

◆ ~GenotyperFH()

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

Member Function Documentation

◆ FHread()

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

Implements FileHandler.

124 {}

◆ FHwrite()

void GenotyperFH::FHwrite ( )
virtual

Implements EventFileHandler< LCE_FileServicesNotifier >.

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

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

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

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

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

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
134 {_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
136 {_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
130 {_format = format;}

References _format.

Referenced by LCE_FileServicesNotifier::setGenotyperParameters().

+ Here is the caller graph for this function:

◆ setLogtime()

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

References _logtime.

◆ setTraitIndex()

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

References _trait_index.

Referenced by LCE_FileServicesNotifier::setGenotyperParameters().

+ Here is the caller graph for this function:

◆ setTraits()

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

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

Catalogued on GSR