forked from benlerch1/IMPUTE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
impute.h
61 lines (45 loc) · 1.46 KB
/
impute.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
#include "VcfFileReader.h"
#include "StringBasics.h"
#include "StringHash.h"
#include "MemoryAllocators.h"
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <iostream> // std::cout, std::endl
#include <iomanip>
using namespace std
// Load Genotypes
// Run HMM
// HMM Functions
void Transpose(int StudyHap, double * Sfrom, double * Sto, double &theta)
{
// For each study haplotype: StudyHap
// Calculate the current state probabilities transitioned from a previous position with probability vector Sfrom
// State space is consisted of N_r reference haplotypes
// Sfrom, Sto is a vector of size N_r, Sfrom[i] is the probability of being in the state of reference haplotype S_i, i= 1, ..., N_r, on previous marker position
// theta is transition rate, i.e., recombination rate, assume it is the same for all markers
int Nr = Sfrom->size(); // total number of reference haplotypes
double p_sum; // sum of vector Sfrom
if (theta == 0) {
for (int i=0; i < Nr; i++) {
Sto[i] = Sfrom[i];
}
}
else{
p_sum = 0.0;
for (int j=0; j < Nr; j++) {
p_sum += Sfrom[j];
}
p_sum *= theta / (double)N_r;
double q = 1.0 - theta;
if (p_sum < 1e-10) {
p_sum *= 1e15;
q *= 1e15;
}
for(int i = 0; i < Nr; i++){
Sto[i] = q * Sfrom[i] + p_sum;
}
}
return;
}
// Impute