#include #include #include #define IM1 2147483563 #define IM2 2147483399 #define AM (1.0/IM1) #define IMM1 (IM1-1) #define IA1 40014 #define IA2 40692 #define IQ1 53668 #define IQ2 52774 #define IR1 12211 #define IR2 3791 #define NTAB 32 #define NDIV (1+IMM1/NTAB) #define EPS 0.00000012 #define RNMX (1.0-EPS) #define V 200.0 /* 600 This means that there are on average 5000 molecules of CRY1 at its max*/ #define tlp_o (1.0)/* note divided by 100*//* note divided by 100*/ #define tlr_o (1.310) #define up_o (3.39) #define upu_o (0.0823) #define uro_o (0.13) #define urt_o (0.2) #define ac_o (0.465/V) #define dc_o (5.09) #define ar_o (0.266/V) #define dr_o (0.352) #define nl_o (2.31) #define ne_o (1.0) /* .713 */ #define hoo_o 0.286 #define hto_o 1.45/* note hto = hot in mathematical files*/ #define hot_o 0.0901 #define ht 0.0 #define trPo_o (43.0*V)/* note multiplied by 10*//* note divided by 10*/ #define trPt_o (116.0*V)/* note multiplied by 10*//* note divided by 10*/ #define trRo_o (226.0*V) #define trRt_o (314.0*V) #define trfac_o 50*V/*was 5*/ #define umfac_o 0.5 /* note that the reciprocal of this number gives a time constant; according to Takahashi, should be 2 hours*/ #define tmc_o (1.5) #define bbin_o (30/V) #define unbbin_o 1.0/* this was 1; reciprocal of this number tells us, roughly the length of the period. thus hard to get oscillations; not sure exactly why*/ #define umPo_o 1.51 #define umPt_o 1.05 #define umRo_o 0.278 #define umRt_o 0.63 #define unbin_o (10000.0) #define bin_o (6000/V) /*this was 0.5*/ #define Nf_o 115.76 #define Ct_o (12.0*V) #define Btot_o (8.0*V*1.0) #define numcells 100 #define numsteps 5001 #define tstep 0.1 /* time steps every 6 minutes*/ #define recnum 57 /*1 + number of reactions*/ float ran2(long *idum); float gasdev(long *init); /*void chgconst(int ii, int ij, int ik, int il, int im, int in);*/ void initconst(void); float sumrea(float *ast, double tstt); void shortrun(long *iidum); int Po, Pt, C, Cn, MnPo, MnPt, MnRo, MnRt, McPo, McPt, McRo, McRt, p[2][3][2][2][2][3], r[3][3][2], facr, GFac, CFac; int phospdeg[17], perk[37], perkn[37], perku[73], perr[49], perrn[49], perru[97], degrone[7], degrtwo[7], bbbin[73], nucubcry[19], cytuncry[19]; int pernl[37], perne[25], phospo[19], phospt[19], nucbmal,nuccrybmal, GPo, GPt, GRo, GRt, PoC, PtC, CPo, CPt, CRo, CRt; float tlp, tlr, up, upu, uro, urt, ac, dc, ar, dr, nl; float ne, hoo, hto, hot, trPo, trPt, trRo, trRt, trfac, umfac, tmc, bbin; float unbbin, umPo, umPt, umRo, umRt, unbin, bin, Nf, Ct, Btot; long totper, totfacr; /* this will track the amount of PER (both per1 and per2) in all cells*/ double recrea[recnum]; float coupling; /*P-vector p[i][j][k][l][m][n][o] i = 0 means Per1 in complex i = 1 means per2 in complex j = 0 means no CRY is bound j = 1 means CRY1 is bound j = 2 means CRY2 is bound k = 0 means no kinase is bound k = 1 means kinase is bound l = 0 means per1 or per2 is in primary phosphorylaion state l = 1 means per1 or per2 is in the secondary phosphorylation state m = 0 means complex is in cytoplasm m = 1 means complex is in nucleus n = 0 means no BMAL bound n = 1 means BMAL-CLK is bound n = 2 means BMAL2 is bound*/ /*r-vector r[i][j][k] i = 0 no CRY i = 1 CRY1 i = 2 cry2 j = 0 no bmal j = 1 bmal1 j = 2 bmal2 k = 0 cytoplasm k = 1 nucleus*/ main() { FILE *varfil; long iidum; int timecnt, icell; long totperr, totfacrr; int recper, iiir, ijjr, ikkr, illr, immr, ioor, innr, imm; int rGPo[numcells], rGPt[numcells], rGRo[numcells], rGRt[numcells], rCPo[numcells], rCPt[numcells], rCRo[numcells], rCRt[numcells], rPoC[numcells], rPtC[numcells], rfacr[numcells], rGFac[numcells], rCFac[numcells]; int rPo[numcells], rPt[numcells], rC[numcells], rCn[numcells], rMnPo[numcells], rMnPt[numcells], rMnRo[numcells], rMnRt[numcells], rMcPo[numcells], rMcPt[numcells], rMcRo[numcells], rMcRt[numcells], rp[2][3][2][2][2][3][numcells], rr[3][3][2][numcells]; float gbba; float tlpv[numcells], tlrv[numcells], upv[numcells], upuv[numcells], urov[numcells], urtv[numcells], acv[numcells], dcv[numcells], arv[numcells], drv[numcells], nlv[numcells]; float nev[numcells], hoov[numcells], htov[numcells], hotv[numcells], trPov[numcells], trPtv[numcells], trRov[numcells], trRtv[numcells], trfacv[numcells], umfacv[numcells], tmcv[numcells], bbinv[numcells]; float unbbinv[numcells], umPov[numcells], umPtv[numcells], umRov[numcells], umRtv[numcells], unbinv[numcells], binv[numcells], Nfv[numcells], Ctv[numcells], Btotv[numcells]; float htv[numcells]; long iinit; long init=(-10); float espsilon; /*iidum = -17; iinit = -17;*/ /*init = -10;*/ coupling = 1.0*.01; /*Coupling factor is .01*/ espsilon = 0.05; varfil = fopen("data_file.m", "w"); /*for (imm = 0; imm < numcells; imm++) { tlpv[imm] = tlp_o; tlrv[imm] = tlr_o; upv[imm] = up_o; upuv[imm] = upu_o; urov[imm] = uro_o; urtv[imm] = urt_o; acv[imm] = ac_o; dcv[imm] = dc_o; arv[imm] = ar_o; drv[imm] = dr_o; nlv[imm] = nl_o; nev[imm] = ne_o; hoov[imm] = hoo_o; htov[imm] = hto_o; hotv[imm] = hot_o; trPov[imm] = trPo_o; trPtv[imm] = trPt_o; trRov[imm] = trRo_o; trRtv[imm] = trRt_o; trfacv[imm] = trfac_o; umfacv[imm] = umfac_o; tmcv[imm] = tmc_o; bbinv[imm] = bbin_o; unbbinv[imm] = unbbin_o; umPov[imm] = umPo_o; umPtv[imm] = umPt_o; umRov[imm] = umRo_o; umRtv[imm] = umRt_o; unbinv[imm] = unbin_o; binv[imm] = bin_o; Nfv[imm] = Nf_o; Ctv[imm] = Ct_o; Btotv[imm] = Btot_o;}*/ /*init = *iinit;*/ for (icell = 0; icell < numcells; icell++) { tlpv[icell] = tlp_o*(1 + espsilon*gasdev(&init)); while (tlpv[icell] < 0){ tlpv[icell] = tlp_o*(1 + espsilon*gasdev(&init)); } tlrv[icell] = tlr_o*(1 + espsilon*gasdev(&init)); while (tlrv[icell] < 0){ tlrv[icell] = tlr_o*(1 + espsilon*gasdev(&init)); } upv[icell] = up_o*(1 + espsilon*gasdev(&init)); while (upv[icell] < 0){ upv[icell] = up_o*(1 + espsilon*gasdev(&init)); } upuv[icell] = upu_o*(1 + espsilon*gasdev(&init)); while (upuv[icell] < 0){ upuv[icell] = upu_o*(1 + espsilon*gasdev(&init)); } urov[icell] = uro_o*(1 + espsilon*gasdev(&init)); while (urov[icell] < 0){ urov[icell] = uro_o*(1 + espsilon*gasdev(&init)); } urtv[icell] = urt_o*(1 + espsilon*gasdev(&init)); while (urtv[icell] < 0){ urtv[icell] = urt_o*(1 + espsilon*gasdev(&init)); } /*printf("%f \n", urtv[icell]); */ acv[icell] = ac_o*(1 + espsilon*gasdev(&init)); while (acv[icell] < 0){ acv[icell] = ac_o*(1 + espsilon*gasdev(&init)); } /*printf("%f \n", acv[icell]); */ dcv[icell] = dc_o*(1 + espsilon*gasdev(&init)); while (dcv[icell] < 0){ dcv[icell] = dc_o*(1 + espsilon*gasdev(&init)); } arv[icell] = ar_o*(1 + espsilon*gasdev(&init)); while (arv[icell] < 0){ arv[icell] = ar_o*(1 + espsilon*gasdev(&init)); } drv[icell] = dr_o*(1 + espsilon*gasdev(&init)); while (drv[icell] < 0){ drv[icell] = dr_o*(1 + espsilon*gasdev(&init)); } nlv[icell] = nl_o*(1 + espsilon*gasdev(&init)); while (nlv[icell] < 0){ nlv[icell] = nl_o*(1 + espsilon*gasdev(&init)); } nev[icell] = ne_o*(1 + espsilon*gasdev(&init)); while (nev[icell] < 0){ nev[icell] = ne_o*(1 + espsilon*gasdev(&init)); } hoov[icell] = hoo_o*(1 + espsilon*gasdev(&init)); while (hoov[icell] < 0){ hoov[icell] = hoo_o*(1 + espsilon*gasdev(&init)); } htov[icell] = hto_o*(1 + espsilon*gasdev(&init)); while (htov[icell] < 0){ htov[icell] = hto_o*(1 + espsilon*gasdev(&init)); } hotv[icell] = hot_o*(1 + espsilon*gasdev(&init)); while (hotv[icell] < 0){ hotv[icell] = hot_o*(1 + espsilon*gasdev(&init)); } htv[icell] = 0.0; /*Note that this rate is set to 0, no variation in this parameter!*/ while (htv[icell] < 0){ htv[icell] = 0.0; } trPov[icell] = trPo_o*(1 + espsilon*gasdev(&init)); while (trPov[icell] < 0){ trPov[icell] = trPo_o*(1 + espsilon*gasdev(&init)); } trPtv[icell] = trPt_o*(1 + espsilon*gasdev(&init)); while (trPtv[icell] < 0){ trPtv[icell] = trPt_o*(1 + espsilon*gasdev(&init)); } trRov[icell] = trRo_o*(1 + espsilon*gasdev(&init)); while (trRov[icell] < 0){ trRov[icell] = trRo_o*(1 + espsilon*gasdev(&init)); } trRtv[icell] = trRt_o*(1 + espsilon*gasdev(&init)); while (trRtv[icell] < 0){ trRtv[icell] = trRt_o*(1 + espsilon*gasdev(&init)); } trfacv[icell] = trfac_o*(1 + espsilon*gasdev(&init)); while (trfacv[icell] < 0){ trfacv[icell] = trfac_o*(1 + espsilon*gasdev(&init)); } umfacv[icell] = umfac_o*(1 + espsilon*gasdev(&init)); while (umfacv[icell] < 0){ umfacv[icell] = umfac_o*(1 + espsilon*gasdev(&init)); } tmcv[icell] = tmc_o*(1 + espsilon*gasdev(&init)); while (tmcv[icell] < 0){ tmcv[icell] = tmc_o*(1 + espsilon*gasdev(&init)); } bbinv[icell] = bbin_o*(1 + espsilon*gasdev(&init)); while (bbinv[icell] < 0){ bbinv[icell] = bbin_o*(1 + espsilon*gasdev(&init)); } unbbinv[icell] = unbbin_o*(1 + espsilon*gasdev(&init)); while (unbbinv[icell] < 0){ unbbinv[icell] = unbbin_o*(1 + espsilon*gasdev(&init)); } umPov[icell] = umPo_o*(1 + espsilon*gasdev(&init)); while (umPov[icell] < 0){ umPov[icell] = umPo_o*(1 + espsilon*gasdev(&init)); } umPtv[icell] = umPt_o*(1 + espsilon*gasdev(&init)); while (umPtv[icell] < 0){ umPtv[icell] = umPt_o*(1 + espsilon*gasdev(&init)); } umRov[icell] = umRo_o*(1 + espsilon*gasdev(&init)); while (umRov[icell] < 0){ umRov[icell] = umRo_o*(1 + espsilon*gasdev(&init)); } umRtv[icell] = umRt_o*(1 + espsilon*gasdev(&init)); while (umRtv[icell] < 0){ umRtv[icell] = umRt_o*(1 + espsilon*gasdev(&init)); } unbinv[icell] = unbin_o*(1 + espsilon*gasdev(&init)); while (unbinv[icell] < 0){ unbinv[icell] = unbin_o*(1 + espsilon*gasdev(&init)); } binv[icell] = bin_o*(1 + espsilon*gasdev(&init)); while (binv[icell] < 0){ binv[icell] = bin_o*(1 + espsilon*gasdev(&init)); } Nfv[icell] = Nf_o*(1 + espsilon*gasdev(&init)); while (Nfv[icell] < 0){ Nfv[icell] = Nf_o*(1 + espsilon*gasdev(&init)); } Ctv[icell] = Ct_o*(1 + espsilon*gasdev(&init)); while (Ctv[icell] < 0){ Ctv[icell] = Ct_o*(1 + espsilon*gasdev(&init)); } Btotv[icell] = Btot_o*(1 + espsilon*gasdev(&init)); while (Btotv[icell] < 0){ Btotv[icell] = Btot_o*(1 + espsilon*gasdev(&init)); } } for (imm = 0; imm < recnum; imm++) {recrea[imm] = 0;}; for (icell = 0; icell < numcells; icell++) { rGPo[icell] = 0; rGPt[icell] = 0; rGRo[icell] = 0; rGRt[icell] = 0; rCPo[icell] = 0; rCPt[icell] = 0; rCRo[icell] = 0; rCRt[icell] = 0; rPoC[icell] = 0; rPtC[icell] = 0; rPo[icell] = 0*300*V/600; rPt[icell] = 0*300*V/600; rCn[icell] = (int) 0; rC[icell] = (int) Ctv[icell]; rMnPo[icell] = 0; rMnPt[icell] = 0; rMnRo[icell] = 0; rMnRt[icell] = 0; rMcPo[icell] = (int) V/2; rMcPt[icell] = (int) V/2; rMcRo[icell] = (int) V/2; rMcRt[icell] = (int) V/2; rfacr[icell] = 0; rGFac[icell] = 1; rCFac[icell] = 1; for (iiir = 0; iiir < 2; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) {for (illr = 0; illr < 2; illr++) {for (immr = 0; immr < 2; immr++) {for (innr = 0; innr < 3; innr++) { rp[iiir][ijjr][ikkr][illr][immr][innr][icell] = 0; if (ijjr == 0) {if (ikkr == 0) {if (illr == 0) {if (immr == 1) {if (innr == 0) { rp[iiir][ijjr][ikkr][illr][immr][innr][icell] = (int) (300*V/600);};};};};}; };};};};};}; for (iiir = 0; iiir < 3; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) { rr[iiir][ijjr][ikkr][icell] = 0;};};}; /*initial conditions for bmal1 and bmal2; NOTE: bmal1 and bmal all start in the nucleus = so the third number is a 1 rr[i][j][k][icell] matrix i = 1 CRY1 i = 2 cry2 j = 1 bmal1 j = 2 bmal2 k = 0 cytoplasm k = 1 nucleus icell - particular cell */ rr[1][1][1][icell] = ceil(Btotv[icell]/2); /* bmal1 w/cry1 attached in nucleus */ rr[2][1][1][icell] = ceil(Btotv[icell]/2); /* bmal1 w/cry2 attached in nucleus */ rr[1][0][1][icell] = (int) V*10.0; rr[2][0][1][icell] = (int) V*10.0; rr[1][2][1][icell] = 0*V/600; /* bmal2 w/cry1 attached in nucleus */ rr[2][2][1][icell] = 0*V/600; /* bmal2 w/cry2 attached in nucleus */ totfacr = 0.0; totper = 0.0; }; for (timecnt = 1; timecnt < numsteps; timecnt++) { /*note: we simulate 0.1 hours, and then move to neuron 2 and simulate another 0.1 hour, then move to neuron 3, etc*/ fprintf(varfil, "%d ", timecnt); printf("%d ", timecnt); totperr = 0.0; totfacrr = 100.0; for (icell = 0; icell < numcells; icell++) { /*this counter is over the particular neuron being simulated*/ tlp = tlpv[icell]; tlr = tlrv[icell]; up = upv[icell]; upu = upuv[icell]; uro = urov[icell]; urt = urtv[icell]; ac = acv[icell]; dc = dcv[icell]; ar = arv[icell]; dr = drv[icell]; nl = nlv[icell]; ne = nev[icell]; hoo = hoov[icell]; hto = htov[icell]; hot = hotv[icell]; trPo = trPov[icell]; trPt = trPtv[icell]; trRo = trRov[icell]; trRt = trRtv[icell]; trfac = trfacv[icell]; umfac = umfacv[icell]; tmc = tmcv[icell]; bbin = bbinv[icell]; unbbin = unbbinv[icell]; umPo = umPov[icell]; umPt = umPtv[icell]; umRo = umRov[icell]; umRt = umRtv[icell]; unbin = unbinv[icell]; bin = binv[icell]; Nf = Nfv[icell]; Ct = Ctv[icell] ; Btot = Btotv[icell]; /*In this part, we are defining what the values of the molecules will be from the values above*/ CPo = rCPo[icell]; CPt = rCPt[icell]; CRo = rCRo[icell]; CRt = rCRt[icell]; GPo = rGPo[icell]; GPt = rGPt[icell]; GRo = rGRo[icell]; GRt = rGRt[icell]; PoC = rPoC[icell]; PtC = rPtC[icell]; Po = rPo[icell]; Pt = rPt[icell]; C = rC[icell]; Cn = rCn[icell]; MnPo = rMnPo[icell]; MnPt = rMnPt[icell]; MnRo = rMnRo[icell]; MnRt = rMnRt[icell]; McPo = rMcPo[icell]; McPt = rMcPt[icell]; McRo = rMcRo[icell]; McRt = rMcRt[icell]; facr = rfacr[icell]; GFac = rGFac[icell]; CFac = rCFac[icell]; for (iiir = 0; iiir < 2; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) {for (illr = 0; illr < 2; illr++) {for (immr = 0; immr < 2; immr++) {for (innr = 0; innr <3; innr++) { p[iiir][ijjr][ikkr][illr][immr][innr] = rp[iiir][ijjr][ikkr][illr][immr][innr][icell];};};};};};}; for (iiir = 0; iiir < 3; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) { r[iiir][ijjr][ikkr] = rr[iiir][ijjr][ikkr][icell];};};}; shortrun(&iidum); /*Run the shortrun subroutine which does the stochastic mammalian 'clock'*/ /*This part below updates into the r vector the particular value of a molecule for a particular neuron*/ rGPo[icell] = GPo; rGPt[icell] = GPt; rGRo[icell] = GRo; rGRt[icell] = GRt; rCPo[icell] = CPo; rCPt[icell] = CPt; rCRo[icell] = CRo; rCRt[icell] = CRt; rPoC[icell] = PoC; rPtC[icell] = PtC; rPo[icell] = Po; rPt[icell] = Pt; rC[icell] = C; rCn[icell] = Cn; rMnPo[icell] = MnPo; rMnPt[icell] = MnPt; rMnRo[icell] = MnRo; rMnRt[icell] = MnRt; rMcPo[icell] = McPo; rMcPt[icell] = McPt; rMcRo[icell] = McRo; rMcRt[icell] = McRt; rfacr[icell] = facr; rGFac[icell] = GFac; rCFac[icell] = CFac; for (iiir = 0; iiir < 3; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) { rr[iiir][ijjr][ikkr][icell] = r[iiir][ijjr][ikkr];};};}; for (iiir = 0; iiir < 2; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) {for (illr = 0; illr < 2; illr++) {for (immr = 0; immr < 2; immr++) {for (innr = 0; innr <3; innr++) { rp[iiir][ijjr][ikkr][illr][immr][innr][icell] = p[iiir][ijjr][ikkr][illr][immr][innr];};};};};};}; recper = 0; for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) {for (illr = 0; illr < 2; illr++) {for (immr = 0; immr < 2; immr++) {for (innr = 0; innr <3; innr++) { recper = recper + p[1][ijjr][ikkr][illr][immr][innr];};};};};}; recper = recper + Pt +PtC; /*These two species of per2 are not in the p matrix */ fprintf(varfil, "%d ", recper); /*if (icell == 0) { fprintf(varfil, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d ", CPo, CPt, CRo, CRt, GPo, GPt, GRo, GRt, PoC, PtC, Po, Pt, C, Cn, MnPo, MnPt, MnRo, MnRt, McPo, McPt, McRo, McRt, GFac, CFac, facr); for (iiir = 0; iiir < 3; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) { fprintf(varfil, "%d ", r[iiir][ijjr][ikkr]);};};}; for (iiir = 0; iiir < 2; iiir++) {for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) {for (illr = 0; illr < 2; illr++) {for (immr = 0; immr < 2; immr++) {for (innr = 0; innr <3; innr++) { fprintf(varfil, "%d ", p[iiir][ijjr][ikkr][illr][immr][innr]);};};};};};};};*/ /* add the total amount of per1*/ for (ijjr = 0; ijjr < 3; ijjr++) {for (ikkr = 0; ikkr < 2; ikkr++) {for (illr = 0; illr < 2; illr++) {for (immr = 0; immr < 2; immr++) {for (innr = 0; innr <3; innr++) { recper = recper + p[0][ijjr][ikkr][illr][immr][innr];};};};};}; recper = recper + Po +PoC;/* recper is now the total per1 AND per2*/ totperr = totperr + recper;/* add the amount of per in this cell note per1 mRNA*/ totfacrr = totfacrr + facr; printf("%d ", recper); }; fprintf(varfil, "\n"); gbba = ((float) nuccrybmal)/((float) nucbmal); printf("%d facr %d %d %d %d %d gbba number %f \n", p[0][0][0][0][1][0], facr, MnPo, McPo, MnPt, McPt, gbba); totper = totperr;/* total per1 AND per2 in all cells*/ totfacr = totfacrr; }; fclose(varfil); for (imm = 0; imm < recnum; imm++) {printf("%d %f ", imm, recrea[imm]);}; }; void shortrun(long *iidum) { double tst; long idum; int ii, ij, ik, il, im, inn, inm, antr, ptes, iim, ijm, ikm, ilm, imm, inr, ior, nmp, nmt, ijjr, ikkr, illr, immr, mns, snsd; float chk, immmrr; float azero, artwo, asum, ast[recnum], gbba; double maincntr; int garb, garbb[12]; /* the following code initializes and then sums up the number of molecules within each reaction class*/ idum = *iidum; degrone[0] = 0; degrtwo[0] = 0; bbbin[0] = 0; nucubcry[0] = 0; cytuncry[0] = 0; phospdeg[0] = 0; perk[0] = 0; perkn[0] = 0; perku[0] = 0; perr[0] = 0; perrn[0] = 0; perru[0] = 0; pernl[0] = 0; perne[0] = 0; phospo[0] = 0; phospt[0] = 0; nuccrybmal = 0; nucbmal = 0; initconst(); /* the following code initializes variables used in the gillespie simulation*/ tst = 0;/* keeps track of elapsed time*/ maincntr = 0;/* counts how many total reactions have occured*/ ptes = 1;/* tells us which reaction has last occured*/ ii = 0; ij = 0; ik = 0; il = 0; immmrr = 0; /*mns = 0;*/ /* printf("%f %f %f %f %f %f %f %f %f %f %f %f \n", V, tlp, tlr, up, upu, uro, urt, ac, dc, ar, dr, nl);*/ /*while (maincntr < 10000000) {maincntr++;*/ /* This counts how many times each reaction occurs*/ while (tst < tstep) {maincntr++;/* maincntr counts how many reactions have occured*/ /* the following check for potential errors (e.g. nonzero chemical species which must be zero, or any chemical species which have negative numbers of molecules*/ /* the folloing code makes sure that we are in the bounds of the matrix p*/ /* if ((ii != 0) && (ii != 1)) {printf("ii break %d", ptes); break;}; if ((ij != 0) && (ij != 1) && (ij != 2)) {printf("ij break %d", ptes); break;}; if ((ik != 0) && (ik != 1)) {printf("ik break %d", ptes); break;}; if ((il != 0) && (il != 1)) {printf("il break %d", ptes); break;}; if ((im != 0) && (im != 1)) {printf("im break %d", ptes); break;};*/ /* The following check that the kinase concentration is conserved*/ /*garb = C + Cn + PoC + PtC; for (iim = 0; iim<2; iim++) {for (ijm = 0; ijm < 3; ijm++) {for (ilm = 0; ilm < 2; ilm++) {for (imm = 0; imm < 2; imm++) {for (inn = 0; inn < 3; inn ++) { garb = garb + p[iim][ijm][1][ilm][imm][inn];};};};};}; if (garb != (int) Ct) {printf("error %d %f %d %d %d %d %d \n", ptes, maincntr, ii, ij, ik, il, im); break;}; garb = 0; for (iim = 0; iim<3; iim++) {for (ijm = 1; ijm < 3; ijm++) {for (ilm = 0; ilm < 2; ilm++) { if (r[iim][ijm][imm] < 0) printf("neg conc");};};}; for (iim = 0; iim<3; iim++) {for (ijm = 1; ijm < 3; ijm++) {for (ilm = 0; ilm < 2; ilm++) { garb = garb + r[iim][ijm][ilm];};};}; for (iim = 0; iim<2; iim++) {for (ijm = 0; ijm < 3; ijm++) {for (ikm = 0; ikm < 2; ikm++) {for (ilm = 0; ilm < 2; ilm++) {for (imm = 0; imm < 2; imm++) {for (inn = 1; inn < 3; inn ++) { garb = garb + p[iim][ijm][ikm][ilm][imm][inn];};};};};};}; snsd = 600; if (mns == 0) {if (garb != snsd) {printf(" bmal not conserved, %d %d %d last rec", ptes, garb, snsd); mns = 1;};};*/ /* the following checks that no chemical species are negative*/ /*for (iim = 0; iim<2; iim++) {for (ijm = 0; ijm < 3; ijm++) {for (ikm = 0; ikm < 2; ikm++) {for (ilm = 0; ilm < 2; ilm++) {for (imm = 0; imm < 2; imm++) {for (inn = 0; inn < 3; inn++) { if (p[iim][ijm][ikm][ilm][imm][inn] < 0) {printf("hugeerror %d %d %d %d %d %d %d\n", ptes, iim, ijm, ikm, ilm, imm, inn); break;};};};};};};};*/ /*if (mns == 0) { for (iim = 0; iim<3; iim++) {for (ijm = 0; ijm < 3; ijm++) {for (ikm = 0; ikm < 2; ikm++) { if (r[iim][ijm][ikm] < 0) {printf("hugeerror %d %d %d %d %d %d %d %d %f %d\n", ptes, iim, ijm, ikm, ilm, imm, inm, antr, chk, bbbin[antr]); antr = 1; for (ii = 0; ii < 2; ii++) {for (ij = 1; ij < 3; ij++) {for (ik = 0; ik < 2; ik++) {for (il = 0; il < 2; il++) {for (im = 0; im < 2; im++) {for (inn = 1; inn <3; inn++) { printf("%d ", bbbin[antr]); antr++;};};};};};}; for (ij = 1; ij < 3; ij++) {for (inn = 1; inn < 3; inn++) {for (im = 0; im < 2; im++) { printf("%d ", bbbin[antr]); antr++;};};}; mns = 1; printf("\n"); break;};};};};};*/ /*if (CPo < 0) printf("error! CPo"); if (CPt < 0) printf("error! CPt"); if (CRo < 0) printf("error! CRo"); if (CRt < 0) printf("error! CRt"); if (CRo > 1) printf("error! CRoa"); if (CRt > 1) printf("error! CRta"); if (CPo > 5) printf("error! CPoa, %d", (GPo -CPo)); if (CPt > 5) printf("error! CPta, %d", (GPt - CPt));*/ recrea[ptes]++; /* add one to whichever reaction occurs next*/ azero = sumrea(ast, tst); /* sum all reaction rates*/ tst = tst + (double) (1/azero)*log(1/ran2(&idum)); /* updates the time*/ /*if (tst > tstep) {break;};*/ /* Key change, we want to simulate up to tstep and not beyond*/ artwo = ran2(&idum)*azero;/* chooses a random number*/ asum = 0; for (ptes = 1; ptes 0) CFac--; break; }; }; *iidum = idum; }; void initconst(void) { int antr, iir, ijr, ikr, ilr, imr, inn, ii, ij, ik, il, im; ij = 0; inn = 0; antr = 1; for (iir = 0; iir < 2; iir++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (imr = 0; imr < 2; imr++) { phospdeg[antr] = phospdeg[antr-1] + p[iir][ij][ikr][ilr][imr][inn]; antr++;};};};}; im = 0; ik = 0; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 0; ijr < 3; ijr++) {for (ilr = 0; ilr < 2; ilr++) {for (inn = 0; inn <3; inn++) { perk[antr] = perk[antr-1] + p[iir][ijr][ik][ilr][im][inn]; antr++;};};};}; im = 1; ik = 0; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 0; ijr < 3; ijr++) {for (ilr = 0; ilr < 2; ilr++) {for (inn = 0; inn <3; inn++) { perkn[antr] = perkn[antr-1] + p[iir][ijr][ik][ilr][im][inn]; antr++;};};};}; ik = 1; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 0; ijr < 3; ijr++) {for (ilr = 0; ilr < 2; ilr++) {for (imr = 0; imr < 2; imr++) {for (inn = 0; inn <3; inn++) { perku[antr] = perku[antr-1] + p[iir][ijr][ik][ilr][imr][inn]; antr++;};};};};}; ij = 0; im = 0; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 1; ijr <3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (inn = 0; inn <3; inn++) { perr[antr] = perr[antr-1] + p[iir][0][ikr][ilr][im][0]*r[ijr][inn][0]; antr++;};};};};}; ij = 0; im = 1; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 1; ijr <3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (inn = 0; inn <3; inn++) { perrn[antr] = perrn[antr-1] + p[iir][0][ikr][ilr][im][0]*r[ijr][inn][1]; antr++;};};};};}; im = 1; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 0; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (inn = 0; inn <1; inn++) { perne[antr] = perne[antr-1] + p[iir][ijr][ikr][ilr][im][inn]; antr++;};};};};}; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 1; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (imr = 0; imr < 2; imr++) {for (inn = 0; inn <3; inn++) { perru[antr] = perru[antr-1] + p[iir][ijr][ikr][ilr][imr][inn]; antr++;};};};};};}; il = 0; im = 0; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 0; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (inn = 0; inn <3; inn++) { pernl[antr] = pernl[antr-1] + p[iir][ijr][ikr][il][im][inn]; antr++;};};};}; ii = 1; ik = 1; il = 0; antr = 1; for (ijr = 0; ijr < 3; ijr++) {for (imr = 0; imr < 2; imr++) {for (inn = 0; inn <3; inn++) { phospt[antr] = phospt[antr-1] + p[ii][ijr][ik][il][imr][inn]; antr++;};};}; ii = 0; ik = 1; il = 0; antr = 1; for (ijr = 0; ijr < 3; ijr++) {for (imr = 0; imr < 2; imr++) {for (inn = 0; inn <3; inn++) { phospo[antr] = phospo[antr-1] + p[ii][ijr][ik][il][imr][inn]; antr++;};};}; antr = 1; im = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 1; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) { nucubcry[antr] = nucubcry[antr - 1] + p[iir][ijr][ikr][ilr][im][0]; antr++;};};};}; nucubcry[antr] = nucubcry[antr - 1] + r[1][0][1]; antr++; nucubcry[antr] = nucubcry[antr - 1] + r[2][0][1]; antr = 1; im = 0; for (iir = 0; iir < 2; iir++) {for (ijr = 1; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) { cytuncry[antr] = cytuncry[antr - 1] + p[iir][ijr][ikr][ilr][im][0]; antr++;};};};}; cytuncry[antr] = cytuncry[antr - 1] + r[1][0][0]; antr++; cytuncry[antr] = cytuncry[antr - 1] + r[2][0][0]; antr = 1; for (inn = 0; inn < 3; inn++) {for (im = 0; im < 2; im++) { degrone[antr] = degrone[antr -1] + r[1][inn][im]; antr++;};}; antr = 1; for (inn = 0; inn < 3; inn++) {for (im = 0; im < 2; im++) { degrtwo[antr] = degrtwo[antr -1] + r[2][inn][im]; antr++;};}; antr = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 1; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (imr = 0; imr < 2; imr++) {for (inn = 1; inn <3; inn++) { bbbin[antr] = bbbin[antr - 1] + p[iir][ijr][ikr][ilr][imr][inn]; antr++;};};};};};}; for (ijr = 1; ijr < 3; ijr++) {for (inn = 1; inn < 3; inn++) {for (imr = 0; imr < 2; imr++) { bbbin[antr] = bbbin[antr - 1] + r[ijr][inn][imr]; antr++;};};}; nucbmal = 0; im = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 0; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (inn = 1; inn < 3; inn++) { nucbmal = nucbmal + p[iir][ijr][ikr][ilr][im][inn];};};};};} for (ijr = 0; ijr < 3; ijr++) {for (inn = 1; inn < 3; inn++) { nucbmal = nucbmal + r[ijr][inn][1];};}; nuccrybmal = 0; im = 1; for (iir = 0; iir < 2; iir++) {for (ijr = 1; ijr < 3; ijr++) {for (ikr = 0; ikr < 2; ikr++) {for (ilr = 0; ilr < 2; ilr++) {for (inn = 1; inn < 3; inn++) { nuccrybmal = nuccrybmal + p[iir][ijr][ikr][ilr][im][inn];};};};};} for (ijr = 1; ijr < 3; ijr++) {for (inn = 1; inn < 3; inn++) { nuccrybmal = nuccrybmal + r[ijr][inn][1];};}; }; /*Calculation of rates used in the simulation; upu is the rate of initial ubiquitination; phospdeg is the total amount of per1 and per2 that can be degraded; n stands for nucleus; */ float sumrea(float *ast, double tstt) { int i; float sdf; ast[1] = tlp*McPo;/* translation of per1*/ ast[2] = tlp*McPt;/* translation of per2*/ ast[3] = tlr*McRo;/* translation of cry1*/ ast[4] = tlr*McRt;/* translation of cry2*/ ast[5] = up*phospdeg[16]; /*degradation of phosphorylated per1 or per2*/ ast[6] = upu*Po;/* degradation of non-phosphorylated per1*/ ast[7] = upu*PoC;/* degradation of non-phosphorylated per1 bound to kinase*/ ast[8] = upu*Pt;/* degradation of non-phos per2 */ ast[9] = upu*PtC;/* deg. of non-phos per2 bound to kinase*/ ast[10] = uro*degrone[6];/* deg. of cry1*/ ast[11] = urt*degrtwo[6];/* deg. of cry2*/ ast[12] = ac*Po*C;/* binding of unphosphorylated per1 to kinase*/ ast[13] = ac*Pt*C;/* binding of unphosphorylated per2 to kinase*/ ast[14] = ac*perk[36]*C; /* binding of phosphorylated per1 or per2 to kinase, cytoplasm*/ ast[15] = ac*perkn[36]*Cn*Nf;/*binding of phosphorylated per1 or per2 to kinase, nucleus*/ ast[16] = dc*perku[72];/*unbinding of phosphorlated per1 or per2, doesn't matter if it's in cytoplasm or nucleus*/ ast[17] = ar*perr[48];/*binding of cry in cytoplasm*/ ast[18] = ar*perrn[48]*Nf;/*binding of cry in nucleus*/ ast[19] = Nf*bbin*nucubcry[18]*r[0][1][1]; /*binding of BMAL1 to CRY in nucleus*/ ast[20] = Nf*bbin*nucubcry[18]*r[0][2][1];/*binding of BMAL2 in nucleus*/ ast[21] = dr*perru[96]; /*unbinding of cry1 of cry2, cytooplasm or nucleus*/ ast[22] = nl*pernl[36];/*nuclear localization, assume it is mono-molecular reaction*/ ast[23] = ne*perne[24];/*nuclear export, assume it is mono-molecular*/ ast[24] = hoo*PoC;/*intial phos of per1*/ ast[25] = hto*PtC;/*initial phos of per2*/ ast[26] = hot*phospo[18];/*secondary phos of per1*/ ast[27] = ht*phospt[18];/*secondary phos of per2*/ ast[28] = (GPo-CPo)*trPo/2 + coupling*(2.0-CPo)*totfacr*totfacr/50;/*changed co-operativity*/ ast[29] = (GPt-CPt)*trPt/2 + coupling*(2.0-CPt)*totfacr*totfacr/50;/*(2.0-CPt)*/ ast[30] = (GRo-CRo)*trRo/2; ast[31] = (GRt-CRt)*trRt/2; ast[32] = tmc*MnPo;/* nuclear export of per1 mRNA*/ ast[33] = tmc*MnPt;/* nuclear export of per2 mRNA*/ ast[34] = tmc*MnRo;/* nuclear export of cry1 mRNA*/ ast[35] = tmc*MnRt;/* nuclear export of cry2 mRNA*/ ast[36] = umPo*McPo; /* degradation of per1 mRNA in cytoplasm*/ ast[37] = umPt*McPt;/* degradation of per2 mRNA in cytoplasm*/ ast[38] = umRo*McRo; /* degradation of cry1 mRNA in cytoplasm*/ ast[39] = umRt*McRt; /* degradation of cry2 mRNA in cytoplasm, note we assume that mRNA is exported from nucleus and then degradated in cytoplasm*/ ast[40] = bin*nucbmal*((float) (2.0 - GPo));/* binding of BMAL1/2 protein to per1 gene assuming 5 possible sites*/ ast[41] = unbin*((float) GPo);/*unbinding of BMAL1/2 to per1 gene*/ ast[42] = bin*nucbmal*((float) (2.0 - GPt));/* binding of BMAL1/2 protein to per2 gene assuming 5 possible sites*/ ast[43] = unbin*((float) GPt);/*unbinding of BMAL1/2 to per2 gene*/ ast[44] = bin*nucbmal*((float) (2.0 - GRo));/* binding of BMAL1/2 protein to cry1 gene assuming 5 possible sites*/ ast[45] = unbin*((float) GRo);/*unbinding of BMAL1/2 to cry1 gene*/ ast[46] = bin*nucbmal*((float) (2.0 - GRt));/* binding of BMAL1/2 protein to cry2 gene assuming 5 possible sites*/ ast[47] = unbin*((float) GRt);/*unbinding of BMAL1/2 to cry2 gene*/ ast[48] = bbin*cytuncry[18]*r[0][1][0]; /*binding of BMAL1 to CRY in cytoplasm*/ ast[49] = bbin*cytuncry[18]*r[0][2][0];/*binding of BMAL2 in cytoplasm*/ ast[50] = dc*PoC;/* degradation of per1 in cytoplasm bound to kinase*/ ast[51] = dc*PtC;/* degradation of per2 in cytoplasm bound to kinase*/ ast[52] = unbbin*bbbin[72];/*unbinding of BMAL*/ if (CFac > 0)/*cry2, number of repressor bound to cry2*/ ast[53] = 0.0;/*no transcription*/ else ast[53] = GFac*trfac; /*transcription rate of factor*/ ast[54] = facr*umfac; ast[55] = bin*nucbmal*((float) (1.0 - GFac));/* binding of BMAL1/2 protein to fac gene assuming 5 possible sites*/ ast[56] = unbin*((float) GFac);/*unbinding of BMAL1/2 to fac gene*/ sdf = 0; for (i = 1; i < recnum; i++) sdf = sdf + ast[i];/* sum all reaction rates for gillespie method*/ return sdf; }; /* initconds gives the initial conditions for the stochastic simulation. Some substances are zero because they have not been made yet! */ /*Below is the random number generator taken 'verbatim' from Numerical Recipes This random generator is used above to generate the 2 independent random numbers for the Gillespie Algorithm*/ float ran2(long *idum) { int j; long k; static long idum2 = 123456789; static long iy = 0; static long iv[NTAB]; float temp; if (*idum <= 0) { if (-(*idum) < 1) *idum = 1; else *idum = -(*idum); idum2=(*idum); for (j = NTAB+7; j>=0; j--) { k=(*idum)/IQ1; *idum=IA1*(*idum-k*IQ1)-k*IR1; if (*idum < 0) *idum += IM1; if (j < NTAB) iv[j] = *idum; } iy=iv[0]; } k = (*idum)/IQ1; *idum=IA1*(*idum-k*IQ1)-k*IR1; if (*idum < 0) *idum += IM1; k=idum2/IQ2; idum2=IA2*(idum2-k*IQ2)-k*IR2; if (idum2 < 0) idum2 += IM2; j = iy/NDIV; iy=iv[j]-idum2; iv[j] = *idum; if (iy < 1) iy += IMM1; if ((temp=AM*iy) > RNMX) return RNMX; else return temp; } float gasdev(long *init) { static int iset=0; static float gset; float fac, rsq, v1, v2; if (*init<0) iset=0; if (iset==0) { do { /*v1=2.0*(rand( )/(RAND_MAX+1.0))-1.0; v2=2.0*(rand( )/(RAND_MAX+1.0))-1.0;*/ v1=2.0*ran2(init)-1.0; v2=2.0*ran2(init)-1.0; rsq=v1*v1+v2*v2; } while (rsq>=1.0 || rsq == 0.0); fac=sqrt(-2.0*log(rsq)/rsq); gset=v1*fac; iset=1; return v2*fac; } else { iset=0; return gset; } }