-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
219 lines (202 loc) · 6.53 KB
/
main.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <list>
#include "common.h"
#include "TissueVolume.h"
using namespace std;
using namespace adevs;
/********************************************************************************
Basis Information:
The diameter of your esophagus is 24mm, the diameter of a quarter.
The thickness of your esophageal wall is 4mm, the width of 3 pennies.
We will use 24 mm in our simulation which gives the circumference to be 75.4 mm.
The grid width is 0.42 mm for ni = 179 or 0.21 mm for ni = 359.
Jumbo biopsy is about 5mmx3mm (12 by 7 grid) or (24 by 14 grid).
This model is based closely on the one appearing in
Kit Curtius, William D. Hazelton, Jihyoun Jeon, and E. Georg Luebeck (2015)
A Multiscale Model Evaluates Screening for Neoplasia in Barret's Esophagus
PLOS Computational Biology 11(5):e1004272. doi 10.1371/journal.pcbi.100472.
The essential operation of the model is as follows:
A grid of TissueVolume models is created. Each TissueVolume on the surface
of the esophagus section being looked at begins life with BE. Everything
below the surface is NORMAL.
At some point (possibly too far into the future to matter) some of the BE volumes
will mutate into DYSPLASIA. Then the DYSPLASIA volumes will mutate into CANCER.
The DYSPLASIA volumes will spread into other parts of the BE volume. The CANCER
volumes will spread into NORMAL and DYSPLASIA volumes.
The tumor grows via these two processes of mutation and growth. All of the
growth and mutation rules can be found in the TumorVolume class.
********************************************************************************/
#define NUM_LAYERS 5
// Fractional thickness of each layer
static const double LayerThicknessFraction[NUM_LAYERS] =
{
0.2, // Epithelium
0.1, // Basement membrane
0.2, // Lamina propia
0.1, // Mucular mucosaa
0.4 // Submucosa
};
static const double grid_size = 0.42; // mm
static const double thickness = 4.0; // mm
static const double circumference = 75.4; // mm
static const double length = 250.0; // mm
static const int ni = (circumference / grid_size)+1; // Spatial points in X direction.
static const int nj = (length / grid_size)+1; // Spatial points in Y direction.
static const int nk = (thickness / grid_size)+1; // Spatial points in Z direction.
// The TissueVolume objects in this CellSpace comprise the dynamic part of the model
static CellSpace<int>* tissue;
// The Simulator handles time management, etc.
static Simulator<CellEvent<int> >* sim;
// File for parameters not hard coded into the model.
static std::string inputData = "input.txt";
// Time points for taking biopsies
static list<double> biopsy;
// Onset age for be
static double be_onset;
/**
* Calculate the length of the BE segment in grid points.
*/
int calculate_be_length()
{
const double long_be_prob = 0.63;
const double long_be_mean = 6.4; // cm
const double long_be_std_dev = 3.1; // cm
const double short_be_mean = 1.4; // cm
const double short_be_std_dev = 0.7; // cm
double length;
if (Parameters::getInstance()->uniform() < long_be_prob)
length = Parameters::getInstance()->normal(long_be_mean,long_be_std_dev);
else
length = Parameters::getInstance()->normal(short_be_mean,short_be_std_dev);
if (length < 0.0) length = 0.0;
return (int(length*10.0/grid_size)+1);
}
/**
* This data can be visualized using paraview. See
* www.paraview.org/Wiki/ParaView/Data_formats
*/
void PrintCSV(int seq_num, double t)
{
assert(NUM_CELL_TYPES == 4);
static const char* names[NUM_CELL_TYPES] = {
"normal",
"BE",
"dysplasia",
"cancer",
};
int types[NUM_CELL_TYPES] = { 0, 0, 0, 0 };
char filename[100];
sprintf(filename,"tumor.csv.%d",seq_num);
// Output the paraview file format
ofstream fout(filename);
fout << "xcoord,ycoord,zcoord,type" << endl;
for (int i = 0; i < ni; i++)
for (int j = 0; j < nj; j++)
for (int k = 0; k < nk; k++)
{
int type =
dynamic_cast<TissueVolume*>(tissue->getModel(i,j,k))->itype();
types[type]++;
if (type >= BE)
{
fout << i << "," << j << "," << k << "," << type << endl;
}
}
fout.close();
// Report the time and counts of each cell type
cout << "t = " << t << endl;
for (int i = 0; i < NUM_CELL_TYPES; i++)
{
cout << names[i] << " : " << types[i] << " " << endl;
}
}
//===========================================================================//
void InitModel(void)
{
// Set the size of the simulation grid
Parameters::getInstance()->cell_size(grid_size);
Parameters::getInstance()->xdim(ni);
Parameters::getInstance()->ydim(nj);
Parameters::getInstance()->zdim(nk);
// Load the free parameters
Parameters::getInstance()->load_from_file(inputData.c_str());
// Create the simulation grid
tissue = new CellSpace<int>(ni,nj,nk);
int BeSize = calculate_be_length();
cout << "Segment has length of " << ((double)(BeSize)*grid_size/10.0) << " cm" << endl;
cout << "Extends over " << (((double)(BeSize)/(double)(nj))*100.0) << "\% of length" << endl;
// Populate it with TissueVolume objects
for (int i = 0; i < ni; i++)
{
for (int j = 0; j < nj; j++)
{
for (int k = 0; k < nk; k++)
{
// Top layer has BE
if (k == 0 && j < BeSize)
tissue->add(new TissueVolume(BE,i,j,k),i,j,k);
// Everything else is initially normal
else
tissue->add(new TissueVolume(NORMAL,i,j,k),i,j,k);
}
}
}
// Get the BE onset age
double mean_onset = Parameters::getInstance()->be_onset_age();
be_onset = Parameters::getInstance()->exponential(mean_onset);
// Sort the biopsies by age
biopsy.sort();
// Create the simulator for our tissue model
sim = new Simulator<CellEvent<int> >(tissue);
}
int main(int argc, char **argv)
{
// Read and apply the command line arguments
for( int i = 1; i < argc; ++i )
{
if(strcmp( argv[i],"-var") == 0 && ++i < argc)
{
inputData = argv[i];
}
else if( strcmp( argv[i], "-ranseed" ) == 0 && ++i < argc )
{
unsigned ranseed = (unsigned)atol( argv[i] );
Parameters::getInstance()->set_seed(ranseed);
}
else
{
errno = 0;
double age = strtod(argv[i],NULL);
if (age <= 0.0 || errno != 0)
{
cout << "Illegal biopsy age " << argv[i] << endl;
return 0;
}
biopsy.push_back(age);
}
}
// Setup the model
InitModel();
// Run the simulation
int seq_num = 0;
while (!biopsy.empty())
{
// Take a biopsy
if (sim->nextEventTime()+be_onset > biopsy.front())
{
PrintCSV(seq_num++,biopsy.front());
biopsy.pop_front();
}
// Otherwise advance the simulation
else
sim->execNextEvent();
}
// Cleanup
delete sim;
delete tissue;
Parameters::deleteInstance();
return 0;
}