4
genotype::~genotype(){}
8
void zvar::setPopName(string popName){
14
double pooled::bound(double v){
110
// polymorphism for GL and PL
112
double gt::unphred(map< string, vector<string> > & geno, int index){
116
double gl::unphred(map< string, vector<string> > & geno, int index){
118
double unphreded = atof(geno["GL"][index].c_str());
122
double gp::unphred(map< string, vector<string> > & geno, int index){
124
double unphreded = atof(geno["GP"][index].c_str());
125
return log(unphreded) ;
128
double pl::unphred(map< string, vector<string> > & geno, int index){
130
double unphreded = atof(geno["PL"][index].c_str());
132
unphreded = log(pow(10, (-unphreded/10)));
137
void pooled::loadPop(vector< map< string, vector<string> > > & group, string seqid, long int position){
138
vector< map< string, vector<string> > >::iterator targ_it = group.begin();
141
for(; targ_it != group.end(); targ_it++){
143
string genotype = (*targ_it)["GT"].front();
145
if(genotype == "./."){
149
string allelecounts = (*targ_it)["AD"].front();
151
vector<string> ac = (*targ_it)["AD"];
156
double af = atof(ac[1].c_str()) / ( atof(ac[0].c_str()) + atof(ac[1].c_str()) );
158
if(atof(ac[1].c_str()) == 0){
161
if(atof(ac[0].c_str()) == 0){
169
nrefs.push_back(atof(ac[0].c_str()));
170
nalts.push_back(atof(ac[1].c_str()));
172
nref += atof(ac[0].c_str());
173
ntot += atof(ac[0].c_str());
174
nalt += atof(ac[1].c_str());
175
ntot += atof(ac[1].c_str());
185
void genotype::estimatePosterior(void){
187
int ng = genoIndex.size();
189
for(int i = 0 ; i < ng; i++){
191
if(genoIndex[i] == -1){
195
double aa = genoLikelihoods[i][0] ;
196
double ab = genoLikelihoods[i][1] ;
197
double bb = genoLikelihoods[i][2] ;
202
alpha += 2 * exp(aa);
209
void pooled::estimatePosterior(void){
212
cerr << "FATAL: not enough pooled populations in the target or background\n";
219
for(int i = 0 ; i < npop; i++){
220
ss += pow(( afs[i] - xbar),2);
223
double var = (1/(npop-1))*ss;
229
if(var < xbar*(1-xbar)){
230
alpha = xbar * (((xbar*(1-xbar))/var) -1);
231
beta = (1 - xbar) * (((xbar*(1-xbar))/var) -1);
239
void genotype::loadPop( vector< map< string, vector<string> > >& group, string seqid, long int position){
244
vector< map< string, vector<string> > >::iterator targ_it = group.begin();
246
for(; targ_it != group.end(); targ_it++){
248
string genotype = (*targ_it)["GT"].front();
250
gts.push_back(genotype);
252
vector<double> phreds;
253
vector<double> phredsCDF;
256
if(genotype != "./."){
258
double pa = unphred( (*targ_it), 0) ;
259
double pab = unphred( (*targ_it), 1) ;
260
double pbb = unphred( (*targ_it), 2) ;
262
double norm = log(exp(pa) + exp(pab) + exp(pbb)) ;
264
phreds.push_back(pa - norm);
265
phreds.push_back(pab - norm);
266
phreds.push_back(pbb - norm);
269
// cerr << exp(pa - norm) << endl;
270
// cerr << exp(pab - norm) << endl;
271
// cerr << exp(pbb - norm) << endl;
274
sum += exp(pa - norm);
275
// cerr << sum << endl;
276
phredsCDF.push_back(sum);
277
sum += exp(pab - norm);
278
// cerr << sum << endl;
279
phredsCDF.push_back(sum);
280
sum += exp(pbb - norm);
281
// cerr << sum << endl;
283
phredsCDF.push_back(sum);
286
phreds.push_back(log(1/3));
287
phreds.push_back(log(1/3));
288
phreds.push_back(log(1/3));
289
phredsCDF.push_back(1/3);
290
phredsCDF.push_back(2/3);
291
phredsCDF.push_back(1);
294
genoLikelihoods.push_back(phreds);
295
genoLikelihoodsCDF.push_back(phredsCDF);
297
if(genotype == "./0" || genotype == "./1"){
302
if(genotype == "./."){
303
genoIndex.push_back(-1);
306
if(genotype == "0/0"){
310
genoIndex.push_back(0);
313
if(genotype == "0/1"){
318
genoIndex.push_back(1);
321
if(genotype == "1/0"){
326
genoIndex.push_back(1);
329
if(genotype == "1/1"){
333
genoIndex.push_back(2);
336
if(genotype == "0|0"){
340
genoIndex.push_back(0);
343
if(genotype == "0|1"){
348
genoIndex.push_back(1);
351
if(genotype == "1|0"){
356
genoIndex.push_back(1);
359
if(genotype == "1|1"){
363
genoIndex.push_back(2);
366
cerr << "FATAL: unknown genotype: " << genotype << endl;
370
if(nalt == 0 && nref == 0){
374
af = (nalt / (nref + nalt));
377
fis = ( 1 - ((nhet/ngeno) / (2*af*(1 - af))));