-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
211 lines (176 loc) · 6.37 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
#include <iostream>
#include <fstream>
#include <string>
#include <utility>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <algorithm>
#include <ctime>
#include "header.h"
void usage(char *argv[]){
printf("**************************************************************\n"
"** **\n"
"** Simulate mRNA populations **\n"
"** **\n"
"**************************************************************\n"
"\n\n"
" This is Free Software - You can use and distribute it under \n"
" the terms of the GNU General Public License, version 3 or later\n\n"
" (c) Massimo Cavallaro ([email protected])\n\n");
printf("Usage: %s [# simulation time] [DIM ENSEMBLE] [alpha] [beta] [decay] [l_on] [l_off] [loop(recycling rate)]\n\n" , argv[0]);
}
int main(int argc, char *argv[]) {
if (argc != 9){
usage(argv);
exit(1);
}
ofstream swi;
ofstream tran;
ofstream mRNA;
ofstream ss;
ofstream PolIIss;
ofstream PolII;
char file_name_switch_events[150];
char file_name_transcription_events[150];
char file_name_mRNA[150];
char file_name_ss[150];
char file_name_PolIIss[150];
char file_name_PolII[150];
snprintf(file_name_switch_events, 150, "%s%s_%s_%s_%s_%s_%s_%s.dat", folder, "/trace/switch_", argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
snprintf(file_name_transcription_events, 150, "%s%s_%s_%s_%s_%s_%s_%s.dat", folder, "/trace/transcription", argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
snprintf(file_name_mRNA, 150, "%s%s_%s_%s_%s_%s_%s_%s.dat", folder, "/trace/mRNA_", argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
snprintf(file_name_ss, 150, "%s%s_%s_%s_%s_%s_%s_%s.dat", folder, "/trace/ss_mRNA_", argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
snprintf(file_name_PolIIss, 150, "%s%s_%s_%s_%s_%s_%s_%s.dat", folder, "/trace/Pol2ss_", argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
snprintf(file_name_PolII, 150, "%s%s_%s_%s_%s_%s_%s_%s.dat", folder, "/trace/Pol2_", argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
fprintf(stderr, "%s\n", file_name_ss);
mRNA.open(file_name_mRNA);
swi.open(file_name_switch_events);
tran.open(file_name_transcription_events);
PolII.open(file_name_PolII);
int num_of_rates = 7;
double T;
double t;
double R;
int DIM_ENSEMBLE;
int i;
int j;
gsl_rng *r;
r = gsl_rng_alloc(gsl_rng_mt19937);
gsl_rng_set (r, 1144); //time(NULL)
int status = 0;
T = atof(argv[1]);
DIM_ENSEMBLE = atoi(argv[2]);
Rates br;
br.alpha = atof(argv[3]);
br.beta = atof(argv[4]);
br.decay = atof(argv[5]);
br.l_on = atof(argv[6]);
br.l_off = atof(argv[7]);
br.loop = atof(argv[8]);
br.delta = 1;
//br.thinning = 1;
vector<Systems> system(DIM_ENSEMBLE);
for(i=0; i<DIM_ENSEMBLE; i++){
system[i].pol2=1;
system[i].mRNA=0;
system[i].part_sum.resize(num_of_rates);
system[i].part_sum.assign(num_of_rates, 0);
system[i].is_open = gsl_ran_bernoulli(r, 0.5);
system[i].current = 0;
}
for(i=0; i<DIM_ENSEMBLE; i++){
system[i].part_sum[0] = br.alpha; // pol2 is recruited
system[i].part_sum[1] = system[i].part_sum[0] + (1 - br.loop) * br.beta * system[i].pol2 * system[i].is_open; // transcription
system[i].part_sum[2] = system[i].part_sum[1] + br.decay * system[i].mRNA; //mRNA decay
system[i].part_sum[3] = system[i].part_sum[2] + br.l_off * system[i].is_open;
system[i].part_sum[4] = system[i].part_sum[3] + br.l_on * (1 - system[i].is_open);
system[i].part_sum[5] = system[i].part_sum[4] + br.loop * br.beta * system[i].pol2 * system[i].is_open; // transcription (without loosing polymerase )
system[i].part_sum[6] = system[i].part_sum[5] + br.delta * system[i].pol2;
}
/* * *
* START THE SIMULATION
*/
for (i=0; i<DIM_ENSEMBLE; i++){
t = 0;
while (t < T) {
// br.thinning = 1; //int(sin(t/100.)+1);
R = gsl_rng_uniform(r) * system[i].part_sum.back();
j = upper_bound(system[i].part_sum.begin(), system[i].part_sum.end(), R) - system[i].part_sum.begin();
status = update(&system[0], i, j, br);
if (status!=EXIT_SUCCESS) {
fprintf(stderr,"ERROR %f %d", t, j);
}
if(i==0){
if(j==0){
PolII << t << " " << system[0].pol2 << endl;
}
if (j==1){ // mRNA is created
PolII << t << " " << system[0].pol2 << endl;
mRNA << t << " " << system[0].mRNA << endl;
tran << t << " " << system[0].current << endl;
}
else if(j==2){ // mRNA is destroied
mRNA << t << " " << system[0].mRNA << endl;
}
else if(j==3){
swi << t << " " << system[0].is_open << endl;
}
else if(j==4){
swi << t << " " << system[0].is_open << endl;
}
else if (j==5){ // mRNA is created
mRNA << t << " " << system[0].mRNA << endl;
tran << t << " " << system[0].current << endl;
}
else if (j==6){
PolII << t << " " << system[0].pol2 << endl;
}
}
t = t + gsl_ran_exponential(r, 1./system[i].part_sum.back());
}
}
double media_mRNA = 0;
double media_Pol2 = 0;
for (i=0; i<DIM_ENSEMBLE; i++){
media_mRNA = media_mRNA + system[i].mRNA;
media_Pol2 = media_Pol2 + system[i].pol2;
}
media_mRNA = media_mRNA / (double)DIM_ENSEMBLE;
media_Pol2 = media_Pol2 / (double)DIM_ENSEMBLE;
double mpol2 = br.alpha / (br.delta + br.beta * (1 - br.loop));
printf("%s %f %f %s %f %f %f \n",
"pol2",
mpol2,
/* br.alpha / (br.delta + br.beta),*/
media_Pol2,
"mRNA",
br.beta * br.l_on / (br.l_on + br.l_off) / br.decay *
(br.alpha + br.loop * mpol2 * br.beta) / (br.delta + br.beta),
br.beta * mpol2 / br.decay * br.l_on / (br.l_on + br.l_off),
media_mRNA);
ss.open(file_name_ss);
ss << system[0].mRNA;
for (i= 1; i<DIM_ENSEMBLE; i++){
ss << ' ' << system[i].mRNA;
}
ss << endl;
PolIIss.open(file_name_PolIIss);
PolIIss << system[0].pol2;
for (i= 1; i<DIM_ENSEMBLE; i++){
PolIIss << ' ' << system[i].pol2;
}
PolIIss << endl;
mRNA.close();
swi.close();
tran.close();
ss.close();
PolIIss.close();
PolII.close();
gsl_rng_free(r);
return EXIT_SUCCESS;
}