-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdset.c
More file actions
1579 lines (1534 loc) · 56.2 KB
/
dset.c
File metadata and controls
1579 lines (1534 loc) · 56.2 KB
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
/*
* dset.c
*
* Copyright 2019 Ryan Koehler, VerdAscend Sciences, ryan@verdascend.com
*
* The programs and source code of the vertools collection are free software.
* They are distributed in the hope that they will be useful,
* WITHOUT ANY WARRANTY OF FITNESS FOR ANY PARTICULAR PURPOSE.
*
* Permission is granted for research, educational, and possibly commercial use
* and modification as long as 1) Code and any derived works are not
* redistributed for any fee, and 2) Proper credit is given to the authors.
* If you wish to include this software in a product, or use it commercially,
* please contact the authors.
*
* See https://www.verdascend.com/ for more
*
*/
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <math.h>
# include <time.h>
#include "dset.h"
/***
* Conditional debug printing
*
* In order to use dynamic debug, the global variable char DB[] must
* be defined (as it is in prim.h). If prim.h is included (and the
* variable is initialized safely, then __PRIMH__ is defined and DB[]
* may be used.
*
* If you don't want prim.h, comment it out and define DB_DSET to
* be ON (i.e. if(1) = all printing) or OFF (i.e. if(0) = no printing)
*/
#include "prim.h"
#ifdef __PRIMH__
#define DB_DSET if(DB[108])
#else
#define DB_DSET if(1)
#endif
/*************************************************************/
/*thermoacI*/
/*************************************************************/
int thermoacI(double CMoD,double CMgD,double tempD,double CtopD,double CbotD ,int seqtop[lmax], int leff,double Gprop[4][4][4][4],double Gterm[5][5][5][5], double Hprop[4][4][4][4], double Hterm[5][5][5][5],double HinitAT,double HinitGC, double GinitAT,double GinitGC,double H[4], double Ssalt[4],double Gsalt[5], double Tm[5],double xD[5])
{
int scomp;
int initright, initleft;
double G37, Gtemp, S;
double saltlen;
double saltcorrG(double Gtemp, double CMo, double CMg, double saltlen,double tempD);
double saltcorrS(double H, double G37, double CMo, double CMg, double saltlen);
double tmcalc(double Ctop,double Cbot,double Ssalt,double H, int scomp);
double hybtemp(double H, double S, double temp);
double FractionD(double CtopD,double CbotD,double tempD ,double Gsalt);
int selfcoacI( int seqtopI[lmax], int leffI);
double inittermprop37acD(int seqtop[lmax],int initright, int initleft, double Eprop[4][4][4][4], double Eterm[5][5][5][5], double EinitAT,double EinitGC, int leff, int scomp);
DB_DSET { printf(">> thermoacI\n"); fflush(stdout); }
G37=0.0;
H[0]=0.0;
scomp=selfcoacI(seqtop,leff);
initright=leff-1;
initleft=0;
/*
printf("init # HAT%f HGC%f GAT%f GGC%f",HinitAT,HinitGC,GinitAT,GinitGC);
*/
H[0]=inittermprop37acD(seqtop, initright, initleft, Hprop, Hterm, HinitAT,HinitGC, leff, 0);
G37=inittermprop37acD(seqtop,initright, initleft,Gprop, Gterm,GinitAT,GinitGC, leff, scomp);
/*
printf("ac after inittermprop37 Gtemp %f %f ",G37, H[0]);
*/
S=((H[0]-G37)/310.15)*1000.0;
Gtemp=hybtemp(H[0], S, tempD);
/*
printf("Gtemp %f ",Gtemp);
*/
saltlen=leff-1;
Gsalt[0]=saltcorrG(Gtemp,CMoD,CMgD,saltlen,tempD);
/*
printf("Gsalt %f ",Gsalt[0]);
*/
Ssalt[0]=saltcorrS( H[0], G37, CMoD, CMgD, saltlen);
/*
printf("Ssalt %f",*Ssalt);
*/
Tm[0]=tmcalc( CtopD, CbotD, Ssalt[0], H[0],scomp);
/*
printf("Tm %f",Tm[0]);
*/
xD[0]=FractionD(CtopD,CbotD,tempD,Gsalt[0]);
/**
printf(" %10.1f %10.1f %11.2f %10.1f %f\n",*H,*Ssalt,*Gsalt,*Tm,*xD);
**/
return 0;
}
/*************************************************************/
/*thermocI*/
/*************************************************************/
int thermocI(double CMoD,double CMgD,double tempD,double CtopD,double CbotD,double Cbot2D,int seqtop[lmax],int seqbot[lmax], int leff,double Gprop[4][4][4][4], double Gterm[5][5][5][5],double Hprop[4][4][4][4], double Hterm[5][5][5][5],double HinitAT,double HinitGC, double GinitAT,double GinitGC,double Gcoax[4][4][4][4],double Hcoax[4][4][4][4], int lbotI,int *errorI,double GgapD[30],double GATclosepenD,double H[4], double Ssalt[4],double Gsalt[5], double Tm[5],double xD[5])
{
int gaposI,gaplenI;
int coaxposI,scomp=0;
int initright, initleft;
double G37, Gtemp, S,GgapcorD,GglobalD,HglobalD,SglobalD,saltlen1D,saltlen2D;
double saltlen,GcoaxcorD,HcoaxcorD;
int seqbot35[lmax];
double saltcorrG(double Gtemp, double CMoD, double CMgD, double saltlen,double tempD);
double saltcorrS(double H, double G37, double CMoD, double CMgD, double saltlen);
double tmcalc(double CtopD,double CbotD,double Ssalt,double H, int scomp);
double hybtemp(double H, double S, double temp);
int gapstack(int seqtop[lmax],int seqbot35[lmax], int *,int lbotI ,int *,int *,int *,int * );
double coaxcalc(double EcoaxD[4][4][4][4],int seqtop[lmax] , int seqbot35[lmax],int *);
double gapcalcD(int gaposI,int gaplenI,double EgapD[30],double ATclospenD,double Eprop[4][4][4][4],int seqtop[lmax], int seqbot35[lmax]);
double FractionD(double CtopD,double CbotD,double tempD ,double Gsalt);
int selfco(int seqtop[lmax], int seqbot[lmax], int leff);
int penleft(int seqtop[lmax], int seqbot[lmax], double Gprop[4][4][4][4], double Gterm[5][5][5][5],double GinitAT,double GinitGC, int leff);
int penright(int seqtop[lmax], int seqbot[lmax], double Gprop[4][4][4][4], double Gterm[5][5][5][5],double GinitAT,double GinitGC, int leff);
int saltlength(int seqtop[lmax],int seqbot[lmax],int initright, int initleft, int leff);
double inittermprop37(int seqtop[lmax], int seqbot[lmax],int initright, int initleft, double Eprop[4][4][4][4], double Eterm[5][5][5][5], double EinitAT,double EinitGC, int leff, int scomp);
void bot35(int seqbot[lmax],int seqbot35[lmax],int leff);
double GnetcalcD(double tempD,double HglobalD,double SglobalD,double CtopD,double CbotD,double Cbot2D,double Gsalt[5],double Ssalt[4],double H[4]);
double TmnetcalcD(double HglobalD,double SglobalD,double CtopD,double dCbotD,double Cbot2D,double Gsalt[5],double Ssalt[4],double H[4]);
double minD(double aD,double bD,double cD);
double dedup2GD,dedup2HD,dedup1GD,dedup1HD,transD;
DB_DSET {printf(">> thermocI\n"); fflush(stdout); }
G37=0.0;
*H=0.0;
GcoaxcorD=0.0;
HcoaxcorD=0.0;
GgapcorD=0.0;
coaxposI=0;
*errorI=0;
/**
printf("ThermocI entry");
printf("Cbot2D=%f<Br>",Cbot2D);
printf("error %d",*errorI);
fflush(stdout);
**/
bot35(seqbot,seqbot35,lbotI);
gapstack(seqtop,seqbot35,&leff,lbotI,errorI,&coaxposI,&gaposI,&gaplenI);
/**
printf("coaxposI%d",coaxposI);
printf("leffI=%d",leff);
**/
if (*errorI==0)
{
/*printf("-------------------");*/
fflush(stdout);
/*----------if coaxial stacking*/
if(coaxposI!=0)
{
/*----------Attribution of concentrations*/
/*Rules:CtopD never contains a nick*/
/* CbotD always nicked at 5' extremity*/
/* CbotD always nicked at 3'extremity*/
if (coaxposI<0)
{
transD=CbotD;
CbotD=Cbot2D;
Cbot2D=transD;
}
/*----------*/
/*----------Calculation of coaxial stacking contribution*/
GcoaxcorD=coaxcalc( Gcoax,seqtop, seqbot35,&coaxposI);
HcoaxcorD=coaxcalc( Hcoax,seqtop, seqbot35,&coaxposI);
/*----------*/
/*----------Calculation of duplex 0*/
/*Duplex 0 thermodynamics is thermodynamics of Duplex 0 binding alone */
/*printf("<Br>-------------------------------------------------duplex 0<Br>");*/
initleft=penleft(seqtop,seqbot35,Gprop,Gterm,GinitAT,GinitGC,abs(coaxposI)+1);
initright=abs(coaxposI);
/*printf("initright %d initleft %d",initright,initleft);*/
/*0.5 added to correct for extra DE*/
saltlen1D=saltlength(seqtop,seqbot35,initright,initleft,initright+1)+0.5;
/* Moved up to from below RTK */
saltlen=saltlength(seqtop,seqbot35,initright, initleft,leff);
/*--------------------Determination of extra DE contribution as a functuion of top or bottom coax*/
if (coaxposI>0)
{
dedup1GD=Gterm[seqtop[coaxposI]][seqtop[coaxposI+1]][4][seqbot35[coaxposI]];
dedup1HD=Hterm[seqtop[coaxposI]][seqtop[coaxposI+1]][4][seqbot35[coaxposI]];
}
else
{
dedup1GD=Gterm[seqtop[abs(coaxposI)]][4][seqbot35[abs(coaxposI)+1]][seqbot35[abs(coaxposI)]];
dedup1HD=Hterm[seqtop[abs(coaxposI)]][4][seqbot35[abs(coaxposI)+1]][seqbot35[abs(coaxposI)]];
}
/*printf("<Br>dedup1GD %f,dedup1HD %f <Br>",dedup1GD,dedup1HD);*/
/*fflush(stdout);*/
/*--------------------*/
/*----------Calculate gap contribution if gap*/
if ((gaposI!=0)&&(gaposI<abs(coaxposI)))
{
GgapcorD=gapcalcD(gaposI,gaplenI,GgapD,GATclosepenD,Gprop,seqtop,seqbot35);
G37=G37+GgapcorD;
saltlen=saltlen-gaplenI;
}
/*----------*/
H[0]=inittermprop37(seqtop, seqbot35,initright, initleft, Hprop, Hterm, HinitAT,HinitGC, initright+1, 0)+dedup1HD;
G37=G37+inittermprop37(seqtop, seqbot35,initright, initleft,Gprop, Gterm,GinitAT,GinitGC, initright+1, 0)+dedup1GD;
/*printf("<Br>G37=%f**",G37);*/
S=((H[0]-G37)/310.15)*1000.0;
Gtemp=hybtemp(H[0], S, tempD);
Gsalt[0]=saltcorrG( Gtemp, CMoD, CMgD, saltlen1D,tempD);
Ssalt[0]=saltcorrS( H[0], G37, CMoD, CMgD, saltlen1D);
Tm[0]=tmcalc( CtopD, CbotD, Ssalt[0], H[0],scomp);
xD[0]=FractionD(CtopD,CbotD,tempD,Gsalt[0]);
/**/
/*printf("<Br>1 H S G T X %f %f %f %f %f<Br>",H[0],Ssalt[0],Gsalt[0],Tm[0],xD[0]);*/
/**/
/*----------*/
/*----------calculation of duplex 1*/
/*Duplex 1 thermodynamics is thermodynamics of Duplex 0 binding assuming other duplex is 100% bound */
/*printf("<Br>-------------------------------------------------duplex 1<Br>");*/
/*printf("<Br>GcoaxcorD %f, HcoaxcorD %f",GcoaxcorD,HcoaxcorD);*/
/*No dangling end stabilization*/
H[1]=H[0]+HcoaxcorD-dedup1HD;
G37=G37+GcoaxcorD-dedup1GD;
S=((H[1]-G37)/310.15)*1000.0;
Gtemp=hybtemp(H[1], S, tempD);
/*No dangling end stabilization => -0.5*/
saltlen1D=saltlen1D-0.5;
Gsalt[1]=saltcorrG( Gtemp, CMoD, CMgD, saltlen1D,tempD);
Ssalt[1]=saltcorrS( H[1], G37, CMoD, CMgD, saltlen1D);
Tm[1]=tmcalc( CtopD, CbotD, Ssalt[1], H[1],scomp);
xD[1]=FractionD(CtopD,CbotD,tempD,Gsalt[1]);
/**
printf("<Br>2 H S G T X %f %f %f %f %f<Br>",H[1],Ssalt[1],Gsalt[1],Tm[1],xD[1]);
**/
/*----------*/
/*----------calculation of duplex 2*/
/*Duplex 2 thermodynamics is thermodynamics of Duplex 2 binding alone */
/*printf("<Br>-------------------------------------------------duplex 2<Br>");*/
G37=0.0;
initleft=abs(coaxposI)+1;
initright=penright(seqtop,seqbot35,Gprop,Gterm,GinitAT,GinitGC,leff);
/*leff for this duplex in saltlength is initright-initleft+1 - initleft is 0 - initright is initright-initleft*/
/*This is equivalent to placing the duplex so that is starts at position 0*/
/*0.5 added to correct for extra DE*/
saltlen2D=saltlength(seqtop,seqbot35,initright-initleft, 0,initright-initleft+1)+0.5;
/*--------------------Determination of extra DE contribution as a functuion of top or bottom coax*/
if (coaxposI>0)
{
dedup2GD=Gterm[seqtop[coaxposI]][seqtop[coaxposI+1]][seqbot35[coaxposI+1]][4];
dedup2HD=Hterm[seqtop[coaxposI]][seqtop[coaxposI+1]][seqbot35[coaxposI+1]][4];
}
else
{
dedup2GD=Gterm[4][seqtop[abs(coaxposI)+1]][seqbot35[abs(coaxposI)+1]][seqbot35[abs(coaxposI)]];
dedup2HD=Hterm[4][seqtop[abs(coaxposI)+1]][seqbot35[abs(coaxposI)+1]][seqbot35[abs(coaxposI)]];
}
/*printf("<Br>dedup2GD %f,dedup2HD %f <Br>",dedup2GD,dedup2HD);*/
/*--------------------*/
/*----------Calculate gap contribution if gap*/
/*printf("<Br>initright=%d, initleft=%d",initright,initleft);*/
if ((gaposI!=0)&&(gaposI>abs(coaxposI)))
{
GgapcorD=gapcalcD(gaposI,gaplenI,GgapD,GATclosepenD,Gprop,seqtop,seqbot35);
G37=G37+GgapcorD;
saltlen=saltlen-gaplenI;
}
/*----------*/
/*printf("<Br>initright=%d, initleft=%d",initright,initleft);*/
/*-1.001 is needed because as initleft<>0, terminal elts are added in inittermprop37*/
/*as the terminal elts are in fact perfect matches they are found in Gterm and Hterm as 1.001 filling default*/
H[2]=inittermprop37(seqtop, seqbot35,initright, initleft, Hprop, Hterm, HinitAT,HinitGC, leff, 0)-1.001+dedup2HD;
G37=G37+inittermprop37(seqtop, seqbot35,initright, initleft,Gprop, Gterm,GinitAT,GinitGC, leff, 0)-1.001+dedup2GD;
S=((H[2]-G37)/310.15)*1000.0;
Gtemp=hybtemp(H[2], S, tempD);
Gsalt[2]=saltcorrG( Gtemp, CMoD, CMgD, saltlen2D,tempD);
Ssalt[2]=saltcorrS( H[2], G37, CMoD, CMgD, saltlen2D);
Tm[2]=tmcalc( CtopD, Cbot2D, Ssalt[2], H[2],scomp);
xD[2]=FractionD(CtopD,Cbot2D,tempD,Gsalt[2]);
/**
printf("<Br>3 H S G T X %f %f %f %f %f<Br>",H[2],Ssalt[2],Gsalt[2],Tm[2],xD[2]);
**/
/*----------*/
/*----------calculation of second duplex 3*/
/*Duplex 3 thermodynamics is thermodynamics of Duplex 2 binding assuming other duplex is 100% bound */
/*printf("<Br>-------------------------------------------------duplex 3<Br>");*/
/*No dangling end stabilization*/
H[3]=H[2]+HcoaxcorD-dedup2HD;
G37=G37+GcoaxcorD-dedup2GD;
S=((H[3]-G37)/310.15)*1000.0;
Gtemp=hybtemp(H[3], S, tempD);
/*No dangling end stabilization => -0.5*/
saltlen2D=saltlen2D-0.5;
Gsalt[3]=saltcorrG( Gtemp, CMoD, CMgD, saltlen2D,tempD);
Ssalt[3]=saltcorrS( H[3], G37, CMoD, CMgD, saltlen2D);
Tm[3]=tmcalc( CtopD, Cbot2D, Ssalt[3], H[3],scomp);
xD[3]=FractionD(CtopD,Cbot2D,tempD,Gsalt[3]);
/**
printf("<Br>4 H S G T X %f %f %f %f %f<Br>",H[3],Ssalt[3],Gsalt[3],Tm[3],xD[3]);
**/
/*----------*/
/*----------calculation of global structure*/
/*printf("<Br>-------------------------------------------------triplex <Br>");*/
GglobalD=Gsalt[1]+Gsalt[2]-dedup2GD;
HglobalD=H[1]+H[2]-dedup2HD;
SglobalD=((HglobalD-GglobalD)/(tempD+273.15))*1000.0;
/**
printf("Hglobal %f Sglobal %f Gglobal %f",HglobalD,SglobalD,GglobalD);
**/
/*-----------*/
/*-----------calculation of net free energy of global structure*/
xD[4]=GnetcalcD(tempD,HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Gsalt,Ssalt,H);
/**
printf("X[4] %f",xD[4]);
printf("fraction: %f",FractionD(CtopD,CbotD,tempD,Gsalt[4]));
w=0;
printf("fraction: %f",FractionD(CtopD,CbotD,tempD,w));
**/
/*-----------*/
/*-----------calculation of Tm effective of global structure*/
Tm[4]=TmnetcalcD(HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Gsalt,Ssalt,H);
/**
printf("<Br>Tm[4] %f <Br>",Tm[4]);
**/
/*-----------*/
}
/*----------if no coaxial stacking*/
else if (coaxposI==0)
{
DB_DSET {printf("+ no-coax case\n"); fflush(stdout); }
Gsalt[1]=698282.0;
scomp=selfco( seqtop, seqbot35,leff);
initleft=penleft(seqtop,seqbot35,Gprop,Gterm,GinitAT,GinitGC, leff);
initright=penright(seqtop,seqbot35,Gprop,Gterm,GinitAT,GinitGC,leff);
/* Moved up to from below RTK */
saltlen=saltlength(seqtop,seqbot35,initright, initleft,leff);
/**
printf("main after pen %d %d", initleft,initright);
fflush(stdout);
**/
if (initright<=initleft)
{
/*----------uses double mismatch CCCC values for calculation of H and G if no consecutive pairing*/
*H=leff*Hprop[1][1][1][1];
G37=leff*Gprop[1][1][1][1];
/*----------*/
}
else
{
/*
printf("saltlen %f ",saltlen);
*/
*H=inittermprop37(seqtop, seqbot35,initright, initleft, Hprop, Hterm, HinitAT,HinitGC, leff, 0);
G37=inittermprop37(seqtop, seqbot35,initright, initleft,Gprop, Gterm,GinitAT,GinitGC, leff, scomp);
/**
printf("main after inittermprop37 Gtemp %f %f ",G37, *H);
fflush(stdout);
**/
/*----------Calculate gap contribution if gap*/
if (gaposI!=0)
{
GgapcorD=gapcalcD(gaposI,gaplenI,GgapD,GATclosepenD,Gprop,seqtop,seqbot35);
G37=G37+GgapcorD;
saltlen=saltlen-gaplenI;
}
DB_DSET {printf("+ gap calculated\n"); fflush(stdout); }
/*----------*/
}
S=((H[0]-G37)/310.15)*1000.0;
Gtemp=hybtemp(H[0], S, tempD);
/* Wrong place? Moved up to top RTK
saltlen=saltlength(seqtop,seqbot35,initright, initleft,leff);
*/
/*
printf("Gtemp %f ",Gtemp);
*/
Gsalt[0]=saltcorrG( Gtemp, CMoD, CMgD, saltlen,tempD);
/*
printf("Gsalt %f ",*Gsalt);
*/
Ssalt[0]=saltcorrS( H[0], G37, CMoD, CMgD, saltlen);
/*
printf("Ssalt %f",Ssalt[1]);
*/
*Tm=tmcalc( CtopD, CbotD, *Ssalt, H[0],scomp);
if(*Tm<MIN_TM)
{
*Tm = MIN_TM;
}
/*
printf("Tm %f",*Tm);
*/
xD[0]=FractionD(CtopD,CbotD,tempD,Gsalt[0]);
}
}
DB_DSET {printf("<< thermocI 0\n"); fflush(stdout); }
return 1;
}
/*************************************************************/
/*Calculates Equilibrium concentrations in case of coaxial stacking, GnetcalcD and fraction triplex*/
/*************************************************************/
/* he following equilibria are considered:*/
/* +B=AB A+C=AC A+B+C=ABC */
/*instant concentrations of A, B, and C are CAD,CBD,and CCD*/
/*initial concentrations of A, B, and C are CtopD, CbotD, and Cbot2D)*/
/*Ks for the above equilibria are respectively KABD, KACD, and KABCD*/
/*H[0], Ssalt[0] correspond to KABD*/
/*H[2], Ssalt[2] correspond to KACD*/
/*HglobalD, SglobalD correspond to KABCD*/
double GnetcalcD(double tempD,double HglobalD,double SglobalD,double CtopD,double CbotD,double Cbot2D,double Gsalt[5],double Ssalt[4],double H[4])
{
const double R=1.98722;
/* TK 12/29/12
double ABD, ACD;
*/
int i;
double minD(double aD,double bD,double cD);
double KABD,KACD,KABCD,CAD,CBD,CCD,ABCD,CAprevD,CBprevD,CCprevD,KnetD,xnetD;
i=0;
/*printf("<Br>Ssalt[0] %f H[0] %f tempD %f R %f",Ssalt[0],H[0],tempD,R);*/
/*----------Calculates Ks at the given temp*/
KABD=exp(-(1000*H[0]-(tempD+273.15)*Ssalt[0])/(R*(tempD+273.15)));
/*printf("KABD %f",KABD);*/
/*printf("<Br>Ssalt[2] %f H[2] %f tempD %f R %f",Ssalt[2],H[2],tempD,R);*/
KACD=exp(-(1000*H[2]-(tempD+273.15)*Ssalt[2])/(R*(tempD+273.15)));
KABCD=exp(-(1000*HglobalD-(tempD+273.15)*SglobalD)/(R*(tempD+273.15)));
/*printf("<Br>//////////////////////////<Br>");*/
/*printf("<Br> K %g %g %g",KABD,KACD,KABCD);*/
/*printf("<Br>C %f %f %f",CtopD,CbotD,Cbot2D);*/
/*----------*/
/*----------initialize SS concentrations*/
CAD=CtopD;
CBD=CbotD;
CCD=Cbot2D;
/*printf("tempD %f ",tempD);*/
/*----------*/
/*----------iterates SS concentrations until convergence is reached*/
do
{
i=i+1;
CAprevD=CAD;
CBprevD=CBD;
CCprevD=CCD;
CAD=CtopD/(1.0+KABD*CBD+KACD*CCD+KABCD*CBD*CCD);
CBD=CbotD/(1.0+KABD*CAD+KABCD*CAD*CCD);
CCD=Cbot2D/(1.0+KACD*CAD+KABCD*CAD*CBD);
/**
printf("///////%g",fabs(CAprevD-CAD));
**/
}
while ((fabs(CAprevD-CAD)>convergeD) ||(fabs(CBprevD-CBD)>convergeD) ||(fabs(CCprevD-CCD)>convergeD));
/*----------*/
/*----------calculates equilibrium concentration of duplexes and triplex*/
ABCD=KABCD*CAD*CBD*CCD;
/* TK 12/29/12
ABD=KABD*CAD*CBD;
ACD=KACD*CAD*CCD;
*/
/*printf("<Br>ABCD ABD ACD %g %g %g" ,ABCD,ABD,ACD);*/
/*printf("<Br> CAD CBD CCD %g %g %g" ,CAD,CBD,CCD);*/
/*printf("cons %g %g %g",ABD+ACD+ABCD+CAD,ABD+ABCD+CBD,ACD+ABCD+CCD);*/
/*----------*/
/*----------Calculates Knet and Gnet*/
KnetD=ABCD/((CtopD-ABCD)*(CbotD-ABCD)*(Cbot2D-ABCD));
/*printf("Knet %g",KnetD);*/
Gsalt[4]=(-R*(tempD+273.15)*log(KnetD))/1000.0;
/*printf("Gnet %g ",Gsalt[4]);*/
/*---------*/
/*----------calculates fraction triplex*/
/*printf("min %f",minD(CtopD,CbotD,Cbot2D));*/
xnetD=ABCD/minD(CtopD,CbotD,Cbot2D)*100.0;
/*printf("<Br>i %d xnet %f",i,xnetD);*/
/*printf("<Br>//////////////////////////<Br>");*/
/*----------*/
return xnetD;
}
/*************************************************************/
/*Takes minimum of 3 doubles*/
/*************************************************************/
double minD(double aD,double bD,double cD)
{
double miniD;
if (aD>bD)
{
miniD=bD;
}
else
{
miniD=aD;
}
if (miniD>cD)
{
miniD=cD;
}
return miniD;
}
/*************************************************************/
/*Calculates the TMnet in case of coaxial stacking*/
/*************************************************************/
double TmnetcalcD(double HglobalD,double SglobalD,double CtopD,double CbotD,double Cbot2D,double Gsalt[5],double Ssalt[4],double H[4])
{
double tlowD,thighD,tmidD,flowD,fhighD,fmidD,TmnetD;
tlowD=0.0;
thighD=100.0;
/**
printf("<Br>*-*-*-*-*-*- %f %f %f %f %f %f %f %f<Br>",HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Ssalt[2],Ssalt[0],H[0]);
**/
flowD=GnetcalcD(tlowD,HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Gsalt,Ssalt,H);
fhighD=GnetcalcD(thighD,HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Gsalt,Ssalt,H);
/*printf("<Br>-------<Br>flow %f fhigh %f",flowD,fhighD);*/
if ((fhighD<50.0) && (flowD>50.0))
{
do
{
tmidD=(tlowD+thighD)/2;
fmidD=GnetcalcD(tmidD,HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Gsalt,Ssalt,H);
if (fmidD>50.0)
{
tlowD=tmidD;
/*fhighD=GnetcalcD(thighD,HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Gsalt,Ssalt,H);*/
}
else
{
thighD=tmidD;
/*flowD=GnetcalcD(tlowD,HglobalD,SglobalD,CtopD,CbotD,Cbot2D,Gsalt,Ssalt,H);*/
}
/*printf("<Br>t values %f %f %f",tlowD, thighD,tmidD);*/
}
while (fabs(tlowD-thighD)>0.01);
TmnetD=tlowD;
}
else
{
TmnetD=698282.0;
}
return TmnetD;
}
/*************************************************************/
/*thermocpI*/
/*************************************************************/
int thermocpI(double CMoD,double CMgD,double tempD,double CtopD,double CbotD,int seqtop[lmax],int seqbot[lmax], int leff,double Gprop[4][4][4][4], double Gterm[5][5][5][5],double Hprop[4][4][4][4], double Hterm[5][5][5][5],double HinitAT,double HinitGC, double GinitAT,double GinitGC, int *errorI,double H[4], double Ssalt[4],double Gsalt[5], double Tm[5],double xD[5])
{
int scomp=0;
int initright, initleft;
double G37, Gtemp, S;
double saltlen;
int seqbot35[lmax];
double saltcorrG(double Gtemp, double CMoD, double CMgD, double saltlen,double tempD);
double saltcorrS(double H, double G37, double CMoD, double CMgD, double saltlen);
double tmcalc(double CtopD,double CbotD,double Ssalt,double H, int scomp);
double hybtemp(double H, double S, double temp);
double FractionD(double CtopD,double CbotD,double tempD ,double Gsalt);
int selfco(int seqtop[lmax], int seqbot[lmax], int leff);
double inittermprop37(int seqtop[lmax], int seqbot[lmax],int initright, int initleft, double Eprop[4][4][4][4], double Eterm[5][5][5][5], double EinitAT,double EinitGC, int leff, int scomp);
void bot35(int seqbot[lmax],int seqbot35[lmax],int leff);
G37=0.0;
H[1]=0.0;
/**
printf("leff %d",leff);
**/
bot35(seqbot,seqbot35,leff);
initleft=1;
initright=leff-2;
/**
printf("main after pen %d %d", initleft,initright);
**/
if (initright<=initleft)
{
H[0]=0.0;
Ssalt[0]=0.0;
Gsalt[0]=0.0;
Tm[0]=0.0;
xD[0]=0.0;
}
else
{
saltlen=leff-2;
/**
printf("saltlen %f ",saltlen);
**/
H[0]=inittermprop37(seqtop, seqbot35,initright, initleft, Hprop, Hterm, HinitAT,HinitGC, leff, 0);
G37=inittermprop37(seqtop, seqbot35,initright, initleft,Gprop, Gterm,GinitAT,GinitGC, leff, scomp);
/**
printf("main after inittermprop37 Gtemp %f %f ",G37, H);
**/
S=((H[0]-G37)/310.15)*1000.0;
Gtemp=hybtemp(H[0], S, tempD);
/**
printf("Gtemp %f ",Gtemp);
**/
Gsalt[0]=saltcorrG( Gtemp, CMoD, CMgD, saltlen,tempD);
/**
printf("Gsalt %f ",Gsalt[0]);
**/
Ssalt[0]=saltcorrS( H[0], G37, CMoD, CMgD, saltlen);
/**
printf("Ssalt %f",Ssalt[0]);
**/
Tm[0]=tmcalc( CtopD, CbotD, Ssalt[0], H[0],scomp);
/**
printf("Tm %f",Tm[0]);
**/
xD[0]=FractionD(CtopD,CbotD,tempD,Gsalt[0]);
/**
printf("xD %f",xD[0]);
**/
}
/**
printf( "<font color=000066>");
printf(" %10.1f %10.1f %11.2f %10.1f %f\n",*H,*Ssalt,*Gsalt,*Tm,*xD);
printf("</font><Br>");
**/
return 0;
}
/*************************************************************/
/*Takes care of gaps and coaxial stacking*/
/*************************************************************/
int gapstack(int seqtop[lmax],int seqbot35[lmax], int *leffI,int lbotI ,int *errorI,int *coaxposI,int *gaposI, int *gaplenI)
{
int i,k,safareaI=0;
int ncoaxI;
*gaposI=0;
*gaplenI=0;
k=0;
ncoaxI=0;
*coaxposI=0;
/**
printf("<Br>gapstack entry\n<Br>");
printf("errorI %d",*errorI);
fflush(stdout);
printf("<Br>\nleffI %d, lbotI %d", *leffI,lbotI);
**/
/*----------if more than one stacking: error*/
for (i=0;i<=lbotI-1; i++)
{
if (seqbot35[i]==6)
{
ncoaxI=ncoaxI+1;
}
}
for (i=0;i<=*leffI-1; i++)
{
if (seqtop[i]==6)
{
ncoaxI=ncoaxI+1;
}
}
if (ncoaxI>1)
{
*errorI=1;
/**
printf(" ncoax %d",ncoaxI);
fflush(stdout);
**/
}
else
{
/*----------Finds stacking in top strand and excise stacking symbol 6 and return -coaxposI*/
for (i=0;i<=*leffI-1; i++)
{
if (seqtop[i]==6)
{
ncoaxI=1;
*coaxposI=-(i-1);
for (k=i;k<=*leffI;k++)
{
seqtop[k]=seqtop[k+1];
}
*leffI=*leffI-1;
}
}
/**
printf("<Br>coaxposI top %d",*coaxposI);
printf("errorI %d",*errorI);
fflush(stdout);
**/
/*----------*/
/*----------Finds stacking in bottom strand and excise stacking symbol 6 and return +coaxposI*/
/**
printf("<Br>");
for(i=0;i<=*leffI-1;i++)
{
printf(" %d ",seqtop[i]);
}
printf("<Br>");
for(i=0;i<=lbotI-1;i++)
{
printf(" %d ",seqbot35[i]);
}
printf("<Br>");
**/
for (i=0;i<=lbotI-1; i++)
{
if (seqbot35[i]==6)
{
*coaxposI=i-1;
for (k=i;k<=lbotI;k++)
{
seqbot35[k]=seqbot35[k+1];
}
lbotI=lbotI-1;
}
}
/**
for(i=0;i<=*leffI-1;i++)
{
printf(" %d ",seqtop[i]);
}
printf("<Br>");
for(i=0;i<=lbotI-1;i++)
{
printf(" %d ",seqbot35[i]);
}
**/
/**
printf("<Br>coaxposI bot %d",*coaxposI);
printf("errorI %d",*errorI);
fflush(stdout);
**/
/*----------*/
}
/*----------check that there is no mismatch at the stacking interface - errorI=3*/
/*printf("coaxpos %d ncoax %d",*coaxposI,ncoaxI);*/
fflush(stdout);
if (ncoaxI!=0)
{
if ((abs(*coaxposI)<3)||(abs(*coaxposI)>(*leffI-4)))
{
*errorI=2;
}
if ((seqbot35[abs(*coaxposI)]+seqtop[abs(*coaxposI)])!=3)
{
*errorI=3;
printf("------%d %d",seqbot35[abs(*coaxposI)],seqtop[abs(*coaxposI)]);
}
if ((seqbot35[abs(*coaxposI)+1]+seqtop[abs(*coaxposI)+1])!=3)
{
*errorI=3;
printf("------%d %d",seqbot35[abs(*coaxposI)],seqtop[abs(*coaxposI)]);
}
}
/**
printf("*errorI_1 %d",*errorI);
fflush(stdout);
**/
/*----------check that the two strands have similar length - errorI=4*/
if ((*leffI!=lbotI)&&(*errorI==0))
{
*errorI=4;
}
/*printf("<Br>\nleffI %d, lbotI %d", *leffI,lbotI);*/
/**
printf("*errorI_4 %d",*errorI);
fflush(stdout);
**/
/*----------Finds gaps in top strand*/
/*Only allows one gap; gaps in top and bottom strand: errorI=5; more than one gap in top strand: errorI=6*/
if (*errorI==0)
{
for (i=0;i<=*leffI-1; i++)
{
if (seqtop[i]==7)
{
if (*gaposI==0)
{
for (k=0;k<=*leffI-1; k++)
{
if (seqbot35[k]==7)
{
*errorI=5;
}
else
{
*gaposI=i-1;
*gaplenI=1;
}
}
}
else
{
/**
printf("i %d",i);
**/
if (i==(*gaposI+*gaplenI+1))
{
*gaplenI=*gaplenI+1;
}
else
{
*errorI=6;
}
}
}
}
}
/**
printf("*errorI_5_6 %d",*errorI);
fflush(stdout);
**/
/*Finds gaps in bottom strand*/
/*----------Only allows one gap; more than one gap in bottom strand: errorI=7*/
if ((*gaposI==0)&&(*errorI==0))
{
for (i=0;i<=*leffI-1; i++)
{
/*printf("b%db",seqbot35[i]);*/
if (seqbot35[i]==7)
{
if (*gaposI==0)
{
*gaposI=i-1;
*gaplenI=1;
/*printf("jkhgfksjh",*gaposI);*/
}
else
{
if (i==(*gaposI+*gaplenI+1))
{
*gaplenI=*gaplenI+1;
}
else
{
*errorI=7;
}
}
}
}
}
/**
printf("*errorI_7 %d",*errorI);
fflush(stdout);
**/
/*printf("gaposI %d gaplenI %d",*gaposI,*gaplenI);*/
/*----------Determine safety area size as a function of gap length*/
if (*errorI==0)
{
if (*gaplenI==1)
{
safareaI=4;
}
else if ((*gaplenI>1)&&(*gaplenI<=10))
{
safareaI=5;
}
else if (*gaplenI>10)
{
safareaI=6;
}
}
/*----------Check no mismatch or duplex extremity within safareaI bp of gap; if any: errorI=8*/
if ((*errorI==0)&&(*gaplenI!=0))
{
if ((*gaposI<safareaI-1)||((*gaposI+*gaplenI)>(*leffI-safareaI-1)))
{
*errorI=8;
/**
printf("test0");
**/
}
if (*errorI==0)
{
for (i=*gaposI+*gaplenI+1;i<=*gaposI+*gaplenI+safareaI;i++)
{
if ((seqbot35[i]+seqtop[i])!=3)
{
/*
printf("test1");
*/
*errorI=8;
break;
}
}
}
if (*errorI==0)
{
for (i=*gaposI;i>=*gaposI-safareaI+1;i--)
{
if ((seqbot35[i]+seqtop[i])!=3)
{
/*
printf("test2");
*/
*errorI=8;
break;
}
}
}
}
/**
printf("*errorI_8 %d",*errorI);
fflush(stdout);
**/
/*----------Check no stacking within safareaI bp of gap;if any: errorI=9*/
if ((*errorI==0)&&(ncoaxI!=0)&&(*gaplenI!=0))
{
if ((abs(*coaxposI)>=*gaposI-safareaI+1)&&(abs(*coaxposI)<=*gaposI+*gaplenI+safareaI))
{
*errorI=9;
}
}
/*
printf("<Br>xxx ");
*/
/**
for(i=0;i<=9;i++)
{
printf(" %d ",seqtop[i]);
}
printf("<Br>");
for(i=0;i<=9;i++)
{
printf(" %d ",seqbot35[i]);
}
printf("<Br>");
**/
/**
printf("*errorI_9 %d",*errorI);
fflush(stdout);
**/
/*----------generate new top and bottom strand*/
if (*errorI==0)
{
for (i=*gaposI+1;i<=*leffI;i++)
{
seqtop[i]=seqtop[i+*gaplenI];
seqbot35[i]=seqbot35[i+*gaplenI];
/*leffI=leffI-1;*/
}
*leffI=*leffI-*gaplenI;
}
/**
for(i=0;i<=*leffI-1;i++)
{
printf(" %d ",seqtop[i]);
}
printf("<Br>");
for(i=0;i<=*leffI-1;i++)
{
printf(" %d ",seqbot35[i]);
}
**/
/*----------decrement coaxial stacking position if gap before stacking interface*/
/*and if there is a stacking*/
if ((*gaposI<abs(*coaxposI))&&(ncoaxI!=0))
{
*coaxposI=*coaxposI/abs(*coaxposI)*(abs(*coaxposI)-*gaplenI);
}
/*----------*/
/**
printf("<Br>coaxposI %d",*coaxposI);
printf("<Br>gaposI: %d gaplenI: %d", *gaposI,*gaplenI);
printf("<Br>gapstack exit\n<Br>");
fflush(stdout);
**/
return 0;
}
/*************************************************************/
/*Calculates gap contribution*/
/*************************************************************/
double gapcalcD(int gaposI,int gaplenI,double GgapD[30],double GATclosepenD,double Eprop[4][4][4][4],int seqtop[lmax], int seqbot35[lmax])
{
double EgapcorrD;
EgapcorrD=0.0;
/*----------if bulge of one add bulge increment*/
if (gaplenI==1)
{
EgapcorrD=GgapD[0];
}
/*----------*/
/*----------Limit gap length correction to 30 nts*/
if (gaplenI>30)