-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComputeFst_core.cpp
152 lines (103 loc) · 3.56 KB
/
ComputeFst_core.cpp
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
145
146
147
148
149
150
151
152
/*
* ComputeFst_core
* Date: Jan-24-2013
* Author : Gabriel Renaud gabriel.reno [at sign here ] gmail.com
*
*/
#include "ComputeFst_core.h"
// #define DEBUG3
// damage (<-)
// transition (<->)
// A --------- G
// | |
// | |
// | |
// | |
// C --------- T
// transition (<->)
// damage ( ->)
inline bool isTransition(char allel_sample,char allel_reference,char allel_chimpHumanAncestor){
return (
(allel_sample == 'C' && (allel_reference == 'T' || (allel_chimpHumanAncestor == 'T') ) ) ||
(allel_sample == 'T' && (allel_reference == 'C' || (allel_chimpHumanAncestor == 'C') ) ) ||
(allel_sample == 'A' && (allel_reference == 'G' || (allel_chimpHumanAncestor == 'G') ) ) ||
(allel_sample == 'G' && (allel_reference == 'A' || (allel_chimpHumanAncestor == 'A') ) )
);
}
inline bool isDamage(char allel_sample,char allel_reference,char allel_chimpHumanAncestor){
return (
(allel_sample == 'T' && (allel_reference == 'C' || (allel_chimpHumanAncestor == 'C') ) ) ||
(allel_sample == 'A' && (allel_reference == 'G' || (allel_chimpHumanAncestor == 'G') ) )
);
}
void computeFst(char allel_chimpHumanAncestor,char allel_reference,char allel_sample,bool isCpG,FstResult * fstr){
if( (allel_chimpHumanAncestor == allel_reference ) && //no mutation
(allel_chimpHumanAncestor == allel_sample ) ){
//no need to call isTransition() isDamage() since no mutation
fstr->all.counterSame++;
if(isCpG)
fstr->onlyCpg.counterSame++;
else
fstr->noCpg.counterSame++;
}
if( (allel_chimpHumanAncestor != allel_reference ) || //mutation occured
(allel_chimpHumanAncestor != allel_sample ) ){
if(allel_reference == allel_sample){ //common
#ifdef DEBUG3
cout<<"common"<<endl;
#endif
if(isTransition(allel_sample,allel_reference,allel_chimpHumanAncestor)){
fstr->transitions.counterCommon++;
}else{
fstr->transversions.counterCommon++;
}
if(!isDamage( allel_sample,allel_reference,allel_chimpHumanAncestor)){
fstr->noDamage.counterCommon++;
}else{
}
fstr->all.counterCommon++;
if(isCpG)
fstr->onlyCpg.counterCommon++;
else
fstr->noCpg.counterCommon++;
}
if( (allel_chimpHumanAncestor == allel_reference ) && //mutation occured in sample
(allel_chimpHumanAncestor != allel_sample ) ){
#ifdef DEBUG3
cout<<"sample"<<endl;
#endif
if(isTransition(allel_sample,allel_reference,allel_chimpHumanAncestor)){
fstr->transitions.counterSample++;
}else{
fstr->transversions.counterSample++;
}
if(!isDamage( allel_sample,allel_reference,allel_chimpHumanAncestor)){
fstr->noDamage.counterSample++;
}
fstr->all.counterSample++;
if(isCpG)
fstr->onlyCpg.counterSample++;
else
fstr->noCpg.counterSample++;
}
if( (allel_chimpHumanAncestor != allel_reference ) && //mutation occured in reference
(allel_chimpHumanAncestor == allel_sample ) ){
#ifdef DEBUG3
cout<<"reference"<<endl;
#endif
if(isTransition(allel_sample,allel_reference,allel_chimpHumanAncestor)){
fstr->transitions.counterReference++;
}else{
fstr->transversions.counterReference++;
}
if(!isDamage( allel_sample,allel_reference,allel_chimpHumanAncestor)){
fstr->noDamage.counterReference++;
}
fstr->all.counterReference++;
if(isCpG)
fstr->onlyCpg.counterReference++;
else
fstr->noCpg.counterReference++;
}
}
}