-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
661 lines (549 loc) · 17.4 KB
/
Program.cs
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/*
* Created by SharpDevelop.
* User: oferfrid
* Date: 22/02/2009
* Time: 10:30
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
namespace CyclicSimulation
{
class Program
{
public static void Main(string[] args)
{
DeferentDilutionCyclesSimulation(Convert.ToDouble(args[0]),Convert.ToDouble(args[1]),Convert.ToDouble(args[2]));
}
private static void DeferentDilutionCycleSimulation(double MutationRatio,double Dilution,double N0Persisters)
{
double Nf=1e9;
int seed=1;
double tauNormalKill=10;
double tauPersisterKill=100;
double tauGrowNormal=20;
double tauGrowResistant=tauGrowNormal;
//double N0Persisters = 1e8;
double N0normal=Nf - N0Persisters;
double N0Resisters = 0;
double NormalPersistersFraction = N0Persisters/N0normal;
string FileName = "OneExp_" + MutationRatio.ToString("0.##E+000") +"_"+Dilution.ToString() + "_" +N0Persisters.ToString("0.##E+000") +".txt";
System.IO.FileInfo myFile = new FileInfo(FileName);
myFile.Delete();
StreamWriter SR = new StreamWriter(FileName,false);
SimulationParameters SP = new SimulationParameters(Nf,10*Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant ,NormalPersistersFraction,Dilution);
Well NormalWell = new Well(N0normal,N0Persisters,N0Resisters);
Simulation NormalSimulation= new Simulation(NormalWell,seed,SP);
int cycle=0;
do
{
cycle++;
NormalWell = NormalSimulation.DoSycle();
SR.WriteLine("{0}\t{1}\t{2}\t{3}",cycle,NormalWell.NumberOfNormal,NormalWell.NumberOfPersistent,NormalWell.NumberOfResistant);
}
while (NormalWell.NumberOfResistant<Nf);
SR.Close();
}
private static void DeferentDilutionCyclesSimulation(double MutationRatio,double Dilution,double N0Persisters)
{
double Nf=1e9;
int seed;
double tauNormalKill=10;
double tauPersisterKill=100;
double tauGrowNormal=20;
double tauGrowResistant=tauGrowNormal;
//double N0Persisters = 1e6;
double N0normal=Nf - N0Persisters;
double N0Resisters = 0;
double NormalPersistersFraction = N0Persisters/N0normal;
//string FileName = "CyclesSimulation"+ MutationRatio.ToString("0.##E+0") +".txt";
string FileName = "DeferentDilutionCycleOfFixation_" + MutationRatio.ToString("0.00E+000") +"_"+Dilution.ToString()+ "_" +N0Persisters.ToString("0.##E+000")+".txt";
System.IO.FileInfo myFile = new FileInfo(FileName);
myFile.Delete();
StreamWriter SR = new StreamWriter(FileName,false);
int Simulations = 10000;
for (int sim=0;sim < Simulations;sim++)
{
seed = sim;
SimulationParameters SP = new SimulationParameters(Nf,10*Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant ,NormalPersistersFraction,Dilution);
Well NormalWell = new Well(N0normal,N0Persisters,N0Resisters);
Simulation NormalSimulation= new Simulation(NormalWell,seed,SP);
int cycle=0;
do
{
cycle++;
NormalWell = NormalSimulation.DoSycle();
}
while (NormalWell.NumberOfResistant<Nf);
SR.WriteLine(cycle);
}
SR.Close();
}
private static void CyclesSimulation()
{
double Nf=1e9;
double MutationRatio=1e-8 ;
int seed ;
double tauNormalKill=10;
double tauPersisterKill=100;
double tauGrowNormal=20;
double tauGrowResistant=tauGrowNormal;
double N0Persisters ;
double N0normal;
double N0Resisters;
double NormalPersistersFraction;
double HighPersistersFraction;
string FileName = "CyclesSimulation"+ MutationRatio.ToString("0.##E+0") +".txt";
System.IO.FileInfo myFile = new FileInfo(FileName);
myFile.Delete();
StreamWriter SR = new StreamWriter(FileName,false);
int Simulations = 10000;
for (int sim=0;sim < Simulations;sim++)
{
seed = sim;
N0Persisters = 1e6;
N0normal=Nf - N0Persisters;
N0Resisters = 0;
NormalPersistersFraction = N0Persisters/N0normal;
SimulationParameters SP ;
SP= new SimulationParameters(Nf,Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant ,NormalPersistersFraction,200);
Well NormalWell = new Well(N0normal,N0Persisters,N0Resisters);
Simulation NormalSimulation= new Simulation(NormalWell,seed,SP);
do
{
NormalWell = NormalSimulation.DoSycle();
}
while (NormalWell.NumberOfResistant<Nf);
N0Persisters = 1e8;
N0normal=Nf - N0Persisters;
N0Resisters = 0;
HighPersistersFraction = N0Persisters/N0normal;
SP = new SimulationParameters(Nf,Nf,MutationRatio,tauNormalKill,tauPersisterKill ,tauGrowNormal,tauGrowResistant,HighPersistersFraction ,200);
Well HighPersistenceWell = new Well(N0normal,N0Persisters,N0Resisters);
Simulation HighPersistenceSimulation = new Simulation(HighPersistenceWell,seed,SP);
do
{
HighPersistenceWell = HighPersistenceSimulation.DoSycle();
}
while (HighPersistenceWell.NumberOfResistant<Nf);
SR.WriteLine("{0}\t{1}",NormalSimulation.Cycle,HighPersistenceSimulation.Cycle);
NormalSimulation = null;
HighPersistenceSimulation = null;
PrintPresentege(sim,Simulations);
}
SR.Close();
}
// public static void article_diferent_mu()
// {
// double Nf=1e10;
// double[] MutationRatio={1e-6,3e-7,1e-7,1e-8,1e-9,1e-10,1e-11} ;
// //int seed =1;
// double tauKill=10;
//
// double tauGrowNormal=20;
// double tauGrowResistant=tauGrowNormal*1.05;
// double N0mutation = 0;
// double N0normal=1e10;
//
// string FileName = "article.txt";//Simulation"+ MutationRate.ToString("0.##E+0") +".txt";
// System.IO.FileInfo myFile = new FileInfo(FileName);
// myFile.Delete();
// StreamWriter SR = new StreamWriter(FileName,false);
// int sims=MutationRatio.Length;
//
// int rep = 30;
// Well[,] myTest=new Well[sims,rep] ;
// Simulation[,] mySimulation = new Simulation[sims,rep];
//
// for (int sim=0;sim<sims;sim++)
// {
// for(int i=0;i<rep;i++)
// {
// mySimulation[sim,i]= new Simulation(Nf,MutationRatio[sim],i,tauKill ,tauGrowNormal,tauGrowResistant );
// myTest[sim,i] = new Well(N0normal,0,N0mutation);
// }
//
// }
//
// int rounds=300;
// for(int round=0;round<rounds;round++)
// {
// double gen=round*Math.Log(100,2);
// SR.Write("{0}\t",gen);
//
// for (int sim=0;sim<sims;sim++)
// {
//
// for(int i=0;i<rep;i++)
// {
//
// myTest[sim,i]=mySimulation[sim,i].DoGrowing(myTest[sim,i]);
// SR.Write("{0}\t",myTest[sim,i].NumberOfResistant);
// myTest[sim,i]=mySimulation[sim,i].DoDilution(myTest[sim,i],100);
//
// }
//
// }
// SR.Write("\n");
//
// PrintPresentege(round,rounds);
// }
//
//
//
//
// SR.Close();
// }
// public static void driftstatistic()
// {
// double Nf=10000;
// double MutationRatio=1e-14;
// double tauKill=10;
//
// double tauGrowNormal=20;
// double tauGrowResistant=20;
// double N0mutation = 5000;
// double N0normal=5000;
//
// Well myTest ;
// string FileName = "ofer.txt";//Simulation"+ MutationRate.ToString("0.##E+0") +".txt";
// System.IO.FileInfo myFile = new FileInfo(FileName);
// myFile.Delete();
// StreamWriter SR = new StreamWriter(FileName,false);
//
//
//
// //SR.WriteLine(myTest.NumberOfResistant);
// for(int i=0;i<1000;i++)
// {
// Simulation mySimulation= new Simulation(Nf,MutationRatio,i,tauKill ,tauGrowNormal,tauGrowResistant );
// myTest = new Well(N0normal,0,N0mutation);
// int j=0;
// while(myTest.NumberOfResistant !=0 && myTest.NumberOfNormal !=0)
// {
// myTest=mySimulation.DoGrowing(myTest);
// //Console.WriteLine(myTest.NumberOfResistant + " " + myTest.NumberOfNormal);
// myTest=mySimulation.DoDilution(myTest,100);
// j++;
// }
// SR.WriteLine(j);
// PrintPresentege(i,1000);
// mySimulation=null;
// }
// SR.Close();
// }
//
// public static void drift()
// {
// double Nf=1e4;
// double MutationRatio=3e-7;
// //int seed =1;
// double tauKill=10;
//
// double tauGrowNormal=20;
// double tauGrowResistant=tauGrowNormal;//*1.05;
// double N0mutation = 5e3;
// double N0normal=5e3;
//
// string FileName = "drift.txt";//Simulation"+ MutationRate.ToString("0.##E+0") +".txt";
// System.IO.FileInfo myFile = new FileInfo(FileName);
// myFile.Delete();
// StreamWriter SR = new StreamWriter(FileName,false);
// int sims=10;
// Well[] myTest=new Well[sims] ;
// Simulation[] mySimulation = new Simulation[sims];
//
// for (int sim=0;sim<sims;sim++)
// {
// mySimulation[sim]= new Simulation(Nf,MutationRatio,sim,tauKill ,tauGrowNormal,tauGrowResistant );
// myTest[sim] = new Well(N0normal,0,N0mutation);
//
// }
//
// int rounds=200;
// for(int round=0;round<rounds;round++)
// {
// double gen=round*Math.Log(100,2);
// SR.Write("{0}\t",gen);
// for (int sim=0;sim<sims;sim++)
// {
//
// myTest[sim]=mySimulation[sim].DoGrowing(myTest[sim]);
// SR.Write("{0}\t",myTest[sim].NumberOfResistant);
// myTest[sim]=mySimulation[sim].DoDilution(myTest[sim],100);
//
// }
// SR.Write("\n");
// PrintPresentege(round,rounds);
// }
//
//
//
//
// SR.Close();
// }
//
// public static void drift_selection_mutation()
// {
//
// double Nf=1e4;
// double MutationRatio=3e-5;
// //int seed =1;
// double tauKill=10;
//
// double tauGrowNormal=20;
// double tauGrowResistant=tauGrowNormal*1.03;
// double N0mutation = 0;
// double N0normal=1e4;
//
// string FileName = "drift+selection+mutation.txt";//Simulation"+ MutationRate.ToString("0.##E+0") +".txt";
// System.IO.FileInfo myFile = new FileInfo(FileName);
// myFile.Delete();
// StreamWriter SR = new StreamWriter(FileName,false);
// int sims=10;
// Well[] myTest=new Well[sims] ;
// Simulation[] mySimulation = new Simulation[sims];
//
// for (int sim=0;sim<sims;sim++)
// {
// mySimulation[sim]= new Simulation(Nf,MutationRatio,sim,tauKill ,tauGrowNormal,tauGrowResistant );
// myTest[sim] = new Well(N0normal,0,N0mutation);
//
// }
//
// int rounds=200;
// for(int round=0;round<rounds;round++)
// {
// double gen=round*Math.Log(100,2);
// SR.Write("{0}\t",gen);
// for (int sim=0;sim<sims;sim++)
// {
//
// myTest[sim]=mySimulation[sim].DoGrowing(myTest[sim]);
// SR.Write("{0}\t",myTest[sim].NumberOfResistant);
// myTest[sim]=mySimulation[sim].DoDilution(myTest[sim],100);
//
// }
// SR.Write("\n");
// PrintPresentege(round,rounds);
// }
//
//
//
//
// SR.Close();
//
// }
public static void drift_selection()
{
double Nf=1e4;
double MutationRatio=3e-10;
//int seed =1;
double tauKill=10;
double tauGrowNormal=20;
double tauGrowResistant=tauGrowNormal*1.005;
double N0mutation = 5e3;
double N0normal=5e3;
string FileName = "drift+selection.txt";//Simulation"+ MutationRate.ToString("0.##E+0") +".txt";
System.IO.FileInfo myFile = new FileInfo(FileName);
myFile.Delete();
StreamWriter SR = new StreamWriter(FileName,false);
int sims=10;
Well[] myTest=new Well[sims] ;
Simulation[] mySimulation = new Simulation[sims];
SimulationParameters SP = new SimulationParameters(Nf,Nf,
MutationRatio,
tauKill,
tauKill ,
tauGrowNormal,
tauGrowResistant ,
0,200);
for (int sim=0;sim<sims;sim++)
{
myTest[sim] = new Well(N0normal,0,N0mutation);
mySimulation[sim]= new
Simulation(myTest[sim],sim,SP);
}
int rounds=200;
for(int round=0;round<rounds;round++)
{
double gen=round*Math.Log(100,2);
SR.Write("{0}\t",gen);
for (int sim=0;sim<sims;sim++)
{
myTest[sim]=mySimulation[sim].DoGrowing(myTest[sim]);
SR.Write("{0}\t",myTest[sim].NumberOfResistant);
myTest[sim]=mySimulation[sim].DoDilution(myTest[sim],100);
}
SR.Write("\n");
PrintPresentege(round,rounds);
}
SR.Close();
}
public static void drift()
{
double Nf=1e4;
double MutationRatio=3e-10;
//int seed =1;
double tauKill=10;
double tauGrowNormal=20;
double tauGrowResistent=tauGrowNormal;
double N0mutation = 5e3;
double N0normal=5e3;
string FileName = "drift.txt";//Simulation"+ MutationRate.ToString("0.##E+0") +".txt";
System.IO.FileInfo myFile = new FileInfo(FileName);
myFile.Delete();
StreamWriter SR = new StreamWriter(FileName,false);
int sims=10;
Well[] myTest=new Well[sims] ;
Simulation[] mySimulation = new Simulation[sims];
SimulationParameters SP= new SimulationParameters( Nf,Nf,
MutationRatio,
tauKill,
tauKill ,
tauGrowNormal,
tauGrowResistent ,
0,200);
for (int sim=0;sim<sims;sim++)
{
myTest[sim] = new Well(N0normal,0,N0mutation);
mySimulation[sim]= new
Simulation(myTest[sim],
sim+90,
SP);
}
int rounds=200;
for(int round=0;round<rounds;round++)
{
double gen=round*Math.Log(100,2);
SR.Write("{0}\t",gen);
for (int sim=0;sim<sims;sim++)
{
myTest[sim]=mySimulation[sim].DoGrowing(myTest[sim]);
SR.Write("{0}\t",myTest[sim].NumberOfResistant);
myTest[sim]=mySimulation[sim].DoDilution(myTest[sim],100);
}
SR.Write("\n");
PrintPresentege(round,rounds);
}
SR.Close();
}
//
// public static void OneWellinDTiale(double MutationRate)
// {
// string FileName = "Simulation"+ MutationRate.ToString("0.##E+0") +".txt";
// System.IO.FileInfo myFile = new FileInfo(FileName);
// myFile.Delete();
// StreamWriter SR = new StreamWriter(FileName,false);
//
// double tauKill = 20 / Math.Log(2);
// double tauGrow = 25 / Math.Log(2);
//
//
// Simulation s = new Simulation(1e9,MutationRate,1,tauKill,tauGrow,tauGrow);
// Well tWell;
// for(int i=0;i<1000;i++)
// {
//
//
// tWell = s.DoSycle();
// SR.WriteLine("{0:0.0e+00}\t{1:0.0e+00}\t{2:0.0e+00}",tWell.NumberOfBacteria ,tWell.NumberOfNormal,tWell.NumberOfResistant);
//
// PrintPresentege(i,1000);
// }
//
//
// SR.Close();
// Console.WriteLine("End");
// Console.Beep();
// }
//
// public static void NumberOfSycleToResistent(double MutationRate,double dilution)
// {
// string FileName = "SimulationSycleToResistentI"+ dilution + "_" + MutationRate.ToString("0.##E+0") + ".txt";
// System.IO.FileInfo myFile = new FileInfo(FileName);
// myFile.Delete();
// StreamWriter SR = new StreamWriter(FileName,false);
//
//
// double tauKill = 20 / Math.Log(2);
// double tauGrow = 25 / Math.Log(2);
//
//
// int simulation = 10000;
// for(int j=0;j<simulation;j++)
// {
// Simulation s = new Simulation(1e9,MutationRate,j,tauKill,tauGrow,tauGrow);
// Well tWell;
// do
// {
// tWell = s.DoSycle(dilution,260);
// // SR.WriteLine("{0:0.0e+00}\t{1:0.0e+00}\t{2:0.0e+00}",tWell.NumberOfBacteria ,tWell.NumberOfNormal,tWell.NumberOfResistant);
//
// }
// while (tWell.NumberOfResistant<tWell.NumberOfNormal);
// SR.WriteLine(s.Sycle.ToString() );
// PrintPresentege(j,simulation);
// }
//
//
// SR.Close();
// Console.WriteLine("End");
// Console.Beep();
// }
//
// public static void NumberOfSycleToOver(double MutationRate)
// {
// string FileName = "SimulationSycleToOver" + MutationRate.ToString("0.##E+0") + ".txt";
// System.IO.FileInfo myFile = new FileInfo(FileName);
// myFile.Delete();
// StreamWriter SR = new StreamWriter(FileName,false);
//
//
// double tauKill = 20 / Math.Log(2);
// double tauGrow = 25 / Math.Log(2);
//
//
// int simulation = 10000;
// for(int j=0;j<simulation;j++)
// {
// Simulation s = new Simulation(1e9,MutationRate,j,tauKill,tauGrow,tauGrow);
// Well tWell;
// do
// {
// tWell = s.DoSycle();
// // SR.WriteLine("{0:0.0e+00}\t{1:0.0e+00}\t{2:0.0e+00}",tWell.NumberOfBacteria ,tWell.NumberOfNormal,tWell.NumberOfResistant);
//
// }
// while (tWell.NumberOfResistant<tWell.NumberOfNormal);
// SR.WriteLine(s.Sycle.ToString() );
// PrintPresentege(j,simulation);
// }
//
//
// SR.Close();
// Console.WriteLine("End");
// Console.Beep();
// }
public static void PrintPresentege(int ind,int from)
{
//Console.WriteLine(Convert.ToInt32((double)ind/from*1000));
int fraction = Convert.ToInt32((double)ind/from*1000);
int postfraction = Convert.ToInt32((double)(ind-1)/from*1000);
if ((fraction-postfraction)>=1)
{
Console.CursorLeft = 0;
Console.Write("{0}%",((double)fraction/10).ToString("00.0"));
}
}
public static void PrintPresentege(double ind,double from)
{
//Console.WriteLine(Convert.ToInt32((double)ind/from*1000));
int fraction = Convert.ToInt32((double)ind/from*1000);
int postfraction = Convert.ToInt32((double)(ind-1)/from*1000);
Console.CursorLeft = 0;
Console.Write("{0}%",((double)fraction/10).ToString("00.0"));
}
}
}