Skip to content

Commit 0f5a6ef

Browse files
committed
Beta binomial
1 parent 5f352e6 commit 0f5a6ef

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set( pmh_hdr
3939
set( simulation_hdr
4040
src/simulation/cell.h
4141
src/simulation/celltree.h
42+
src/simulation/beta_distribution.hpp
4243
src/nonbinaryclonetree.h
4344
src/clonetree.h
4445
src/binarytree.h

src/simulation/celltree.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "celltree.h"
9+
#include "beta_distribution.hpp"
910

1011
CellTree::CellTree(double K,
1112
double migrationRate,
@@ -173,7 +174,15 @@ void CellTree::simulateReadCounts()
173174

174175
int coverage = poisson(g_rng);
175176
// divide 2, heterozygous diploid
176-
std::binomial_distribution<> binom(coverage, _freq[s][p][i] / 2);
177+
double f = _freq[s][p][i] / 2;
178+
int alpha = std::min(1, int(f * 100));
179+
int beta = 100 - alpha;
180+
181+
sftrabbit::beta_distribution<> beta_dist(alpha, beta);
182+
double ff = beta_dist(g_rng);
183+
184+
// std::binomial_distribution<> binom(coverage, f);
185+
std::binomial_distribution<> binom(coverage, ff);
177186
_var[s][p][i] = binom(g_rng);
178187
_ref[s][p][i] = coverage - _var[s][p][i];
179188
}
@@ -187,16 +196,20 @@ void CellTree::writeReadCounts(std::ostream& out) const
187196
{
188197
int nrMutations = getNrMutations();
189198

190-
out << _nrAnatomicalSites << " #anatomical sites" << std::endl;
199+
out << _nrActiveAnatomicalSites << " #anatomical sites" << std::endl;
191200
out << _nrSamplesPerAnatomicalSite * _nrAnatomicalSites << " #samples" << std::endl;
192201
out << nrMutations << " #mutations" << std::endl;
193202

194203
out << "#sample_index\tsample_label\tanatomical_site_index\tanatomical_site_label"\
195204
"\tcharacter_index\tcharacter_label\tref\tvar" << std::endl;
196205

197206
char buf[1024];
207+
int activeSiteIndex = 0;
198208
for (int s = 0; s < _nrAnatomicalSites; ++s)
199209
{
210+
if (!_isActiveAnatomicalSite[s])
211+
continue;
212+
200213
std::string label_s;
201214
if (s == 0)
202215
{
@@ -210,18 +223,20 @@ void CellTree::writeReadCounts(std::ostream& out) const
210223

211224
for (int p = 0; p < _nrSamplesPerAnatomicalSite; ++p)
212225
{
213-
int pp = s * _nrSamplesPerAnatomicalSite + p;
226+
int pp = activeSiteIndex * _nrSamplesPerAnatomicalSite + p;
214227

215228
snprintf(buf, 1024, "%s_%d", label_s.c_str(), p);
216229
std::string label_p = buf;
217230
for (int i = 0; i < nrMutations; ++i)
218231
{
219232
out << pp << "\t" << label_p << "\t"
220-
<< s << "\t" << label_s << "\t"
233+
<< activeSiteIndex << "\t" << label_s << "\t"
221234
<< i << "\t" << i << "\t"
222235
<< _ref[s][p][i] << "\t" << _var[s][p][i] << std::endl;
223236
}
224237
}
238+
239+
++activeSiteIndex;
225240
}
226241
}
227242

src/simulation/simulationmain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int main(int argc, char** argv)
138138
mutFreqThreshold,
139139
maxNrAnatomicalSites,
140140
2,
141-
160,
141+
200,
142142
migrationPattern);
143143
if (cellTree.simulate(true))
144144
{
@@ -158,7 +158,7 @@ int main(int argc, char** argv)
158158
mutFreqThreshold,
159159
maxNrAnatomicalSites,
160160
2,
161-
160,
161+
200,
162162
migrationPattern);
163163
if (cellTree.simulate(false))
164164
{
@@ -174,6 +174,7 @@ int main(int argc, char** argv)
174174
std::cout << "FAILURE" << std::endl;
175175
}
176176
}
177+
else
177178
{
178179
std::cout << "FAILURE" << std::endl;
179180
}

0 commit comments

Comments
 (0)