2 ###################################
3 # convert energy parameter files #
4 # from ViennaRNAPackage 1.8.4 to #
8 ###################################
18 #include "fold_vars.h"
19 #include "read_epars.h"
22 #include "1.8.4_epars.h"
23 #include "1.8.4_intloops.h"
25 #include "convert_epars.h"
27 enum parset_184 {UNKNOWN_184= -1, QUIT_184, S_184, SH_184, HP_184, B_184, IL_184, MMI_184, MMH_184, MMM_184, MM_H_184,
28 DE5_184, DE3_184, DE5_H_184, DE3_H_184, ML_184, TL_184, TRI_184, TE_184, NIN_184, MISC_184,
29 INT11_184, INT11_H_184, INT21_184, INT21_H_184, INT22_184, INT22_H_184};
32 PRIVATE unsigned int read_old_parameter_file(FILE *ifile, int skip_header);
33 PRIVATE void write_new_parameter_file(FILE *ofile, unsigned int options);
34 PRIVATE void rd_stacks(int stack[NBPAIRS+1][NBPAIRS+1], FILE *fp);
35 PRIVATE void rd_loop(int looparray[31], FILE *fp);
36 PRIVATE void rd_mismatch(int mismatch[NBPAIRS+1][5][5], FILE *fp);
37 PRIVATE void rd_int11(int int11[NBPAIRS+1][NBPAIRS+1][5][5], FILE *fp);
38 PRIVATE void rd_int21(int int21[NBPAIRS+1][NBPAIRS+1][5][5][5], FILE *fp);
39 PRIVATE void rd_int22(int int22[NBPAIRS+1][NBPAIRS+1][5][5][5][5], FILE *fp);
40 PRIVATE void rd_dangle(int dangles[NBPAIRS+1][5], FILE *fp);
41 PRIVATE void rd_MLparams(FILE *fp);
42 PRIVATE void rd_misc(FILE *fp);
43 PRIVATE void rd_ninio(FILE *fp);
44 PRIVATE void rd_Tetra_loop(FILE *fp);
45 PRIVATE void rd_Tri_loop(FILE *fp);
46 PRIVATE void check_symmetry(void);
47 PRIVATE enum parset_184 gettype_184(char ident[]);
48 PRIVATE char *get_array1(int *arr, int size, FILE *fp);
49 PRIVATE void ignore_comment(char *line);
50 PRIVATE void display_array(int *p, int size, int line, FILE *fp);
53 PUBLIC void convert_parameter_file(const char *iname, const char *oname, unsigned int options){
55 unsigned int old_options = 0;
56 int skip_input_header = 0;
58 if(options & VRNA_CONVERT_OUTPUT_DUMP){
59 if(oname == NULL) oname = iname;
60 skip_input_header = 1;
65 skip_input_header = 1;
67 else if(!(ifile=fopen(iname,"r"))){
68 fprintf(stderr, "convert_epars: can't open file %s\n", iname);
71 /* read old (1.8.4 format) parameter file */
72 old_options = read_old_parameter_file(ifile, skip_input_header);
73 if(ifile != stdin) fclose(ifile);
77 if(options & VRNA_CONVERT_OUTPUT_VANILLA)
78 options = old_options;
80 if(oname == NULL) ofile = stdout;
81 else if(!(ofile=fopen(oname,"a+"))){
82 fprintf(stderr, "convert_epars: can't open file %s for writing\n", oname);
85 write_new_parameter_file(ofile, options);
86 if(ofile != stdout) fclose(ofile);
90 /*------------------------------------------------------------*/
91 PRIVATE unsigned int read_old_parameter_file(FILE *ifile, int skip_header){
92 char *line, ident[32];
95 unsigned int read_successfully = 0;
97 if (!(line = get_line(ifile))) {
98 warn_user("convert_epars: can't read input parameter file");
102 if (strncmp(line,"## RNAfold parameter file",25)!=0){
103 warn_user("convert_epars: Missing header line in input parameter file.\n"
104 "May be this file has incorrect format?");
109 line = get_line(ifile);
113 r = sscanf(line, "# %31s", ident);
115 type = gettype_184(ident);
117 case QUIT_184: if(ifile == stdin){
118 fprintf(stderr, "press ENTER to continue...\n");
123 case SH_184: rd_stacks(enthalpies_184, ifile);
124 read_successfully |= VRNA_CONVERT_OUTPUT_STACK;
126 case S_184: rd_stacks(stack37_184, ifile);
127 read_successfully |= VRNA_CONVERT_OUTPUT_STACK;
129 case HP_184: rd_loop(hairpin37_184, ifile);
130 read_successfully |= VRNA_CONVERT_OUTPUT_HP;
132 case B_184: rd_loop(bulge37_184, ifile);
133 read_successfully |= VRNA_CONVERT_OUTPUT_BULGE;
135 case IL_184: rd_loop(internal_loop37_184, ifile);
136 read_successfully |= VRNA_CONVERT_OUTPUT_INT;
138 case MMH_184: rd_mismatch(mismatchH37_184, ifile);
139 read_successfully |= VRNA_CONVERT_OUTPUT_MM_HP;
141 case MMI_184: rd_mismatch(mismatchI37_184, ifile);
142 read_successfully |= VRNA_CONVERT_OUTPUT_MM_INT
143 |VRNA_CONVERT_OUTPUT_MM_INT_1N /* since 1:n-interior loop mismatches are treated seperately in 2.0 */
144 |VRNA_CONVERT_OUTPUT_MM_INT_23; /* since 2:3-interior loop mismatches are treated seperately in 2.0 */
146 case MMM_184: rd_mismatch(mismatchM37_184, ifile);
147 read_successfully |= VRNA_CONVERT_OUTPUT_MM_MULTI;
149 case MM_H_184: rd_mismatch(mism_H_184, ifile);
150 read_successfully |= VRNA_CONVERT_OUTPUT_MM_HP /* since hairpin mismatches are treated seperately in 2.0 */
151 |VRNA_CONVERT_OUTPUT_MM_INT /* since interior loop mismatches are treated seperately in 2.0 */
152 |VRNA_CONVERT_OUTPUT_MM_INT_1N /* since 1:n-interior loop mismatches are treated seperately in 2.0 */
153 |VRNA_CONVERT_OUTPUT_MM_INT_23 /* since 2:3-interior loop mismatches are treated seperately in 2.0 */
154 |VRNA_CONVERT_OUTPUT_MM_MULTI; /* since multi loop mismatches are treated seperately in 2.0 */
156 case INT11_184: rd_int11(int11_37_184, ifile);
157 read_successfully |= VRNA_CONVERT_OUTPUT_INT_11;
159 case INT11_H_184: rd_int11(int11_H_184, ifile);
160 read_successfully |= VRNA_CONVERT_OUTPUT_INT_11;
162 case INT21_184: rd_int21(int21_37_184, ifile);
163 read_successfully |= VRNA_CONVERT_OUTPUT_INT_21;
165 case INT21_H_184: rd_int21(int21_H_184, ifile);
166 read_successfully |= VRNA_CONVERT_OUTPUT_INT_21;
168 case INT22_184: rd_int22(int22_37_184, ifile);
169 read_successfully |= VRNA_CONVERT_OUTPUT_INT_22;
171 case INT22_H_184: rd_int22(int22_H_184, ifile);
172 read_successfully |= VRNA_CONVERT_OUTPUT_INT_22;
174 case DE5_184: rd_dangle(dangle5_37_184, ifile);
175 read_successfully |= VRNA_CONVERT_OUTPUT_DANGLE5
176 |VRNA_CONVERT_OUTPUT_MM_MULTI /* since multi loop mismatches were treated as dangle contribution */
177 |VRNA_CONVERT_OUTPUT_MM_EXT; /* since exterior loop mismatches were treated as dangle contribution */
179 case DE5_H_184: rd_dangle(dangle5_H_184, ifile);
180 read_successfully |= VRNA_CONVERT_OUTPUT_DANGLE5
181 |VRNA_CONVERT_OUTPUT_MM_MULTI /* since multi loop mismatches were treated as dangle contribution */
182 |VRNA_CONVERT_OUTPUT_MM_EXT; /* since exterior loop mismatches were treated as dangle contribution */
184 case DE3_184: rd_dangle(dangle3_37_184, ifile);
185 read_successfully |= VRNA_CONVERT_OUTPUT_DANGLE3
186 |VRNA_CONVERT_OUTPUT_MM_MULTI /* since multi loop mismatches were treated as dangle contribution */
187 |VRNA_CONVERT_OUTPUT_MM_EXT; /* since exterior loop mismatches were treated as dangle contribution */
189 case DE3_H_184: rd_dangle(dangle3_H_184, ifile);
190 read_successfully |= VRNA_CONVERT_OUTPUT_DANGLE3
191 |VRNA_CONVERT_OUTPUT_MM_MULTI /* since multi loop mismatches were treated as dangle contribution */
192 |VRNA_CONVERT_OUTPUT_MM_EXT; /* since exterior loop mismatches were treated as dangle contribution */
194 case ML_184: rd_MLparams(ifile);
195 read_successfully |= VRNA_CONVERT_OUTPUT_ML
196 |VRNA_CONVERT_OUTPUT_MISC; /* since TerminalAU went to "misc" section */
198 case NIN_184: rd_ninio(ifile);
199 read_successfully |= VRNA_CONVERT_OUTPUT_NINIO;
201 case TL_184: rd_Tetra_loop(ifile);
202 read_successfully |= VRNA_CONVERT_OUTPUT_SPECIAL_HP;
204 case TRI_184: rd_Tri_loop(ifile);
205 read_successfully |= VRNA_CONVERT_OUTPUT_SPECIAL_HP;
207 case MISC_184: rd_misc(ifile);
208 read_successfully |= VRNA_CONVERT_OUTPUT_MISC;
210 default: /* do nothing but complain */
211 fprintf(stderr,"convert_parameter_file: Unknown field identifier in `%s'\n", line);
213 } /* else ignore line */
215 } while((line=get_line(ifile)) && !last);
216 return read_successfully;
219 PRIVATE void display_array(int *p, int size, int nl, FILE *fp){
221 for (i=1; i<=size; i++, p++) {
223 case INF: fprintf(fp," INF"); break;
224 case -INF: fprintf(fp," -INf"); break;
225 case DEF: fprintf(fp," DEF"); break;
226 default: fprintf(fp,"%6d", *p); break;
228 if ((i%nl)==0) fprintf(fp,"\n");
230 if (size%nl) fprintf(fp,"\n");
234 PRIVATE char *get_array1(int *arr, int size, FILE *fp){
235 int i, p, pos, pp, r, last;
240 if (!line) nrerror("convert_epars: unexpected end of file in get_array1");
241 ignore_comment(line);
243 while ((i<size)&&(sscanf(line+pos,"%15s%n", buf, &pp)==1)) {
245 if (buf[0]=='*') {i++; continue;}
246 else if (buf[0]=='x') { /* should only be used for loop parameters */
247 if (i==0) nrerror("convert_epars: can't extrapolate first value");
248 p = arr[last] + (int) (0.5+ lxc37_184*log(((double) i)/(double)(last)));
250 else if (strcmp(buf,"DEF") == 0) p = DEF;
251 else if (strcmp(buf,"INF") == 0) p = INF;
252 else if (strcmp(buf,"NST") == 0) p = NST;
254 r=sscanf(buf,"%d", &p);
257 fprintf(stderr, "convert_epars: can't interpret `%s' in get_array1\n", buf);
269 /*------------------------------------------------------------*/
271 PRIVATE void rd_stacks(int stacks[NBPAIRS+1][NBPAIRS+1], FILE *fp)
275 for (i=1; i<=NBPAIRS; i++) {
276 cp = get_array1(stacks[i]+1,NBPAIRS, fp);
278 fprintf(stderr,"convert_epars: \nrd_stacks: %s\n", cp);
284 /*------------------------------------------------------------*/
286 PRIVATE void rd_loop(int loop[31], FILE *fp)
290 cp = get_array1(loop, 31, fp);
293 fprintf(stderr,"convert_epars: \nrd_loop: %s\n", cp);
298 /*------------------------------------------------------------*/
300 PRIVATE void rd_mismatch(int mismatch[NBPAIRS+1][5][5], FILE *fp)
305 for (i=1; i<NBPAIRS+1; i++) {
306 cp = get_array1(mismatch[i][0],5*5, fp);
308 fprintf(stderr, "convert_epars: rd_mismatch: in field mismatch[%d]\n\t%s\n", i, cp);
315 /*------------------------------------------------------------*/
316 PRIVATE void rd_int11(int int11[NBPAIRS+1][NBPAIRS+1][5][5], FILE *fp)
321 for (i=1; i<NBPAIRS+1; i++) {
322 for (j=1; j<NBPAIRS+1; j++) {
323 cp = get_array1(int11[i][j][0],5*5, fp);
325 fprintf(stderr, "convert_epars: rd_int11: in field int11[%d][%d]\n\t%s\n", i, j, cp);
333 /*------------------------------------------------------------*/
334 PRIVATE void rd_int21(int int21[NBPAIRS+1][NBPAIRS+1][5][5][5], FILE *fp)
339 for (i=1; i<NBPAIRS+1; i++) {
340 for (j=1; j<NBPAIRS+1; j++) {
341 for (k=0; k<5; k++) {
342 cp = get_array1(int21[i][j][k][0],5*5, fp);
344 fprintf(stderr, "convert_epars: rd_int21: in field int21[%d][%d][%d]\n\t%s\n",
354 /*------------------------------------------------------------*/
355 PRIVATE void rd_int22(int int22[NBPAIRS+1][NBPAIRS+1][5][5][5][5], FILE *fp)
360 for (i=1; i<NBPAIRS+1; i++)
361 for (j=1; j<NBPAIRS+1; j++)
364 for (m=1; m<5; m++) {
365 cp = get_array1(int22[i][j][k][l][m]+1,4, fp);
367 fprintf(stderr, "convert_epars: rd_int22: in field "
368 "int22[%d][%d][%d][%d][%d]\n\t%s\n",
377 /*------------------------------------------------------------*/
378 PRIVATE void rd_dangle(int dangle[NBPAIRS+1][5], FILE *fp)
383 for (i=0; i< NBPAIRS+1; i++) {
384 cp = get_array1(dangle[i],5, fp);
386 fprintf(stderr,"convert_epars: \nrd_dangle: %s\n", cp);
393 /*------------------------------------------------------------*/
394 PRIVATE void rd_MLparams(FILE *fp)
399 cp = get_array1(values,4, fp);
401 fprintf(stderr,"convert_epars: rd_MLparams: %s\n", cp);
405 ML_BASE37_184 = values[0];
406 ML_closing37_184 = values[1];
407 ML_intern37_184 = values[2];
408 TerminalAU_184 = values[3];
413 /*------------------------------------------------------------*/
415 PRIVATE void rd_misc(FILE *fp)
418 int values[1]; /* so far just one */
420 cp = get_array1(values,1, fp);
422 fprintf(stderr,"convert_epars: rd_misc: %s\n", cp);
426 DuplexInit_184 = values[0];
431 /*------------------------------------------------------------*/
433 PRIVATE void rd_ninio(FILE *fp)
438 cp = get_array1(temp, 2, fp);
441 fprintf(stderr,"convert_epars: rd_F_ninio: %s\n", cp);
444 F_ninio37_184[2] = temp[0];
445 MAX_NINIO_184 = temp[1];
449 /*------------------------------------------------------------*/
450 PRIVATE void rd_Tetra_loop(FILE *fp)
456 memset(&Tetraloops_184, 0, 1400);
457 memset(&TETRA_ENERGY37_184, 0, sizeof(int)*200);
460 if (buf==NULL) break;
461 r = sscanf(buf,"%6s %d", &Tetraloops_184[7*i], &TETRA_ENERGY37_184[i]);
462 strcat(Tetraloops_184, " ");
465 } while((r==2)&&(i<200));
469 /*------------------------------------------------------------*/
470 PRIVATE void rd_Tri_loop(FILE *fp)
476 memset(&Triloops_184, 0, 241);
477 memset(&Triloop_E37_184, 0, sizeof(int)*40);
480 if (buf==NULL) break;
481 r = sscanf(buf,"%5s %d", &Triloops_184[6*i], &Triloop_E37_184[i]);
482 Triloops_184[6*i+5]=' ';
485 } while((r==2)&&(i<40));
489 /*------------------------------------------------------------*/
492 PRIVATE void ignore_comment(char * line)
494 /* excise C style comments */
495 /* only one comment per line, no multiline comments */
498 if ((cp1=strstr(line, "/*"))) {
499 cp2 = strstr(cp1, "*/");
501 nrerror("convert_epars: unclosed comment in parameter file");
502 /* can't use strcpy for overlapping strings */
503 for (cp2+=2; *cp2!='\0'; cp2++, cp1++)
511 PRIVATE enum parset_184 gettype_184(char ident[]){
512 if (strcmp(ident,"stack_enthalpies") == 0) return SH_184;
513 else if (strcmp(ident,"stack_energies") == 0) return S_184;
514 else if (strcmp(ident,"hairpin" ) == 0) return HP_184;
515 else if (strcmp(ident,"bulge") == 0) return B_184;
516 else if (strcmp(ident,"internal_loop") == 0) return IL_184;
517 else if (strcmp(ident,"mismatch_hairpin") == 0) return MMH_184;
518 else if (strcmp(ident,"mismatch_interior") == 0) return MMI_184;
519 else if (strcmp(ident,"mismatch_multi") == 0) return MMM_184;
520 else if (strcmp(ident,"mismatch_enthalpies") == 0) return MM_H_184;
521 else if (strcmp(ident,"int11_energies") == 0) return INT11_184;
522 else if (strcmp(ident,"int11_enthalpies") == 0) return INT11_H_184;
523 else if (strcmp(ident,"int21_energies") == 0) return INT21_184;
524 else if (strcmp(ident,"int21_enthalpies") == 0) return INT21_H_184;
525 else if (strcmp(ident,"int22_energies") == 0) return INT22_184;
526 else if (strcmp(ident,"int22_enthalpies") == 0) return INT22_H_184;
527 else if (strcmp(ident,"dangle5")== 0) return DE5_184;
528 else if (strcmp(ident,"dangle3")== 0) return DE3_184;
529 else if (strcmp(ident,"dangle5_enthalpies")== 0) return DE5_H_184;
530 else if (strcmp(ident,"dangle3_enthalpies")== 0) return DE3_H_184;
531 else if (strcmp(ident,"ML_params")== 0) return ML_184;
532 else if (strcmp(ident,"NINIO") == 0) return NIN_184;
533 else if (strcmp(ident,"Tetraloops") == 0) return TL_184;
534 else if (strcmp(ident,"Triloops") == 0) return TRI_184;
535 else if (strcmp(ident,"END") == 0) return QUIT_184;
536 else return UNKNOWN_184;
539 PRIVATE void write_new_parameter_file(FILE *ofile, unsigned int option_bits){
541 char *pnames[] = {"NP", "CG", "GC", "GU", "UG", "AU", "UA", " @"};
542 char bnames[] = "@ACGU";
543 unsigned int options = 0;
545 options = (option_bits & VRNA_CONVERT_OUTPUT_ALL) ?
546 VRNA_CONVERT_OUTPUT_HP
547 | VRNA_CONVERT_OUTPUT_STACK
548 | VRNA_CONVERT_OUTPUT_MM_HP
549 | VRNA_CONVERT_OUTPUT_MM_INT
550 | VRNA_CONVERT_OUTPUT_MM_INT_1N
551 | VRNA_CONVERT_OUTPUT_MM_INT_23
552 | VRNA_CONVERT_OUTPUT_MM_MULTI
553 | VRNA_CONVERT_OUTPUT_MM_EXT
554 | VRNA_CONVERT_OUTPUT_DANGLE5
555 | VRNA_CONVERT_OUTPUT_DANGLE3
556 | VRNA_CONVERT_OUTPUT_INT_11
557 | VRNA_CONVERT_OUTPUT_INT_21
558 | VRNA_CONVERT_OUTPUT_INT_22
559 | VRNA_CONVERT_OUTPUT_BULGE
560 | VRNA_CONVERT_OUTPUT_INT
561 | VRNA_CONVERT_OUTPUT_ML
562 | VRNA_CONVERT_OUTPUT_MISC
563 | VRNA_CONVERT_OUTPUT_SPECIAL_HP
564 | VRNA_CONVERT_OUTPUT_NINIO
568 make_pair_matrix(); /* needed for special loop energy contributions */
570 fprintf(ofile,"## RNAfold parameter file v2.0\n");
572 if(options & VRNA_CONVERT_OUTPUT_STACK){
573 fprintf(ofile,"\n# %s\n", settype(S));
574 fprintf(ofile,"/* CG GC GU UG AU UA @ */\n");
575 for (c=1; c<NBPAIRS+1; c++)
576 display_array(stack37_184[c]+1,NBPAIRS,NBPAIRS, ofile);
577 fprintf(ofile,"\n# %s\n", settype(S_H));
578 fprintf(ofile,"/* CG GC GU UG AU UA @ */\n");
579 for (c=1; c<NBPAIRS+1; c++)
580 display_array(enthalpies_184[c]+1,NBPAIRS,NBPAIRS, ofile);
583 if(options & VRNA_CONVERT_OUTPUT_MM_HP){
584 fprintf(ofile,"\n# %s\n", settype(MMH));
586 for (k=1; k<NBPAIRS+1; k++)
588 display_array(mismatchH37_184[k][i],5,5, ofile);
590 fprintf(ofile,"\n# %s\n", settype(MMH_H));
592 for (k=1; k<NBPAIRS+1; k++)
594 display_array(mism_H_184[k][i],5,5, ofile);
598 if(options & VRNA_CONVERT_OUTPUT_MM_INT){
599 fprintf(ofile,"\n# %s\n", settype(MMI));
601 for (k=1; k<NBPAIRS+1; k++)
603 display_array(mismatchI37_184[k][i],5,5, ofile);
605 fprintf(ofile,"\n# %s\n", settype(MMI_H));
607 for (k=1; k<NBPAIRS+1; k++)
609 display_array(mism_H_184[k][i],5,5, ofile);
613 if(options & VRNA_CONVERT_OUTPUT_MM_INT_1N){
614 fprintf(ofile,"\n# %s\n", settype(MMI1N));
616 for (k=1; k<NBPAIRS+1; k++)
618 display_array(mismatchI37_184[k][i],5,5, ofile);
620 fprintf(ofile,"\n# %s\n", settype(MMI1N_H));
622 for (k=1; k<NBPAIRS+1; k++)
624 display_array(mism_H_184[k][i],5,5, ofile);
628 if(options & VRNA_CONVERT_OUTPUT_MM_INT_23){
629 fprintf(ofile,"\n# %s\n", settype(MMI23));
631 for (k=1; k<NBPAIRS+1; k++)
633 display_array(mismatchI37_184[k][i],5,5, ofile);
635 fprintf(ofile,"\n# %s\n", settype(MMI23_H));
637 for (k=1; k<NBPAIRS+1; k++)
639 display_array(mism_H_184[k][i],5,5, ofile);
643 if(options & VRNA_CONVERT_OUTPUT_MM_MULTI){
644 fprintf(ofile,"\n# %s\n", settype(MMM));
645 fprintf(ofile,"/* @ A C G U */\n");
648 for (k=1; k<NBPAIRS+1; k++)
651 bla[j] = ((dangle5_37_184[k][i] == INF) ? 0 : dangle5_37_184[k][i]) + ((dangle3_37_184[k][j] == INF) ? 0 : dangle3_37_184[k][j]);
652 display_array(bla,5,5, ofile);
655 fprintf(ofile,"\n# %s\n", settype(MMM_H));
656 fprintf(ofile,"/* @ A C G U */\n");
658 for (k=1; k<NBPAIRS+1; k++)
661 bla[j] = ((dangle5_H_184[k][i] == INF) ? 0 : dangle5_H_184[k][i]) + ((dangle3_H_184[k][j] == INF) ? 0 : dangle3_H_184[k][j]);
662 display_array(bla,5,5, ofile);
667 if(options & VRNA_CONVERT_OUTPUT_MM_EXT){
668 fprintf(ofile,"\n# %s\n", settype(MME));
669 fprintf(ofile,"/* @ A C G U */\n");
672 for (k=1; k<NBPAIRS+1; k++)
675 bla[j] = ((dangle5_37_184[k][i] == INF) ? 0 : dangle5_37_184[k][i]) + ((dangle3_37_184[k][j] == INF) ? 0 : dangle3_37_184[k][j]);
676 display_array(bla,5,5, ofile);
679 fprintf(ofile,"\n# %s\n", settype(MME_H));
680 fprintf(ofile,"/* @ A C G U */\n");
682 for (k=1; k<NBPAIRS+1; k++)
685 bla[j] = ((dangle5_37_184[k][i] == INF) ? 0 : dangle5_H_184[k][i]) + ((dangle3_H_184[k][j] == INF) ? 0 : dangle3_H_184[k][j]);
686 display_array(bla,5,5, ofile);
691 if(options & VRNA_CONVERT_OUTPUT_DANGLE5){
692 fprintf(ofile,"\n# %s\n", settype(D5));
693 fprintf(ofile,"/* @ A C G U */\n");
694 for (c=1; c<NBPAIRS+1; c++)
695 display_array(dangle5_37_184[c], 5, 5, ofile);
696 fprintf(ofile,"\n# %s\n", settype(D5_H));
697 fprintf(ofile,"/* @ A C G U */\n");
698 for (c=1; c<NBPAIRS+1; c++)
699 display_array(dangle5_H_184[c], 5, 5, ofile);
702 if(options & VRNA_CONVERT_OUTPUT_DANGLE3){
703 fprintf(ofile,"\n# %s\n", settype(D3));
704 fprintf(ofile,"/* @ A C G U */\n");
705 for (c=1; c<NBPAIRS+1; c++)
706 display_array(dangle3_37_184[c], 5, 5, ofile);
707 fprintf(ofile,"\n# %s\n", settype(D3_H));
708 fprintf(ofile,"/* @ A C G U */\n");
709 for (c=1; c<NBPAIRS+1; c++)
710 display_array(dangle3_H_184[c], 5, 5, ofile);
713 if(options & VRNA_CONVERT_OUTPUT_INT_11){
714 /* don't print "no pair" entries for interior loop arrays */
715 fprintf(ofile,"\n# %s\n", settype(INT11));
717 for (k=1; k<NBPAIRS+1; k++)
718 for (l=1; l<NBPAIRS+1; l++){
719 fprintf(ofile, "/* %2s..%2s */\n", pnames[k], pnames[l]);
721 display_array(int11_37_184[k][l][i], 5, 5, ofile);
724 fprintf(ofile,"\n# %s\n", settype(INT11_H));
726 for (k=1; k<NBPAIRS+1; k++)
727 for (l=1; l<NBPAIRS+1; l++){
728 fprintf(ofile, "/* %2s..%2s */\n", pnames[k], pnames[l]);
730 display_array(int11_H_184[k][l][i],5,5, ofile);
735 if(options & VRNA_CONVERT_OUTPUT_INT_21){
736 fprintf(ofile,"\n# %s\n", settype(INT21));
738 for (p1=1; p1<NBPAIRS+1; p1++)
739 for (p2=1; p2<NBPAIRS+1; p2++)
741 fprintf(ofile, "/* %2s.%c..%2s */\n", pnames[p1], bnames[i], pnames[p2]);
743 display_array(int21_37_184[p1][p2][i][j],5,5, ofile);
746 fprintf(ofile,"\n# %s\n", settype(INT21_H));
748 for (p1=1; p1<NBPAIRS+1; p1++)
749 for (p2=1; p2<NBPAIRS+1; p2++)
751 fprintf(ofile, "/* %2s.%c..%2s */\n", pnames[p1], bnames[i], pnames[p2]);
753 display_array(int21_H_184[p1][p2][i][j],5,5, ofile);
758 if(options & VRNA_CONVERT_OUTPUT_INT_22){
759 fprintf(ofile,"\n# %s\n", settype(INT22));
760 { int p1, p2, i, j, k;
761 for (p1=1; p1<NBPAIRS; p1++)
762 for (p2=1; p2<NBPAIRS; p2++)
765 fprintf(ofile, "/* %2s.%c%c..%2s */\n", pnames[p1], bnames[i], bnames[j], pnames[p2]);
767 display_array(int22_37_184[p1][p2][i][j][k]+1,4,5, ofile);
770 fprintf(ofile,"\n# %s\n", settype(INT22_H));
771 { int p1, p2, i, j, k;
772 for (p1=1; p1<NBPAIRS; p1++)
773 for (p2=1; p2<NBPAIRS; p2++)
776 fprintf(ofile, "/* %2s.%c%c..%2s */\n", pnames[p1], bnames[i], bnames[j], pnames[p2]);
778 display_array(int22_H_184[p1][p2][i][j][k]+1,4,5, ofile);
783 if(options & VRNA_CONVERT_OUTPUT_HP){
784 fprintf(ofile,"\n# %s\n", settype(HP));
785 display_array(hairpin37_184, 31, 10, ofile);
786 /* we had no hairpin enthalpies before, so
787 * we just pretend to have had some with value 0
789 fprintf(ofile,"\n# %s\n", settype(HP_H));
791 fprintf(ofile, " INF INF INF");
793 fprintf(ofile, "%6d", 0);
794 if(c%10 == 0) fprintf(ofile, "\n");
800 if(options & VRNA_CONVERT_OUTPUT_BULGE){
801 fprintf(ofile,"\n# %s\n", settype(B));
802 display_array(bulge37_184, 31, 10, ofile);
804 /* we had no bulge enthalpies before, so
805 * we just pretend to have had some with value 0
807 fprintf(ofile,"\n# %s\n", settype(B_H));
809 fprintf(ofile, " INF");
811 fprintf(ofile, "%6d", 0);
812 if(c%10 == 0) fprintf(ofile, "\n");
818 if(options & VRNA_CONVERT_OUTPUT_INT){
819 fprintf(ofile,"\n# %s\n", settype(IL));
820 display_array(internal_loop37_184, 31, 10, ofile);
822 /* we had no internal_loop enthalpies before, so
823 * we just pretend to have had some with value 0
825 fprintf(ofile,"\n# %s\n", settype(IL_H));
827 fprintf(ofile, " INF INF INF INF");
829 fprintf(ofile, "%6d", 0);
830 if(c%10 == 0) fprintf(ofile, "\n");
834 fprintf(ofile,"\n# %s\n"
835 "/* Ninio = MIN(max, m*|n1-n2| */\n"
836 "/*\t m\t m_dH max */\n"
837 "\t%6d\t%6d\t%6d\n", settype(NIN), F_ninio37_184[2], 0, MAX_NINIO_184);
840 if(options & VRNA_CONVERT_OUTPUT_ML){
841 fprintf(ofile,"\n# %s\n", settype(ML));
842 fprintf(ofile,"/* F = cu*n_unpaired + cc + ci*loop_degree (+TermAU) */\n");
843 fprintf(ofile,"/*\t cu\t cu_dH\t cc\t cc_dH\t ci\t ci_dH */\n");
844 fprintf(ofile,"\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\n", ML_BASE37_184, 0, ML_closing37_184, 0, ML_intern37_184, 0);
847 if(options & VRNA_CONVERT_OUTPUT_MISC){
848 fprintf(ofile,"\n# %s\n", settype(MISC));
849 fprintf(ofile,"/* all parameters are pairs of 'energy enthalpy' */\n");
850 fprintf(ofile,"/* DuplexInit TerminalAU LXC */\n");
851 fprintf(ofile," %6d %6d %6d %6d %3.6f %6d\n", DuplexInit_184, 0, TerminalAU_184, 0, lxc37_184, 0);
854 if(options & VRNA_CONVERT_OUTPUT_SPECIAL_HP){
855 fprintf(ofile,"\n# %s\n", settype(TRI));
857 int base_en = hairpin37_184[3];
858 int base_dH = TETRA_ENTH37_184;
859 for (c=0; c< (int)strlen(Triloops_184)/6; c++){
862 strncpy(bla, Triloops_184+c*6, 5);
863 int type = pair[(short)encode_char(toupper(bla[0]))][(short)encode_char(toupper(bla[4]))];
864 if(type > 2) en += TerminalAU_184;
865 fprintf(ofile,"\t%.5s %6d %6d\n", Triloops_184+c*6, Triloop_E37_184[c] + en, base_dH);
869 /* since the old hairpin loop function treated the tabulated tetraloop energy as bonus
870 * and the new one takes this tabulated energy as a total energy, we have to compute some
873 fprintf(ofile,"\n# %s\n", settype(TL));
875 int base_en = hairpin37_184[4];
876 int base_dH = TETRA_ENTH37_184;
877 for (c=0; c< (int)strlen(Tetraloops_184)/7; c++){
881 strncpy(bla, Tetraloops_184+c*7, 6);
882 short si = (short)encode_char(toupper(bla[1]));
883 short sj = (short)encode_char(toupper(bla[4]));
884 int type = pair[(short)encode_char(toupper(bla[0]))][(short)encode_char(toupper(bla[5]))];
885 en += mismatchH37_184[type][si][sj];
886 dH += mism_H_184[type][si][sj];
887 fprintf(ofile,"\t%.6s %6d %6d\n", Tetraloops_184+c*7, en + TETRA_ENERGY37_184[c], dH);
890 fprintf(ofile,"\n# %s\n", settype(HEX));
892 fprintf(ofile, "\n");
896 fprintf(ofile, "\n# %s\n", settype(QUIT));
899 PRIVATE void check_symmetry(void) {
902 for (i=0; i<=NBPAIRS; i++)
903 for (j=0; j<=NBPAIRS; j++)
904 if (stack37_184[i][j] != stack37_184[j][i])
905 fprintf(stderr, "WARNING: stacking energies not symmetric\n");
907 for (i=0; i<=NBPAIRS; i++)
908 for (j=0; j<=NBPAIRS; j++)
909 if (enthalpies_184[i][j] != enthalpies_184[j][i])
910 fprintf(stderr, "WARNING: stacking enthalpies not symmetric\n");
913 /* interior 1x1 loops */
914 for (i=0; i<=NBPAIRS; i++)
915 for (j=0; j<=NBPAIRS; j++)
918 if (int11_37_184[i][j][k][l] != int11_37_184[j][i][l][k])
919 fprintf(stderr, "WARNING: int11 energies not symmetric\n");
921 for (i=0; i<=NBPAIRS; i++)
922 for (j=0; j<=NBPAIRS; j++)
925 if (int11_H_184[i][j][k][l] != int11_H_184[j][i][l][k])
926 fprintf(stderr, "WARNING: int11 enthalpies not symmetric\n");
928 /* interior 2x2 loops */
929 for (i=0; i<=NBPAIRS; i++)
930 for (j=0; j<=NBPAIRS; j++)
932 for (l=0; l<5; l++) {
936 if (int22_37_184[i][j][k][l][m][n] != int22_37_184[j][i][m][n][k][l])
937 fprintf(stderr, "WARNING: int22 energies not symmetric\n");
940 for (i=0; i<=NBPAIRS; i++)
941 for (j=0; j<=NBPAIRS; j++)
943 for (l=0; l<5; l++) {
947 if (int22_H_184[i][j][k][l][m][n] != int22_H_184[j][i][m][n][k][l])
948 fprintf(stderr, "WARNING: int22 enthalpies not symmetric: %d %d %d %d %d %d\n", i,j,k,l,m,n);