-
Notifications
You must be signed in to change notification settings - Fork 0
/
Individual.h
144 lines (113 loc) · 4.87 KB
/
Individual.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Individual.h
* admixsimul
*
* Created by Rosenthal Lab on 11/21/11.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <math.h>
#include <iterator>
#include <map>
//#include "def.h"
#include "makemarkerfile.h"
#include "newran02/newran.h"
#include "config.h"
#include "maths.h"
//#include "Population.h"
#pragma once
#ifndef _INDIVIDUAL_FILE
#define _INDIVIDUAL_FILE 0
using namespace std;
struct GeneticLocus {
//int Chromosome;
//double Position;
char Ancestry;
char Allele;
};
struct Marker: public GeneticLocus {
};
struct Gene: public GeneticLocus {
double Value;
};
/*
class Chromosome {
private:
double _nTotalLen;
double _nCentromerePos; // position of the centromere.
};
class Genome {
public:
void BuildGenome( Chromosome * pPaternalGamete, Chromosome * pMaternalGamete);
private:
int _n; // n = ? ploidy is always 2.
Chromosome* Chromosomes; // size will be 2n. Odd number and the next even number are homologs.
};
*/
class Individual {
public:
Individual(void);
Individual(void * pPop, char nAncestryLabel); //constructor for founders
Individual(Individual * pFather, Individual * pMother, bool &bSuccess); //Constructor . Fertilize a new individual given parents
enum Sex {Male, Female};
//Genome CurrentGenome;
~Individual(void);
//Public methods
bool Court(Individual * pChooser); // Only available to males
double EvaluateCourter(Individual * pCourter); //Assign a probability for the female to mate with the given courter. This is the preference function of the female.
int HandleCourter(Individual * pCourter, bool bIgnoreGlobalRules); // Handling the courtship. Only available to females. EvaluateCourter() will be called, then self condition will also be considered. If accepted, will inseminate some eggs. return value are the eggs inseminated
Sex GetSex();
unsigned long long int GetID();
unsigned long long int GetFatherId();
unsigned long long int GetMotherId();
int GetGameteNum();
int GetMateNumber();
double GetPhenotype(string sPhenotype);
void GetGamete(vector< vector<Marker> > &vMarkers, vector< vector<Gene> > &vGenes );
void GiveBirth(vector<Individual *> &vOffSprings, int nNum, bool bIgnoreGlobalRules); // give birth to any number inseminated eggs, pass -1 to nNum to get all. this takes a lot of memory so be careful.
void DumpMarkers(ofstream &fOutFile, int nChromosomeSide); // write all markers to file stream. each chromosome separated by -1.
void DumpGenes(ofstream &fOutFile, int nChromosomeSide); // write all markers to file stream. each chromosome separated by -1.
void DumpPhenotypes(ofstream &fOutFile);
void WritePhenotypeHeader(ofstream &fOutFile);
bool IsDead();
void Die(); // sets the dead flag
void ChangePopulation(void * pPop);
void * GetPop();
void * GetPrevPop(); //What is the prev pop? If the individual migrated, then prev pop will differ from the current.
//friend class Individual;
//void GetGamete( Chromosome * pGamete);
private:
void fnDetermineSex();
void fnDeterminePhenotypes();
void fnDetermineNumGametes(); //determines how many gametes does this female have.
bool fnSetParserPopWide(Parser * pParser, vector<string> &vSymbols, const string &sPrefix, map< string , pair< double, double> > &mpSumPhenotypes);
unsigned long long int _nFatherId; //id of father
unsigned long long int _nMotherId; //id of mother
unsigned long long int _nId; // fish id
void * _pPop; //pointer to the current population it's living in.
void * _pPrevPop; // pointer to the previous population, before migration. this is relavant in oblique imprinting, where the individual learned before migration.
Sex _bSex;
bool _bMatured;
bool _bDead;
double _nCondition; //Condition of fish
double _nAge; //Age of the individual
unsigned int _nAvailableGametes; // how many more gametes available? Only meaningful for females. males have unlimited num of gametes (-1)
int _nHaploidChrNum;
int _nTotalChrNum;
std::map<string, double > _mpPhenotypes; // map recording phenotypic values directly calculated from genotypic values;
std::map<string, double > _mpEnvPhenotypes; // Phenotypes with added enviromental variations NOT USED
std::map<string, double > _mpDadPhenotypes; //father's phenotypes, useful for imprinting
std::map<string, double > _mpMomPhenotypes; //mother's phenotypes, useful for imprinting
//map<double, Marker> * _pmMarkers; // 2n chromosomes, each element in vector is one chromosome, the map are indexed by absolute positions on that chromosome
vector< vector<Marker> > _arrMarkers; // 2n chromosomes, each
//map<double, Gene> * _pmGenes; // same structured as above
vector< vector<Gene> > _arrGenes; // 2n chromosomes, each
vector<Individual *> _arrOtherParentsForOffsprings;// the fatherhoods of each inseminated egg.
};
#endif