//////////////////////////////////////////// // - Save this file as program.cpp // - Create directory data/ // - Create File param.dat of following 5 lines: // // N 10 // F 10 // mu 0.666667 // cycles 1000000 // Nsigma 20 // // - Compile with command: g++ program.cpp /////////////////////////////////////////// #include #include #include #include #include void update(double, int []); double drand(); int N, F, cycles; // N - #Nucleosomes, F - recruitment to noise ratio, cycles - #updates for each sigma int Nsigma; // # Number of bins to divide sigma=[0:1] into double mu,sigma; // mu - assymetry in the A->U->M vs M->U->A reactions int Mtime,Atime,Utime; //Mtime - #of M's at a given time... int main(int argc, char *argv[]) { char cdummy[30],file[100],dir[100]; FILE *pparam,*psigma,*phist; /////////////////////////////////////////////// // Reading Parameters from datafile param.dat /////////////////////////////////////////////// pparam=fopen("param.dat","r"); fscanf(pparam,"%s %d\n",&cdummy, &N); printf("%s %d\n",cdummy,N); fscanf(pparam,"%s %d\n",&cdummy,&F); printf("%s %d\n",cdummy,F); fscanf(pparam,"%s %lf\n",&cdummy,&mu); printf("%s %f\n",cdummy,mu); fscanf(pparam,"%s %d\n",&cdummy,&cycles); printf("%s %d\n",cdummy,cycles); fscanf(pparam,"%s %d\n",&cdummy,&Nsigma); printf("%s %d\n",cdummy,Nsigma); double alpha; // recruitment probability - alpha=F/(1+F) int AvA,AvM; // AvA - calculates the Average # of A's int Nhist[N+1]; // vector to hold the current state of the nucleosomes int histA[N+1]; // vector holding the probabilites of having Atimes=0,N ///////////////////////////////////// // Initializing //////////////////////////////////// srand(time(0)); alpha=F*1./(1.+F); // Directory nammme sprintf(dir,"data/"); // Constructing file to hold vs sigma data sprintf(file,"%sSigmaF%dmu%1.2fN%d.dat",dir,F,mu,N); psigma=fopen(file,"w"); // constructing file to hold P(A) vs. sigma data sprintf(file,"%sHistF%dmu%1.2fN%d.dat",dir,F,mu,N); phist=fopen(file,"w"); for(int i=0; i<=Nsigma; i++){ sigma=0.01*pow(10,i*2./Nsigma); Mtime=0; Atime=0; Utime=N; AvA=0; AvM=0; histA[0]=0; for(int i=1;i<=N;i++){ Nhist[i]=0; histA[i]=0; } ////////////////////////////// // Heart of Simulation... ///////////////////////////// //Getting the system into a steady state before gathering data for(int t=1;t<=500;t++){ update(alpha,Nhist); } for(int t=1;t<=cycles;t++){ update(alpha,Nhist); AvA+=Atime; AvM+=Mtime; histA[Atime]++; } for(int i=0; i<=N; i++) fprintf(phist,"%f %f %f \n",sigma, i*1./N, (histA[i]*1./(1.*N*cycles))); fflush(phist); fprintf(phist,"\n");fflush(phist); fprintf(psigma,"%f %f\n",sigma,(double) (AvA*1./(1.*N*cycles)));fflush(psigma); } fclose(psigma); fclose(phist); } /************************************************************* * Update function... *************************************************************/ void update(double alpha, int Nhist[]){ int site1,site2,site3; for(int m=1;m<=N;m++){ // Selecting nucleosome (site1) to be changed site1=(int) floor(drand()*(N-.001)+1.); // Selecting nucleosome (site2) to recruit the first nucleosome site2=site1; while(site2==site1) site2=(int) floor(drand()*(N-.001)+1.); /************************** * Noise event **************************/ if(drand()<1.-alpha){ if(Nhist[site1]==0){ // U->M if(drand()<0.5){ Nhist[site1]=1; Mtime++; Utime--; } // U->A else{ Nhist[site1]=-1; Atime++; Utime--; } } else if(Nhist[site1]==-1){ // A->U if(drand()<0.5){ Nhist[site1]=0; Atime--; Utime++; } } else if(Nhist[site1]==1){ // M->U if(drand()<0.5){ Nhist[site1]=0; Mtime--; Utime++; } } } /********************************* * Recruitive move ********************************/ else if(Nhist[site2]!=Nhist[site1] && Nhist[site2]!=0){ double ftest=drand(); // M recruits U->M with prob mu if(Nhist[site1]==0 && Nhist[site2]==1 && ftestA with prob (1-mu) else if(Nhist[site1]==0 && Nhist[site2]==-1 && ftest>=mu){ Nhist[site1]=-1; Atime++; Utime--; } // M recruits A->U with prob mu else if(Nhist[site1]==-1 && Nhist[site2]==1 && ftestU with prob (1-mu) else if(Nhist[site1]==1 && Nhist[site2]==-1 && ftest>=mu){ Utime++; Mtime--; Nhist[site1]=0; } } // Selecting site3 for TF to work on site3=(int) floor(drand()*(N-.001)+1.); //////////////////////////////////// // Sigma Working on U->A /////////////////////////////////// // If site3 is in the U state change it to A with probability sigma if(Nhist[site3]==0 && drand()