forked from tbrown91/SimBac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecomb_prob.h
127 lines (123 loc) · 4.48 KB
/
recomb_prob.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
//Copyright (C) 2015 Thomas Brown, Xavier Didelot, Daniel J. Wilson, Nicola De Maio
//
// This file is part of SimBac.
//
// SimBac is free software: you can redistribute it and/or modify
// it under the terms of the
// General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SimBac is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SimBac. If not, see <http://www.gnu.org/licenses/>.
#ifndef RECOMB_PROB
#define RECOMB_PROB
#include <math.h>
void calc_nonClonalRecomb(const int G, const double delta, vector<double> &prob, double &recombRate, const list<int> &starts, const list<int> &ends, const double noStop, const double siteRecomb, int &totMaterial){
//Total amount of ancestral material in the node
list<int>::const_iterator itStart = starts.begin(), itEnd = ends.begin();
totMaterial = 0;
int b = starts.size();
//Reset recombination rate and probability of recombination along the genome
prob.clear();
recombRate = 0.0;
if (starts.size() == 0) return;
while (itStart != starts.end()){
totMaterial += (*itEnd - *itStart) + 1;
++itStart;
++itEnd;
}
if (totMaterial <= 1) return;
if ((starts.front() == 0) && (ends.back() == G-1)){
//Interval wraps around the end of the genome
if (b > 1){
prob.push_back(0.0);
itStart = starts.begin();
itEnd = ends.begin();
++itStart;
while (itStart != starts.end()){
prob.push_back(siteRecomb*delta*(1-pow(noStop,*itStart-*itEnd))*(1-pow(noStop,G-*itStart+*itEnd)));
recombRate += prob.back();
++itStart;
++itEnd;
}
recombRate += siteRecomb*(totMaterial-(b-1))*(1-pow(noStop,G-1));
prob[0] = siteRecomb*(1-pow(noStop,G-1));
}else{
//Interval is the entire genome
recombRate = siteRecomb*totMaterial*(1-pow(noStop,G-1));
prob.push_back(siteRecomb*(1-pow(noStop,G-1)));
}
}else{
//Intervals are contained within the genome
prob.push_back(siteRecomb*delta*(1-pow(noStop,G+starts.front()-ends.back()))*(1-pow(noStop,ends.back()-starts.front())));
recombRate += prob[0];
itStart = starts.begin();
itEnd = ends.begin();
++itStart;
while (itStart != starts.end()){
prob.push_back(siteRecomb*delta*(1-pow(noStop,*itStart-*itEnd))*(1-pow(noStop,G-*itStart+*itEnd)));
recombRate += prob.back();
++itStart;
++itEnd;
}
recombRate += siteRecomb*(totMaterial-b)*(1-pow(noStop,G-1));
}
}
void calc_clonalRecomb(const int G, const double delta, vector<double> &prob, double &recombRate, const list<int> &starts, const list<int> &ends, const double noStop, const double siteRecomb, int &totMaterial){
//Total amount of ancestral material in the node
list<int>::const_iterator itStart = starts.begin(), itEnd = ends.begin();
totMaterial = 0;
int b = starts.size();
//Reset recombination rate and probability of recombination along the genome
prob.clear();
recombRate = 0;
if (starts.size() == 0) return;
while (itStart != starts.end()){
totMaterial += (*itEnd - *itStart) + 1;
++itStart;
++itEnd;
}
if (totMaterial <= 1) return;
if ((starts.front() == 0) && (ends.back() == G-1)){
//Interval wraps around the end of the genome
if (b > 1){
prob.push_back(0.0);
itStart = starts.begin();
itEnd = ends.begin();
++itStart;
while (itStart != starts.end()){
prob.push_back(siteRecomb*delta*(1-pow(noStop,*itStart-*itEnd)));
recombRate += prob.back();
++itStart;
++itEnd;
}
recombRate += siteRecomb*(totMaterial-(b-1));
prob[0] = siteRecomb;
}else{
//Interval is the entire genome
recombRate = siteRecomb*totMaterial;
prob.push_back(siteRecomb);
}
}else{
//Intervals are contained within the genome
prob.push_back(siteRecomb*delta*(1-pow(noStop,G+starts.front()-ends.back())));
recombRate += prob[0];
itStart = starts.begin();
itEnd = ends.begin();
++itStart;
while (itStart != starts.end()){
prob.push_back(siteRecomb*delta*(1-pow(noStop,*itStart-*itEnd)));
recombRate += prob.back();
++itStart;
++itEnd;
}
recombRate += siteRecomb*(totMaterial-b);
}
}
#endif