-
Notifications
You must be signed in to change notification settings - Fork 1
/
virulence_source.updated.Oct2016.alpha-0.47.c
2018 lines (1748 loc) · 87.2 KB
/
virulence_source.updated.Oct2016.alpha-0.47.c
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************/
/********************* HIV NETWORK SIMULATOR **********************/
/************************************************************************/
// modified 9-26-14 jtm 5:57 pm
/* Simulates changes in virulence within a population */
/* Assume N individuals infected or not infected with viruses with different infection setpoint viral loads */
/* Assume probality of infection is proportional to viral load */
/* Version 1: March 26, 2010 (Just got started) */
/* Versoin 2: May 12, 2010 -- Replac edynamic model with phenomenological model */
/* Try to increase population size so that susceptibles */
/* are roughly constant */
/* Version 3: May 19, 2010 -- Added heritabilities expressed in terms of VL setpoint */
/* Create version that reads parameters from a file */
/* Other minor changes */
/* Version 4: Sept 2012 -- Added simple sexual network structure into this framework */
/* Version 5: Nov 2012 -- Added terms for treatment (percent treated & efficacy) */
/* Version 6: Dec. 6, 2012 -- Created modular version with distinct routines for easier reading */
/* This version branches off of Network16May2013_Rev25July2013.c */
#include "virulence_header.updated.h" // Includes names for variables and subroutines
long Flat_Viral_Load = 0; // Setting this to 1 forces VL to be the same value during the entire primary infection period
double PrimaryInfectionLevel = 1.0e7; // Average viral load during primary infection
double OrigAverageDegree;
double expected_time_treated;
long Progression_Model;
long VL_print_time; // Instructs program to print out VL distributions every VL_print_time days.
double VL_print_lower, VL_print_upper, VL_print_interval; // Lower and upper end of the distribution together with bin size
long VL_print_count = 0;
void PrintVLdistribution(void);
long BreakUpList1[3000001], BreakUpList2[3000001], BreakUpList3[3000001], BreakUpList4[3000001]; // These arrays track indices of partnerships to be broken up
long RevisedNumLinks[3000001];
double MutationVariance, H, h;
long OrigN;
long Start_Condom_Campaign;
double Percent_using_condums_after_condom_campaign;
double orig_prob_sex;
void ConstantInputNewSusceptibles(void);
double norm_rand(double rn_mean, double rn_variance);
/**** New flags to implement hillg transmission and time to AIDS functions *****/
int hillg_transmission_model = 1; // 0 = existing transmission, 1 = flat trans, 2 = new hillg trans function
int hillg_time_to_AIDS_model = 1; // 0 = existing random time to AIDS, 1 = flat time, 2 = new hillg time to AIDS
int main()
{
long jcount;
printf("Starting!!!\n");
printf("CD4_Exp_Flag=%d\n",CD4_Exp_Flag);
/* Initialize the population */
OpenFiles();
GetParameters();
orig_prob_sex = prob_sex;
H = Heritability;
h = sqrt(Heritability);
r0 = log(V_peak/V0)/t_peak;
Dead = 0; DiedAIDS = 0; DiedNat = 0; init_genrand(random_number_seed);
cd4InitProbs();
CreateCD4Table();
InitializePopulation();
AddInfecteds();
DefineSexualContactNetwork();
//PrintEdgeList();
//PrintFirstAndLastContacts();
time = 0;
PrintVLdistribution();
PrintHeaders();
//printf("About to print stats\n");
PrintStats();
//printf("About to enter do-while loop\n");
fflush(stdout);
OrigAverageDegree = AverageDegree;
/* Time Loop */
do {
if (VL_print_count >= VL_print_time) {
PrintVLdistribution();
VL_print_count = 0;
}
VL_print_count++;
UpdateViralLoadsForAllInfectedIndividuals();
SimulateInfectionProcessOnePersonToAnother();
ConstantInputNewSusceptibles();
NaturalDeath();
DeathOfAIDSPatients();
RemoveLinksToDeadPeople();
SimulatePartnerShipDissolution();
SimulateNewPartnershipFormation();
CheckEdgeListForImpossibleValues(); // That is, do some elementary error checking
time = time + 1;
if(printOutput==0){printf("time %ld\n",time);}
if (time == Start_SexReduction_Campaign) AverageDegree = AverageDegree/Reduction_Mean_Degree;
if (time == Start_Condom_Campaign) prob_sex = orig_prob_sex * (1.0-Percent_using_condums_after_condom_campaign); if (time == Start_Faithfulness_Campaign) {
MinDuration = MinDuration * Increased_Duration;
MaxDuration = MaxDuration * Increased_Duration;
for (jcount = 1; jcount <= N; jcount++) {
Duration[jcount] = Duration[jcount] * Increased_Duration;
}
}
// if ((time == tfinal) || (StopEarly == 1)) printf("\ntime\tN\tLinks\tUnInf\tInf\tDead\tdAIDS\tdNat\tAveLogV\t\tVstd\t\tSet_Ave\t\tSet_std\t\td_ave\t\td_std\t\tpLinks\t\tV[1]\t\td_a[1]\t\tSts[1]\n");
PrintStats();
fflush(stdout);
} while ( (time < tfinal) && (StopEarly == 0)); // End time loop
if (StopEarly == 1) {
PrintStats();
}
RecordStatusOfLivingHIVPatientsForRegistryFile();
// PrintFirstAndLastContacts();
if (Flat_Viral_Load==1) printf("Constant VL during primary infection was %lf\n",PrimaryInfectionLevel);
if (StopEarly == 1) {
printf("Note: Program halted early -- most likely because of difficulties in finding partners using current search algorithm. Consider increasing MaxLinks.\n");
}
printf("DONE (New) !!! %c%c",7,7); // print bell sounds (ascii character 7)
} // Main
void OpenFiles()
{
if ( (ParFile = fopen("Parameters.txt","r")) == NULL) { printf("Cannot open file 'Parameters.txt'. Hit ctrl-C to quit : "); scanf("%s",junk); }
if ( (OutputFile = fopen("ViralLoadOutput.txt","w")) == NULL) { printf("Cannot open file 'ViralLoadOutput.txt'. Hit ctrl-C to quit : "); scanf("%s",junk); }
if ( (HeritOutputFile = fopen("HeritabilityOutput.txt","w")) == NULL) { printf("Cannot open file 'HeritabilityOutput.txt'. Hit ctrl-C to quit : "); scanf("%s",junk); }
if ( (PatientRegistryOutputFile = fopen("PatientRegistryOutput.txt","w")) == NULL) { printf("Cannot open file 'PatientRegistryOutput.txt'. Hit ctrl-C to quit : "); scanf("%s",junk); }
if ( (VLOutputFile = fopen("VLHistogram.txt","w")) == NULL) { printf("Cannot open file 'VLOutput.txt'. Hit ctrl-C to quit : "); scanf("%s",junk); }
if ( (spVLOutputFile = fopen("spVLHistogram.txt","w")) == NULL) { printf("Cannot open file 'spVLOutput.txt'. Hit ctrl-C to quit : "); scanf("%s",junk); }
}
void PrintVLdistribution()
{
double current_VL;
long i;
long Print_Array_VL[1000];
long Print_Array_spVL[1000];
long bin_count = 0;
/* Print header giving the midpoint VL (on log scale) for each element in the histogram at time 0 */
if (time == 0) {
fprintf(VLOutputFile,"VL\t");
fprintf(spVLOutputFile,"spVL\t");
for (current_VL = VL_print_lower; current_VL <= VL_print_upper; current_VL = current_VL + VL_print_interval) {
fprintf(VLOutputFile,"%3.2lf\t", current_VL+VL_print_interval/2.0);
fprintf(spVLOutputFile,"%3.2lf\t", current_VL+VL_print_interval/2.0);
}
fprintf(VLOutputFile,"\n");
fprintf(spVLOutputFile,"\n");
}
/* Zero out elements of the histogram */
bin_count = 0;
for (current_VL = VL_print_lower; current_VL <= VL_print_upper; current_VL = current_VL + VL_print_interval) {
bin_count++;
Print_Array_VL[bin_count] = 0;
Print_Array_spVL[bin_count] = 0;
}
/* For each infected person, increment histogram cell spanning that person's viral load */
for (i=1; i<=N; i++) {
if (Status[i] == 1) {
bin_count = 0;
for (current_VL = VL_print_lower; current_VL <= VL_print_upper; current_VL = current_VL + VL_print_interval) {
bin_count++;
if ( (log10(V[i]) >= current_VL) && (log10(V[i]) < current_VL+VL_print_interval)) {
//if (time - Time_Inf[i] > 50.0) {
Print_Array_VL[bin_count] = Print_Array_VL[bin_count] + 1;
//}
}
if ( (LogSetPoint[i] >= current_VL) && (LogSetPoint[i] < current_VL+VL_print_interval)) {
Print_Array_spVL[bin_count] = Print_Array_spVL[bin_count] + 1;
}
}
}
}
/* Print histogram to a file */
bin_count = 0;
fprintf(VLOutputFile,"%ld\t", time);
fprintf(spVLOutputFile,"%ld\t", time);
for (current_VL = VL_print_lower; current_VL <= VL_print_upper; current_VL = current_VL + VL_print_interval) {
bin_count++;
fprintf(VLOutputFile,"%ld\t", Print_Array_VL[bin_count]);
fprintf(spVLOutputFile,"%ld\t", Print_Array_spVL[bin_count]);
}
fprintf(VLOutputFile,"\n");
fprintf(spVLOutputFile,"\n");
}
void InitializePopulation()
{
/* Initalizes the s[], Status[], Numrecepients[], Duration[], UnderCare[], and Treated[] arrays to their default values */
long i;
for (i=1;i<=N;i++) {
s[i] = prog_rate; // Same for all patients in this version. Could be made to vary from patient to patient in future studies
Status[i] = 0;
CD4[i] = 0;
CD4_TimeToAIDS[i]= 0;
NumRecipients[i] = 0;
if (genrand_real2() < 0.10) { // 0.15 is what I had 14th November, which worked
Duration[i] = MinDuration;
} else {
Duration[i] = MinDuration + genrand_real2()*(MaxDuration-MinDuration);
}
UnderCare[i] = 0; // Set to zero to start. This will be updated in AddInfecteds() below
Treated[i] = 0; // Assume no treatment for initial population
}
}
void AddInfecteds()
{
long i;
double num, den,f_pow;
for (i=1;i<=Infected;i++) {
ViralContribToLogSP0[i] = norm_rand(AverageLogSP0, sqrt(H*VarianceLogSP0));
EnvirContribToLogSP0[i] = norm_rand(0, sqrt((1-H)*VarianceLogSP0));
LogSetPoint[i] = ViralContribToLogSP0[i] + EnvirContribToLogSP0[i];
SpvlCat[i]=SPVL_Category(LogSetPoint[i] );
CD4[i]=initialCD4(SpvlCat[i]);
CD4_initial_value[i]=CD4[i];
//adding exponential distribution for time in each cd4 category
CD4_TimeToAIDS_exp[i][1]=log(genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[i]][1]) ;
CD4_TimeToAIDS_exp[i][2]=log(genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[i]][2]) ;
CD4_TimeToAIDS_exp[i][3]=log(genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[i]][3]) ;
CD4_TimeToAIDS_exp[i][4]=log(genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[i]][4]) ;
if(CD4_Exp_Flag==1)
{
double ll=0.0;
int kk;
for(kk=CD4[i];kk<=3;kk++)
{
ll+=CD4_TimeToAIDS_exp[i][kk];
}
CD4_TimeToAIDS[i]=ll;
}
//printf("%d----%f\n",i,CD4_TimeToAIDS_exp[i][1]);
//printf("%d -- %d -- %d\n",i,SpvlCat[i], CD4[i]);
//printf("-- %d --", CD4[i]);
SetPoint[i] = pow(10.0,LogSetPoint[i]);
d_acute[i] = log(V_peak/SetPoint[i])/(t_acute - t_peak);
Status[i] = 1;
Generation[i] = 1;
if (SetPoint[i] > DefinitionHighSetPoint && CD4_Determines_Treatment==0) {
if (genrand_real2() < percent_under_care + Increment_Prob_Under_Care_High_spVL) {
UnderCare[i] = 1;
}
} else {
if (genrand_real2() < percent_under_care && CD4_Determines_Treatment==0) {
UnderCare[i] = 1;
}
}
if (CD4[i] > DefinitionHighSetPoint_CD4 && CD4_Determines_Treatment==1) {
if (genrand_real2() < percent_under_care + Increment_Prob_Under_Care_High_CD4) {
UnderCare[i] = 1;
}
} else {
if (genrand_real2() < percent_under_care && CD4_Determines_Treatment==1) {
UnderCare[i] = 1;
}
}
if (Gamma_Death == 1) {
ExpectedDelayTime = Dmax*pow(D50,Dk)/(pow(SetPoint[i],Dk) + pow(D50,Dk));
theta = ExpectedDelayTime/shape_parameter;
//printf("For patient %ld: ExpectedDelayTime = %lf, shape_parameter = %lf, theta = %lf\n",i,ExpectedDelayTime,shape_parameter,theta);
// New section to implement FRANCOIS AND CHRISTOPHE time to AIDS FUNCTIONS HERE
if (hillg_time_to_AIDS_model == 0) RandomTimeToAIDS[i] = t_acute + GetGammaDelay(shape_parameter,theta); // existing function
if (hillg_time_to_AIDS_model == 1) { // FRANCOIS AND CHRISTOPHE's flat function
if (log10(SetPoint[i]) < 4.082279) RandomTimeToAIDS[i] = 40.470557 * 365.0; // YEARS.
if ((log10(SetPoint[i]) >= 4.082279) && (log10(SetPoint[i]) < 5.126785)) RandomTimeToAIDS[i] = 11.546204 * 365.0;
if (log10(SetPoint[i]) >= 5.126785) RandomTimeToAIDS[i] = 4.882448 * 365.0;
}
if (hillg_time_to_AIDS_model == 2) { // FRANCOIS AND CHRISTOPHE's hillg function
num = 39.999994 - 3.933318;
den = 1 + pow(10.0,-2.451946 * (3.514889 - log10(SetPoint[i])));
f_pow = 1/3.801692;
RandomTimeToAIDS[i] = (3.933318 + num / pow(den,f_pow) ) * 365.0;
}
} else { // Not gamma death
RandomTimeToAIDS[i] = 1000000000.0;
}
Time_Inf[i] = -t_acute - genrand_real2()*(364-t_acute);
CD4time[i]=-Time_Inf[i] ;
CD4_treatment_delay_index[i]=-Time_Inf[i];
//Time_Inf[1] = 0.0; // This and next line are special cases for debugging purposes
//RandomTimeToAIDS[1] = 365.0;
if (time <= Time_Inf[i] + t_acute) {
if (Flat_Viral_Load == 1 ) {
V[i] = PrimaryInfectionLevel;
} else {
if (time <= Time_Inf[i] + t_peak) {
V[i] = V0*exp(r0*(time-Time_Inf[i]));
} else {
V[i] = V0*exp(r0*t_peak)*exp(-d_acute[i]*(time - t_peak - Time_Inf[i]));
}
}
} else {
Vss = V0*exp(r0*t_peak)*exp(-d_acute[i]*(t_acute-t_peak));
V[i] = Vss*exp(s[i]*(time - t_acute - Time_Inf[i])/365.0);
if ((Gamma_Death == 1) && (Progression_Model == 2)) {// Alternative model in which viral load jumps to half its peak level at AIDS
if ((time > Time_Inf[i] + RandomTimeToAIDS[i]) && CD4_Death!=1) {
V[i] = 100000;
}
if (CD4[i]==4 && CD4_Death==1) {
V[i] = 100000;
}
}
}
if (V[i] < 0.0) V[i] = 0.0;
Donors_V[i] = -1.0; // Flag absence of information with -1's or zeros.
Donors_ViralContribToLogSP0[i] = -1.0; // Flag absence of information with -1's or zeros
Donors_EnvirContribToLogSP0[i] = -1.0; // Flag absence of information with -1's or zeros
Donors_LogSetPoint[i] = -1.0; // Flag absence of information with -1's or zeros
Donors_SetPoint[i] = 0.0; // Flag absence of information with -1's or zeros
Donors_d_acute[i] = -1.0; // Flag absence of information with -1's or zeros
Donors_Total_Time_Inf_At_Trans[i] = -999.0; // Set unknown donors for the initial infected population to -1 year
Donors_Generation[i] = 0;
Donors_Index[i] = 0;
if (Gamma_Death == 1) {
if(Donors_RandomTimeToAIDS_Flag==1) {
// New section to implement FRANCOIS AND CHRISTOPHE time to AIDS FUNCTIONS HERE
// Note that calculations for the Donors_RandomTimeToAIDS in this section are not particularly meaningful
// I leave them here for compatibility of various graphing functions
if (hillg_time_to_AIDS_model == 0) { // existing function
ExpectedDelayTime = Dmax*pow(D50,Dk)/(pow(Donors_SetPoint[i],Dk) + pow(D50,Dk));
theta = ExpectedDelayTime/shape_parameter;
//printf("For patient %ld: ExpectedDelayTime = %lf, shape_parameter = %lf, theta = %lf\n",i,ExpectedDelayTime,shape_parameter,theta);
Donors_RandomTimeToAIDS[i] = t_acute + GetGammaDelay(shape_parameter,theta);
}
if (hillg_time_to_AIDS_model == 1) { // FRANCOIS AND CHRISTOPHE's flat function
if ( log10(Donors_SetPoint[i]) < 4.082279) Donors_RandomTimeToAIDS[i] = 40.470557 * 365.0; // Converted from years to days
if ((log10(Donors_SetPoint[i]) >= 4.082279) && (log10(Donors_SetPoint[i]) < 5.126785)) Donors_RandomTimeToAIDS[i] = 11.546204 * 365.0;
if ( log10(Donors_SetPoint[i]) >= 5.126785) Donors_RandomTimeToAIDS[i] = 4.882448 * 365.0;
}
if (hillg_time_to_AIDS_model == 2) {// FRANCOIS AND CHRISTOPHE's hillg function
num = 39.999994 - 3.933318;
den = 1 + pow(10.0,-2.451946 * (3.514889 - log10(Donors_SetPoint[i])));
f_pow = 1/3.801692;
Donors_RandomTimeToAIDS[i] = (3.933318 + num / pow(den,f_pow)) * 365.0;
}
} else { // Not Donors_RandomTimeToAIDS_Flag
ExpectedDelayTime = Dmax*pow(D50,Dk)/(pow(Donors_SetPoint[i],Dk) + pow(D50,Dk));
theta = ExpectedDelayTime/shape_parameter;
Donors_RandomTimeToAIDS[i] = ExpectedDelayTime;
}
} else { // Not gamma death
Donors_RandomTimeToAIDS[i] = 1000000000.0;
}
//printf("%ld\t%ld\t%ld\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%6.5e\n",
// time,i,Generation[i],V[i],LogSetPoint[i],ViralContribToLogSP0[i],EnvirContribToLogSP0[i],d_acute[i],time-Time_Inf[i]);
}
}
double norm_rand(double rn_mean, double rn_variance)
{
double rand1, rand2;
rand1 = genrand_real2(); rand2 = genrand_real2();
return(rn_mean + rn_variance*sqrt(-2.0*log(rand1))*cos(2.0*3.14159265358979*rand2));
}
void DefineSexualContactNetwork()
{
long i,j;
for (i=1;i<=N;i++) {
NumLinks[i] = 0;
for (j=1;j<=5;j++) {
Links[i][j] = 0;
}
}
TotalEdges = (long) ( N * AverageDegree / 2.0 + 0.5);
//Links_Broken_Per_Day = N/(30);
//Links_Broken_Per_Day = N/(3*365);
for (i=1;i<=TotalEdges;i++) {
AddNewLink();
}
}
/*void PrintEdgeList()
{
long i,j;
for (i=1;i<=N;i++) {
if (Status[i] == 0) printf("Person %ld is linked to : ",i);
if (Status[i] == 1) printf("Person %ld* is linked to : ",i);
for (j=1;j<=NumLinks[i];j++) {
if (j==1) printf("%ld",Links[i][j]);
if (j>1) printf(", %ld",Links[i][j]);
if (Status[Links[i][j]] == 1) printf("*");
}
printf("\n");
}
fflush(stdout);
//printf("Type 'c' to continue : ");
//scanf("%s",junk);
} */
void PrintFirstAndLastContacts()
{
if(printOutput==1)
{
printf("At time %ld: the first (6) and last (6) contacts are: \n",time);
if (N > 20) {
for (i=1;i<=6;i++) {
if (Status[i] == 0) printf("Person %ld is linked to : ",i);
if (Status[i] == 1) printf("Person %ld* is linked to : ",i);
if (Status[i] <0 ) printf("Person %ld : dead ",i);
for (j=1;j<=NumLinks[i];j++) {
if (j==1) printf("%ld",Links[i][j]);
if (j>1) printf(", %ld",Links[i][j]);
if (Status[Links[i][j]] == 1) printf("*");
}
printf("\n");
}
for (i=N/2-3;i<=N/2+3;i++) {
if (Status[i] == 0) printf("Person %ld is linked to : ",i);
if (Status[i] == 1) printf("Person %ld* is linked to : ",i);
if (Status[i] <0 ) printf("Person %ld : dead ",i);
for (j=1;j<=NumLinks[i];j++) {
if (j==1) printf("%ld",Links[i][j]);
if (j>1) printf(", %ld",Links[i][j]);
if (Status[Links[i][j]] == 1) printf("*");
}
printf("\n");
}
for (i=N-6;i<=N;i++) {
if (Status[i] == 0) printf("Person %ld is linked to : ",i);
if (Status[i] == 1) printf("Person %ld* is linked to : ",i);
if (Status[i] <0 ) printf("Person %ld : dead ",i);
for (j=1;j<=NumLinks[i];j++) {
if (j==1) printf("%ld",Links[i][j]);
if (j>1) printf(", %ld",Links[i][j]);
if (Status[Links[i][j]] == 1) printf("*");
}
printf("\n");
}
} else {
for (i=1;i<=N;i++) {
if (Status[i] == 0) printf("Person %ld is linked to : ",i);
if (Status[i] == 1) printf("Person %ld* is linked to : ",i);
if (Status[i] <0 ) printf("Person %ld : dead ",i);
for (j=1;j<=NumLinks[i];j++) {
if (j==1) printf("%ld",Links[i][j]);
if (j>1) printf(", %ld",Links[i][j]);
if (Status[Links[i][j]] == 1) printf("*");
}
printf("\n");
}
}
}
}
void CreateCD4Table()
{
/* Look up table for CD4 counts from Cori,Fraser,Pickles TableS13 Supplement; years spent in cat.*/
//logSPVL <= 3
CD4_lookup[1][1]=6.08;
CD4_lookup[1][2]=3.83;
CD4_lookup[1][3]=3.60;
//CD4_lookup[1][4]=1.85;
CD4_lookup[1][4]=0.25; //15.36 vs 14.51
//CD4_lookup[1][4]=1;
//3 < logSPVL <= 3.5
CD4_lookup[2][1]=4.69;
CD4_lookup[2][2]=2.12;
CD4_lookup[2][3]=4.18;
//CD4_lookup[2][4]=0.72;
CD4_lookup[1][4]=0.25; //11.71 vs 11.99
//CD4_lookup[1][4]=1;
//3.5 < logSPVL <= 4
CD4_lookup[3][1]=3.94;
CD4_lookup[3][2]=3.08;
CD4_lookup[3][3]=2.38;
//CD4_lookup[3][4]=2.16;
CD4_lookup[3][4]=0.25; //11.56 vs 10.4
//CD4_lookup[3][4]=1;
//4 < logSPVL <= 4.5
CD4_lookup[4][1]=2.96;
CD4_lookup[4][2]=2.64;
CD4_lookup[4][3]=3.81;
//CD4_lookup[4][4]=0.80;
CD4_lookup[4][4]=0.25; //10.21 vs 9.91
//CD4_lookup[4][4]=0.25;
//4.5 < logSPVL <= 5
CD4_lookup[5][1]=2.25;
CD4_lookup[5][2]=2.13;
CD4_lookup[5][3]=3.21;
//CD4_lookup[5][4]=0.82;
CD4_lookup[5][4]=0.25; //8.41 vs 8.09
//CD4_lookup[5][4]=0.25;
//5 < logSPVL <= 5.5
CD4_lookup[6][1]=1.47;
CD4_lookup[6][2]=1.44;
CD4_lookup[6][3]=2.27;
//CD4_lookup[6][4]=0.56;
CD4_lookup[6][4]=0.25; //5.74 vs 5.68
//CD4_lookup[6][4]=0.25;
//5.5 < logSPVL <= 6
CD4_lookup[7][1]=0.95;
CD4_lookup[7][2]=1.42;
//CD4_lookup[7][3]=3.08;
CD4_lookup[7][3]=1.00;
//CD4_lookup[7][4]=0.13;
CD4_lookup[7][4]=0.25; //5.58 vs 3.62
//CD4_lookup[7][4]=0.15;
//6 < logSPVL < 6.5
CD4_lookup[8][1]=0.32;
CD4_lookup[8][2]=0.44;
CD4_lookup[8][3]=0.68;
//CD4_lookup[8][4]=0.07;
CD4_lookup[8][4]=0.25; //1.51 vs 1.69
//CD4_lookup[8][4]=0.15;
//logSPVL > 6.5
CD4_lookup[9][1]=0.30;
CD4_lookup[9][2]=0.35;
CD4_lookup[9][3]=0.37;
//CD4_lookup[9][4]=0.67;
CD4_lookup[9][4]=0.25; //1.69 vs 1.27
//CD4_lookup[9][4]=0.15;
}
int SPVL_Category(double SPVL_param)
{
int SPVL_cat;
if(SPVL_param<=3.0){SPVL_cat = 1;}
else{if(SPVL_param<=3.5){SPVL_cat = 2;}
else{if(SPVL_param<=4.0){SPVL_cat = 3;}
else{if(SPVL_param<=4.5){SPVL_cat = 4;}
else{if(SPVL_param<=5.0){SPVL_cat = 5;}
else{if(SPVL_param<=5.5){SPVL_cat = 6;}
else{if(SPVL_param<=6.0){SPVL_cat = 7;}
else{if(SPVL_param<=6.5){SPVL_cat = 8;}
else{SPVL_cat = 9;}}}}}}}}
return(SPVL_cat);
}
void cd4InitProbs(){
//From Pickles CD4 report supplement, table3
cd4_initProbs[1][1]=0.0;
cd4_initProbs[1][2]=0.12;
cd4_initProbs[1][3]=0.88;
cd4_initProbs[2][1]=0.01;
cd4_initProbs[2][2]=0.12;
cd4_initProbs[2][3]=0.87;
cd4_initProbs[3][1]=0.03;
cd4_initProbs[3][2]=0.12;
cd4_initProbs[3][3]=0.85;
cd4_initProbs[4][1]=0.03;
cd4_initProbs[4][2]=0.19;
cd4_initProbs[4][3]=0.78;
cd4_initProbs[5][1]=0.05;
cd4_initProbs[5][2]=0.21;
cd4_initProbs[5][3]=0.73;
cd4_initProbs[6][1]=0.04;
cd4_initProbs[6][2]=0.25;
cd4_initProbs[6][3]=0.71;
cd4_initProbs[7][1]=0.09;
cd4_initProbs[7][2]=0.27;
cd4_initProbs[7][3]=0.64;
cd4_initProbs[8][1]=1.0;//having all 3 probs =1, forces into box 3
cd4_initProbs[8][2]=1.0;
cd4_initProbs[8][3]=1.0;
cd4_initProbs[9][1]=1.0;
cd4_initProbs[9][2]=1.0;
cd4_initProbs[9][3]=1.0;
}
int initialCD4(int spvl_level){
//can only be 1,2,3 initially
int tempCat;
double tempProb;
tempProb=genrand_real2();
if(tempProb<cd4_initProbs[spvl_level][1]){tempCat=3;}
else{if(tempProb<cd4_initProbs[spvl_level][2]){tempCat=2;}
else{tempCat=1;}}
// printf("%d",tempCat);
return(tempCat);
}
void UpdateViralLoadsForAllInfectedIndividuals()
{
long i;
double tempTime,TimeParam;
for (i=1;i<=N;i++) {
if (Status[i] == 1) {
// CD4 update -----------------------------
if(CD4[i]<5)
{
TimeParam = (CD4time[i])/365.0;
if(CD4_Exp_Flag==0)
{
tempTime = CD4_lookup[SpvlCat[i]][CD4[i]];
}else{
tempTime = CD4_TimeToAIDS_exp[i][CD4[i]];
//printf("tempTime---%f",tempTime);
}
if( TimeParam > tempTime )
{
CD4[i]=CD4[i]+1;
CD4time[i]=0;
if( CD4[i] == TreatmentThreshold_CD4){
CD4_treatment_delay_index[i]=time;}
if(CD4[i]==4 && CD4time[i]==0 && CD4_Exp_Flag==0)
{
CD4_TimeToAIDS[i]=(long)(time-Time_Inf[i]);
}
}else{CD4time[i]=CD4time[i]+1;}
}
//end of CD4 update -------------------------
if (time <= Time_Inf[i] + t_acute) {
if (Flat_Viral_Load == 1 ) {
V[i] = PrimaryInfectionLevel;
} else {
if (time <= Time_Inf[i] + t_peak) {
V[i] = V0*exp(r0*(time-Time_Inf[i]));
} else {
V[i] = V0*exp(r0*t_peak)*exp(-d_acute[i]*(time - t_peak - Time_Inf[i]));
}
//if (i==1) printf("time <= Time_Inf[1] + t_acute, V[i] = %lf (Time_Inf[1] = %lf) \n",V[i],Time_Inf[i]);
}
} else {
Vss = V0*exp(r0*t_peak)*exp(-d_acute[i]*(t_acute-t_peak));
V[i] = Vss*exp(s[i]*(time - t_acute - Time_Inf[i])/365.0);
if ((Gamma_Death == 1) && (Progression_Model == 2)) { // Alternative model in which viral load jumps to half its peak level at AIDS
if ((time > Time_Inf[i] + RandomTimeToAIDS[i]) && CD4_Death!=1) {
V[i] = 100000; //;
}
if (CD4[i]==4 && CD4_Death==1) {
V[i] = 100000; //;
}
}
//if(i==1) printf("time > Time_Inf[1] + t_acute, so V[i] = %lf (time = %ld, Time_Inf[1] = %lf, t_acute = %lf, Vss = %lf) \n",
//V[i],time,Time_Inf[1],t_acute,Vss);
}
if ( (time > Start_Treatment_Campaign) && ((Treated[i] == 0) && (UnderCare[i] == 1)) ) { // Note only do this if Treated == 0, so as to not allow backsliding
//treatment based on VL (not cd4)
if (CD4_Determines_Treatment==0 && (time - Time_Inf[i] > TreatmentTimeInPatients) && (V[i] > TreatmentThreshold)) { /* Two ways to get under treatment: by time_treated (old method) or by VL (new method) */
Treated[i] = 1;
}
//treatment based on cd4 count
if (CD4_Determines_Treatment==1 &&
(CD4[i] >= TreatmentThreshold_CD4 ) &&
(time - Time_Inf[i] > TreatmentTimeInPatients) &&
(time-CD4_treatment_delay_index[i]) >= 365) { /* Two ways to get under treatment: by time_treated (old method) or by VL (new method) */
Treated[i] = 1;
}
}
if (Treated[i] == 1) {
V[i] = VL_After_Treatment;
CD4[i]= CD4_After_Treatment;
}
if (V[i] < 0.0) {
V[i] = 0.0;
}
}
}
}
void SimulateInfectionProcessOnePersonToAnother()
{
long Infector, Recipient; // Potential infector and Recipient
long i,j;
long random_person;
double Specific_Prob_Sex;
double num, den, f_pow, Inf_Prob_per_year; // New parameters for the hillg transmission function
for (i=1;i<=N;i++ ) {
HadSexAlready[i] = 0; // Refers to whether person had sex today
}
for (random_person=1; random_person<=N; random_person++) {
i = genrand_real2()*N + 1; // Select person i at random
if (NumLinks[i] >= 1) {
random_partner = genrand_real2()*NumLinks[i] + 1; // Person i selects one of his or her sex partners each day. (Assumes coital dilution)
j = Links[i][random_partner]; // That person is person j
if ( ((Status[i] + Status[j] == 1) && (max(Status[i],Status[j]) == 1)) && (HadSexAlready[i] + HadSexAlready[j] == 0)) {
if (Status[i] == 1) {
Infector = i;
Recipient = j;
} else{
Infector = j;
Recipient = i;
}
if (Duration[i] + Duration[j] <= 2*365) {
Specific_Prob_Sex = 1*prob_sex;
} else {
if (Duration[i] + Duration[j] <= 2.5*365.0) {
//Specific_Prob_Sex = 0.05*prob_sex;
Specific_Prob_Sex = 0.99*prob_sex; // 0.6 works with Francois flat model at middle h2
} else {
//Specific_Prob_Sex = 0.03*prob_sex;
Specific_Prob_Sex = 0.99*prob_sex; // 0.5 works with Francois flat model at middle h2
}
}
if (genrand_real2() < Specific_Prob_Sex) {
HadSexAlready[Infector] = 1;
HadSexAlready[Recipient] = 1;
if (Inf_Rate_Function == 1) {
if (V[Infector] > VL_After_Treatment)
Inf_Prob = InfRateBaseline*pow(log10(V[Infector]), InfRateExponent);
else
Inf_Prob = 0.0; // power function gives negative values if V < 1.0 (Shouldn't be much of a problem in real-life)
} else { // Inf_Rate_Function != 1
if (V[Infector] > VL_After_Treatment) {
// New section to implement FRANCOIS AND CHRISTOPHE Trasmission FUNCTIONS HERE
if (hillg_transmission_model == 0) { // Existing function
beta = HillCoeffInfRate;
Inf_Prob = MaxInfRate * pow(V[Infector],beta) / (pow(V[Infector],beta) + pow(VHalfMaxInfRate,beta));
}
if (hillg_transmission_model == 1) { // Francois and Christophe's flat function
if ( log10(V[Infector]) < 3.36565029) Inf_Prob_per_year = 0.01910758;
if ((log10(V[Infector]) >= 3.36565029) && (log10(V[Infector]) < 4.43692255)) Inf_Prob_per_year = 0.07348215;
if ( log10(V[Infector]) >= 4.43692255) Inf_Prob_per_year = 0.14301851;
//Inf_Prob = 1 - pow((1 - Inf_Prob_per_year), (1.0/365.0));
Inf_Prob = 3.3*(1 - pow((1 - Inf_Prob_per_year), (1.0/365.0))); //4.3 for plot for Francois' poster
}
if (hillg_transmission_model == 2) { // Francois and Christophe's Hill function
//num = 0.17685326 - 0.01584756;
num = 0.6 - 0.01584756;
den = 1 + pow(10.0,(-0.52153589 * (log10(V[Infector]) - 0.40564718)));
f_pow = 1/0.01459514;
Inf_Prob_per_year = 0.01584756 + num / pow(den,f_pow);
Inf_Prob = 1 - pow((1 - Inf_Prob_per_year), (1.0/365.0));
}
} else { // V[Infector] < VL_After_Treatment
Inf_Prob = 0.0;
}
} // End Inf_Rate_Function != 1
randnum = genrand_real2();
if (randnum < Inf_Prob) {
Time_Inf[Recipient] = time;
V[Recipient] = V0;
//Patient inherits previous patient's virus + mutational deviation
//ViralContribToLogSP0[Recipient] = ViralContribToLogSP0[Infector] + norm_rand(0, ((time-Time_Inf[Infector])/365)*MutationVariance);
ViralContribToLogSP0[Recipient] = ViralContribToLogSP0[Infector] + norm_rand(-0.47, MutationVariance);
// Environmental component is independent
EnvirContribToLogSP0[Recipient] = norm_rand(0, sqrt((1-H)*VarianceLogSP0));
LogSetPoint[Recipient] = ViralContribToLogSP0[Recipient] + EnvirContribToLogSP0[Recipient];
SetPoint[Recipient] = pow(10.0, LogSetPoint[Recipient]);
if (SetPoint[Recipient] > DefinitionHighSetPoint && CD4_Determines_Treatment==0) {
if (genrand_real2() < percent_under_care + Increment_Prob_Under_Care_High_spVL) {
UnderCare[Recipient] = 1;
}
} else {
if (genrand_real2() < percent_under_care && CD4_Determines_Treatment==0) {
UnderCare[Recipient] = 1;
}
}
if (CD4[Recipient] > DefinitionHighSetPoint_CD4 && CD4_Determines_Treatment==1) {
if (genrand_real2() < percent_under_care + Increment_Prob_Under_Care_High_CD4) {
UnderCare[Recipient] = 1;
}
} else {
if (genrand_real2() < percent_under_care && CD4_Determines_Treatment==1) {
UnderCare[Recipient] = 1;
}
}
d_acute[Recipient] = log(V_peak/SetPoint[Recipient])/(t_acute - t_peak);
if (Gamma_Death == 1) {
// New section to implement FRANCOIS AND CHRISTOPHE time to AIDS FUNCTIONS HERE
if (hillg_time_to_AIDS_model == 0) { // Existing function
ExpectedDelayTime = Dmax*pow(D50,Dk)/(pow(SetPoint[Recipient],Dk) + pow(D50,Dk));
theta = ExpectedDelayTime/shape_parameter;
RandomTimeToAIDS[Recipient] = t_acute + GetGammaDelay(shape_parameter,theta); // existing function
}
if (hillg_time_to_AIDS_model == 1) { // FRANCOIS AND CHRISTOPHE's flat function
if ( log10(SetPoint[Recipient]) < 4.082279) RandomTimeToAIDS[Recipient] = 40.470557 * 365.0; // Converted from years to days
if ((log10(SetPoint[Recipient]) >= 4.082279) && (log10(SetPoint[Recipient]) < 5.126785)) RandomTimeToAIDS[Recipient] = 11.546204 * 365.0;
if ( log10(SetPoint[Recipient]) >= 5.126785) RandomTimeToAIDS[Recipient] = 4.882448 * 365.0;
}
if (hillg_time_to_AIDS_model == 2) {// FRANCOIS AND CHRISTOPHE's hillg function
num = 39.999994 - 3.933318;
den = 1 + pow(10.0,-2.451946 * (3.514889 - log10(SetPoint[Recipient])));
f_pow = 1/3.801692;
RandomTimeToAIDS[Recipient] = (3.933318 + num / pow(den,f_pow)) * 365.0;
}
} else { // Not gamma death
RandomTimeToAIDS[Recipient] = 1000000000.0;
}
Generation[Recipient] = Generation[Infector] + 1;
Status[Recipient] = 1;
SpvlCat[Recipient]=SPVL_Category(LogSetPoint[Recipient] );
CD4[Recipient]=initialCD4(SpvlCat[Recipient]);
CD4_initial_value[Recipient]=CD4[Recipient];
CD4time[Recipient]=0;
CD4_treatment_delay_index[Recipient]=time;
//adding exponential distribution for time in each cd4 category
//can tighten this up once it gets working....
CD4_TimeToAIDS_exp[Recipient][1]=log( genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[Recipient]][1]) ;
CD4_TimeToAIDS_exp[Recipient][2]=log( genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[Recipient]][2]) ;
CD4_TimeToAIDS_exp[Recipient][3]=log( genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[Recipient]][3]) ;
CD4_TimeToAIDS_exp[Recipient][4]=log( genrand_real2()) / (-1.0/CD4_lookup[SpvlCat[Recipient]][4]) ;
if(CD4_Exp_Flag==1)
{
double ll=0;
int kk;
for(kk=CD4[Recipient];kk<=3;kk++)
{
ll+=CD4_TimeToAIDS_exp[Recipient][kk];
}
CD4_TimeToAIDS[Recipient]=ll;
}
Donors_ViralContribToLogSP0[Recipient] = ViralContribToLogSP0[Infector];
Donors_EnvirContribToLogSP0[Recipient] = EnvirContribToLogSP0[Infector];
Donors_d_acute[Recipient] = d_acute[Infector];
Donors_RandomTimeToAIDS[Recipient] = RandomTimeToAIDS[Infector];
Donors_Total_Time_Inf_At_Trans[Recipient] = time - Time_Inf[Infector];
Donors_V[Recipient] = V[Infector];
Donors_Generation[Recipient] = Generation[Infector];
Donors_SetPoint[Recipient] = SetPoint[Infector];
Donors_LogSetPoint[Recipient] = LogSetPoint[Infector];
Donors_Index[Recipient] = Infector;
NumRecipients[Infector] = NumRecipients[Infector] + 1;
} // Infection event occurred
} // Couple had sex
} // Status[i] + Status[j] == 1 (i.e., opportunity for new infection) & they hadn't already had sex
} // Person i has at least one partner
} // for i = 1 to N
}
void ConstantInputNewSusceptibles()
{
double NewSusceptiblesPerDayDouble;
long NewSusceptiblesPerDay;
long i;
newbirths = 0;
if (MaxNReached ==0) {
NewSusceptiblesPerDayDouble = ((double) OrigN ) * NaturalDeathRate;
NewSusceptiblesPerDay = (long) (NewSusceptiblesPerDayDouble + 0.5);
if (time == 10 && printOutput==1) {
printf("At time %ld, NewSusceptiblesPerDay = %ld\n", time, NewSusceptiblesPerDay);
}
for (i=1;i<=NewSusceptiblesPerDay;i++) {
if (N < MaxN) {
N++;
newbirths++;
s[N] = prog_rate; // Same for all patients in this version. Could be made to vary from patient to patient in futures studies
Status[N] = 0;
NumRecipients[N] = 0;
if (genrand_real2() < 0.10) { // 0.10
Duration[N] = MinDuration;
} else {
Duration[N] = MinDuration + genrand_real2()*(MaxDuration-MinDuration);
}
NumLinks[N] = 0;
for (j=1;j<=MaxLinks;j++) Links[N][j] = 0;
UnderCare[N] = 0;
Treated[N] = 0;
} else {
if (MaxNReached ==0) {
printf("Warning: MaxN reached. No more births or reincarnation events allowed\n");
MaxNReached = 1;
tMaxNReached = time;
} // MaxNReached
} // else part of N < MaxN
} // for i = 1 to N
} // MaxNReached == 0
}
void BirthOfNewSusceptibles()
{
newbirths = 0;
if ((BirthRate > 0.0) && (MaxNReached ==0)) {
currN = N;
// printf("At time %ld, but before births : NumLinks[100],NumLinks[360] = %ld\n",time,NumLinks[100],NumLinks[360]);
for (i=1;i<=currN;i++) {
if (Status[i] == 0) {
randnum = genrand_real2();
//printf("Testing to see if person %ld will give birth: comparing randnum (= %lf) to BirthRate (= %lf)\n",i,randnum,BirthRate);
if (randnum < BirthRate) {
//printf("Potential birth for person %ld, N = %ld, MaxN = %ld\n",i,N,MaxN);
if (N < MaxN) {
N++;
newbirths++;
s[N] = prog_rate; // Same for all patients in this version. Could be made to vary from patient to patient in futures studies
Status[N] = 0;
NumRecipients[N] = 0;
if (genrand_real2() < 0.10) {
Duration[N] = MinDuration;
} else {
Duration[N] = MinDuration + genrand_real2()*(MaxDuration-MinDuration); }
NumLinks[N] = 0;
for (j=1;j<=MaxLinks;j++) Links[N][j] = 0;
UnderCare[N] = 0;
Treated[N] = 0;
} else {
if (MaxNReached ==0) {
printf("Warning: MaxN reached. No more births or reincarnation events allowed\n");
MaxNReached = 1;
tMaxNReached = time;
}
} // MaxN Reached
} // randnum < birthrate
} // Status == 1
} // for i = 1 to N
}
}
void NaturalDeath()
{
long i;
for (i=1;i<=N;i++) {
if (Status[i] >= 0) {
randnum = genrand_real2();
if (randnum < NaturalDeathRate) {
Status[i] = -1;
fprintf(PatientRegistryOutputFile,"%ld\t%ld\t%9.6e\t%ld\t%ld\t%ld\t%ld\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%9.6e\t%9.6e\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%6.5e\t%d\t%ld\t%7.4f\t%7.4f\t%7.4f\t%lf\t%d\t",
time,i,Duration[i],NumRecipients[i],Donors_Index[i],Generation[i],Donors_Generation[i],Time_Inf[i],V[i],RandomTimeToAIDS[i],Donors_RandomTimeToAIDS[i],Donors_V[i],LogSetPoint[i],Donors_LogSetPoint[i],ViralContribToLogSP0[i],Donors_ViralContribToLogSP0[i],EnvirContribToLogSP0[i],d_acute[i],Donors_d_acute[i],time-Time_Inf[i],Donors_Total_Time_Inf_At_Trans[i],CD4[i],CD4_TimeToAIDS[i],
CD4_TimeToAIDS_exp[i][1],CD4_TimeToAIDS_exp[i][2],CD4_TimeToAIDS_exp[i][3],CD4_TimeToAIDS_exp[i][4],CD4_initial_value[i]);
fprintf(PatientRegistryOutputFile,"DiedNatural\n");
V[i] = 0.0;
} // Person died of natural causes