1 /** \file eval.c */
2
3
4 /*
5 * Free energy evaluation
6 *
7 * c Ivo Hofacker, Chrisoph Flamm
8 * original implementation by
9 * Walter Fontana
10 *
11 * ViennaRNA Package >= v2.0 by Ronny Lorenz
12 *
13 * Vienna RNA package
14 */
15
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include "ViennaRNA/utils/basic.h"
27 #include "ViennaRNA/utils/strings.h"
28 #include "ViennaRNA/model.h"
29 #include "ViennaRNA/params/basic.h"
30 #include "ViennaRNA/constraints/hard.h"
31 #include "ViennaRNA/constraints/soft.h"
32 #include "ViennaRNA/alphabet.h"
33 #include "ViennaRNA/eval.h"
34
35 #ifdef __GNUC__
36 # define INLINE inline
37 #else
38 # define INLINE
39 #endif
40
41 /*
42 #################################
43 # GLOBAL VARIABLES #
44 #################################
45 */
46 #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY
47
48 PUBLIC int cut_point = -1; /* set to first pos of second seq for cofolding */
49 PUBLIC int eos_debug = 0; /* verbose info from energy_of_struct */
50
51 /*
52 #################################
53 # PRIVATE VARIABLES #
54 #################################
55 */
56 PRIVATE vrna_fold_compound_t *backward_compat_compound = NULL;
57
58 #ifdef _OPENMP
59
60 #pragma omp threadprivate(backward_compat_compound)
61
62 #endif
63
64 /*
65 #################################
66 # PRIVATE FUNCTION DECLARATIONS #
67 #################################
68 */
69 PRIVATE vrna_param_t *
70 get_updated_params(vrna_param_t *parameters,
71 int compat);
72
73
74 PRIVATE vrna_fold_compound_t *
75 recycle_last_call(const char *string,
76 vrna_param_t *P);
77
78
79 PRIVATE INLINE float
80 eval_structure_simple_v(const char *string,
81 const char *structure,
82 int verbosity_level,
83 int gquad,
84 int circular,
85 FILE *file);
86
87
88 PRIVATE INLINE float
89 eval_consensus_structure_simple_v(const char **alignment,
90 const char *structure,
91 int verbosity_level,
92 int gquad,
93 int circular,
94 FILE *file);
95
96
97 #endif
98
99 /*
100 #################################
101 # BEGIN OF FUNCTION DEFINITIONS #
102 #################################
103 */
104 PUBLIC float
vrna_eval_structure(vrna_fold_compound_t * fc,const char * structure)105 vrna_eval_structure(vrna_fold_compound_t *fc,
106 const char *structure)
107 {
108 return vrna_eval_structure_v(fc, structure, VRNA_VERBOSITY_QUIET, NULL);
109 }
110
111
112 PUBLIC float
vrna_eval_structure_verbose(vrna_fold_compound_t * fc,const char * structure,FILE * file)113 vrna_eval_structure_verbose(vrna_fold_compound_t *fc,
114 const char *structure,
115 FILE *file)
116 {
117 return vrna_eval_structure_v(fc, structure, VRNA_VERBOSITY_DEFAULT, file);
118 }
119
120
121 PUBLIC float
vrna_eval_structure_simple(const char * string,const char * structure)122 vrna_eval_structure_simple(const char *string,
123 const char *structure)
124 {
125 return eval_structure_simple_v(string, structure, VRNA_VERBOSITY_QUIET, 0, 0, NULL);
126 }
127
128
129 PUBLIC float
vrna_eval_consensus_structure_simple(const char ** alignment,const char * structure)130 vrna_eval_consensus_structure_simple(const char **alignment,
131 const char *structure)
132 {
133 return eval_consensus_structure_simple_v(alignment, structure, VRNA_VERBOSITY_QUIET, 0, 0, NULL);
134 }
135
136
137 PUBLIC float
vrna_eval_gquad_structure(const char * string,const char * structure)138 vrna_eval_gquad_structure(const char *string,
139 const char *structure)
140 {
141 return eval_structure_simple_v(string, structure, VRNA_VERBOSITY_QUIET, 1, 0, NULL);
142 }
143
144
145 PUBLIC float
vrna_eval_gquad_consensus_structure(const char ** alignment,const char * structure)146 vrna_eval_gquad_consensus_structure(const char **alignment,
147 const char *structure)
148 {
149 return eval_consensus_structure_simple_v(alignment, structure, VRNA_VERBOSITY_QUIET, 1, 0, NULL);
150 }
151
152
153 PUBLIC float
vrna_eval_circ_structure(const char * string,const char * structure)154 vrna_eval_circ_structure(const char *string,
155 const char *structure)
156 {
157 return eval_structure_simple_v(string, structure, VRNA_VERBOSITY_QUIET, 0, 1, NULL);
158 }
159
160
161 PUBLIC float
vrna_eval_circ_consensus_structure(const char ** alignment,const char * structure)162 vrna_eval_circ_consensus_structure(const char **alignment,
163 const char *structure)
164 {
165 return eval_consensus_structure_simple_v(alignment, structure, VRNA_VERBOSITY_QUIET, 0, 1, NULL);
166 }
167
168
169 PUBLIC float
vrna_eval_circ_gquad_structure(const char * string,const char * structure)170 vrna_eval_circ_gquad_structure(const char *string,
171 const char *structure)
172 {
173 return eval_structure_simple_v(string, structure, VRNA_VERBOSITY_QUIET, 1, 1, NULL);
174 }
175
176
177 PUBLIC float
vrna_eval_circ_gquad_consensus_structure(const char ** alignment,const char * structure)178 vrna_eval_circ_gquad_consensus_structure(const char **alignment,
179 const char *structure)
180 {
181 return eval_consensus_structure_simple_v(alignment, structure, VRNA_VERBOSITY_QUIET, 1, 1, NULL);
182 }
183
184
185 PUBLIC float
vrna_eval_structure_simple_verbose(const char * string,const char * structure,FILE * file)186 vrna_eval_structure_simple_verbose(const char *string,
187 const char *structure,
188 FILE *file)
189 {
190 return eval_structure_simple_v(string, structure, VRNA_VERBOSITY_DEFAULT, 0, 0, file);
191 }
192
193
194 PUBLIC float
vrna_eval_consensus_structure_simple_verbose(const char ** alignment,const char * structure,FILE * file)195 vrna_eval_consensus_structure_simple_verbose(const char **alignment,
196 const char *structure,
197 FILE *file)
198 {
199 return eval_consensus_structure_simple_v(alignment, structure, VRNA_VERBOSITY_DEFAULT, 0, 0,
200 file);
201 }
202
203
204 PUBLIC float
vrna_eval_structure_simple_v(const char * string,const char * structure,int verbosity_level,FILE * file)205 vrna_eval_structure_simple_v(const char *string,
206 const char *structure,
207 int verbosity_level,
208 FILE *file)
209 {
210 return eval_structure_simple_v(string, structure, verbosity_level, 0, 0, file);
211 }
212
213
214 PUBLIC float
vrna_eval_consensus_structure_simple_v(const char ** alignment,const char * structure,int verbosity_level,FILE * file)215 vrna_eval_consensus_structure_simple_v(const char **alignment,
216 const char *structure,
217 int verbosity_level,
218 FILE *file)
219 {
220 return eval_consensus_structure_simple_v(alignment, structure, verbosity_level, 0, 0, file);
221 }
222
223
224 PUBLIC float
vrna_eval_circ_structure_v(const char * string,const char * structure,int verbosity_level,FILE * file)225 vrna_eval_circ_structure_v(const char *string,
226 const char *structure,
227 int verbosity_level,
228 FILE *file)
229 {
230 return eval_structure_simple_v(string, structure, verbosity_level, 0, 1, file);
231 }
232
233
234 PUBLIC float
vrna_eval_circ_consensus_structure_v(const char ** alignment,const char * structure,int verbosity_level,FILE * file)235 vrna_eval_circ_consensus_structure_v(const char **alignment,
236 const char *structure,
237 int verbosity_level,
238 FILE *file)
239 {
240 return eval_consensus_structure_simple_v(alignment, structure, verbosity_level, 0, 1, file);
241 }
242
243
244 PUBLIC float
vrna_eval_gquad_structure_v(const char * string,const char * structure,int verbosity_level,FILE * file)245 vrna_eval_gquad_structure_v(const char *string,
246 const char *structure,
247 int verbosity_level,
248 FILE *file)
249 {
250 return eval_structure_simple_v(string, structure, verbosity_level, 1, 0, file);
251 }
252
253
254 PUBLIC float
vrna_eval_gquad_consensus_structure_v(const char ** alignment,const char * structure,int verbosity_level,FILE * file)255 vrna_eval_gquad_consensus_structure_v(const char **alignment,
256 const char *structure,
257 int verbosity_level,
258 FILE *file)
259 {
260 return eval_consensus_structure_simple_v(alignment, structure, verbosity_level, 1, 0, file);
261 }
262
263
264 PUBLIC float
vrna_eval_circ_gquad_structure_v(const char * string,const char * structure,int verbosity_level,FILE * file)265 vrna_eval_circ_gquad_structure_v(const char *string,
266 const char *structure,
267 int verbosity_level,
268 FILE *file)
269 {
270 return eval_structure_simple_v(string, structure, verbosity_level, 1, 1, file);
271 }
272
273
274 PUBLIC float
vrna_eval_circ_gquad_consensus_structure_v(const char ** alignment,const char * structure,int verbosity_level,FILE * file)275 vrna_eval_circ_gquad_consensus_structure_v(const char **alignment,
276 const char *structure,
277 int verbosity_level,
278 FILE *file)
279 {
280 return eval_consensus_structure_simple_v(alignment, structure, verbosity_level, 1, 1, file);
281 }
282
283
284 PUBLIC int
vrna_eval_structure_pt(vrna_fold_compound_t * fc,const short * pt)285 vrna_eval_structure_pt(vrna_fold_compound_t *fc,
286 const short *pt)
287 {
288 return vrna_eval_structure_pt_v(fc, pt, VRNA_VERBOSITY_QUIET, NULL);
289 }
290
291
292 PUBLIC int
vrna_eval_structure_pt_verbose(vrna_fold_compound_t * fc,const short * pt,FILE * file)293 vrna_eval_structure_pt_verbose(vrna_fold_compound_t *fc,
294 const short *pt,
295 FILE *file)
296 {
297 return vrna_eval_structure_pt_v(fc, pt, VRNA_VERBOSITY_DEFAULT, file);
298 }
299
300
301 PUBLIC int
vrna_eval_structure_pt_simple(const char * string,const short * pt)302 vrna_eval_structure_pt_simple(const char *string,
303 const short *pt)
304 {
305 return vrna_eval_structure_pt_simple_v(string, pt, VRNA_VERBOSITY_QUIET, NULL);
306 }
307
308
309 PUBLIC int
vrna_eval_consensus_structure_pt_simple(const char ** alignment,const short * pt)310 vrna_eval_consensus_structure_pt_simple(const char **alignment,
311 const short *pt)
312 {
313 return vrna_eval_consensus_structure_pt_simple_v(alignment, pt, VRNA_VERBOSITY_QUIET, NULL);
314 }
315
316
317 PUBLIC int
vrna_eval_structure_pt_simple_verbose(const char * string,const short * pt,FILE * file)318 vrna_eval_structure_pt_simple_verbose(const char *string,
319 const short *pt,
320 FILE *file)
321 {
322 return vrna_eval_structure_pt_simple_v(string, pt, VRNA_VERBOSITY_DEFAULT, file);
323 }
324
325
326 PUBLIC int
vrna_eval_consensus_structure_pt_simple_verbose(const char ** alignment,const short * pt,FILE * file)327 vrna_eval_consensus_structure_pt_simple_verbose(const char **alignment,
328 const short *pt,
329 FILE *file)
330 {
331 return vrna_eval_consensus_structure_pt_simple_v(alignment, pt, VRNA_VERBOSITY_DEFAULT, file);
332 }
333
334
335 PUBLIC int
vrna_eval_structure_pt_simple_v(const char * string,const short * pt,int verbosity_level,FILE * file)336 vrna_eval_structure_pt_simple_v(const char *string,
337 const short *pt,
338 int verbosity_level,
339 FILE *file)
340 {
341 int e;
342
343 /* create fold_compound with default parameters and without DP matrices */
344 vrna_fold_compound_t *fc = vrna_fold_compound(string, NULL, VRNA_OPTION_EVAL_ONLY);
345
346 /* evaluate structure */
347 e = vrna_eval_structure_pt_v(fc, pt, verbosity_level, file);
348
349 /* free fold_compound */
350 vrna_fold_compound_free(fc);
351
352 return e;
353 }
354
355
356 PUBLIC int
vrna_eval_consensus_structure_pt_simple_v(const char ** alignment,const short * pt,int verbosity_level,FILE * file)357 vrna_eval_consensus_structure_pt_simple_v(const char **alignment,
358 const short *pt,
359 int verbosity_level,
360 FILE *file)
361 {
362 int e;
363
364 /* create fold_compound with default parameters and without DP matrices */
365 vrna_fold_compound_t *fc = vrna_fold_compound_comparative(alignment, NULL, VRNA_OPTION_DEFAULT);
366
367 /* evaluate structure */
368 e = vrna_eval_structure_pt_v(fc, pt, verbosity_level, file);
369
370 /* free fold_compound */
371 vrna_fold_compound_free(fc);
372
373 return e;
374 }
375
376
377 PUBLIC int
vrna_eval_move_pt_simple(const char * string,short * pt,int m1,int m2)378 vrna_eval_move_pt_simple(const char *string,
379 short *pt,
380 int m1,
381 int m2)
382 {
383 int e;
384
385 /* create fold_compound with default parameters and without DP matrices */
386 vrna_fold_compound_t *fc = vrna_fold_compound(string, NULL, VRNA_OPTION_EVAL_ONLY);
387
388 /* evaluate structure */
389 e = vrna_eval_move_pt(fc, pt, m1, m2);
390
391 /* free fold_compound */
392 vrna_fold_compound_free(fc);
393
394 return e;
395 }
396
397
398 PUBLIC int
vrna_eval_move_shift_pt(vrna_fold_compound_t * fc,vrna_move_t * m,short * structure)399 vrna_eval_move_shift_pt(vrna_fold_compound_t *fc,
400 vrna_move_t *m,
401 short *structure)
402 {
403 if ((m->pos_5 < 0 && m->pos_3 > 0) || (m->pos_5 > 0 && m->pos_3 < 0)) {
404 /* split shift move */
405 int unchangedPosition = m->pos_5 > 0 ? m->pos_5 : m->pos_3;
406 int insertedPosition = m->pos_5 < 0 ? -m->pos_5 : -m->pos_3;
407 int d1 = -structure[unchangedPosition];
408 int d2 = -unchangedPosition;
409 vrna_move_t deletion;
410 if (d1 < d2)
411 deletion = vrna_move_init(d2, d1);
412 else
413 deletion = vrna_move_init(d1, d2);
414
415 int i1 = unchangedPosition;
416 int i2 = insertedPosition;
417 vrna_move_t insertion;
418 if (i1 > i2)
419 insertion = vrna_move_init(i2, i1);
420 else
421 insertion = vrna_move_init(i1, i2);
422
423 int energy = vrna_eval_move_pt(fc, structure, deletion.pos_5, deletion.pos_3);
424 short *tmpS = vrna_ptable_copy(structure);
425 vrna_move_apply(tmpS, &deletion);
426 energy += vrna_eval_move_pt(fc, tmpS, insertion.pos_5, insertion.pos_3);
427 free(tmpS);
428 return energy;
429 } else {
430 return vrna_eval_move_pt(fc, structure, m->pos_5, m->pos_3);
431 }
432 }
433
434
435 PUBLIC float
vrna_eval_move(vrna_fold_compound_t * fc,const char * structure,int m1,int m2)436 vrna_eval_move(vrna_fold_compound_t *fc,
437 const char *structure,
438 int m1,
439 int m2)
440 {
441 short *pt;
442 int en;
443
444 if (strlen(structure) != fc->length) {
445 vrna_message_warning("vrna_eval_move: "
446 "sequence and structure have unequal length (%d vs. %d)",
447 fc->length,
448 strlen(structure));
449 return (float)(INF / 100.);
450 }
451
452 pt = vrna_ptable(structure);
453 en = vrna_eval_move_pt(fc, pt, m1, m2);
454
455 free(pt);
456
457 return (float)en / 100.;
458 }
459
460
461 PUBLIC int
vrna_eval_loop_pt(vrna_fold_compound_t * fc,int i,const short * pt)462 vrna_eval_loop_pt(vrna_fold_compound_t *fc,
463 int i,
464 const short *pt)
465 {
466 return vrna_eval_loop_pt_v(fc, i, pt, VRNA_VERBOSITY_QUIET);
467 }
468
469
470 PRIVATE INLINE float
eval_structure_simple_v(const char * string,const char * structure,int verbosity_level,int gquad,int circular,FILE * file)471 eval_structure_simple_v(const char *string,
472 const char *structure,
473 int verbosity_level,
474 int gquad,
475 int circular,
476 FILE *file)
477 {
478 char *str;
479 int cp;
480 float e;
481 vrna_md_t md;
482
483 vrna_md_set_default(&md);
484
485 md.circ = circular;
486 md.gquad = gquad;
487
488 /* create fold_compound with default parameters and without DP matrices */
489 vrna_fold_compound_t *fc = vrna_fold_compound(string, &md, VRNA_OPTION_DEFAULT);
490
491 /* splice-out '&' strand break identifier, if present in structure */
492 str = vrna_cut_point_remove(structure, &cp);
493
494 /* evaluate structure */
495 e = vrna_eval_structure_v(fc, str, verbosity_level, file);
496
497 /* free fold_compound */
498 vrna_fold_compound_free(fc);
499 free(str);
500
501 return e;
502 }
503
504
505 PRIVATE INLINE float
eval_consensus_structure_simple_v(const char ** alignment,const char * structure,int verbosity_level,int gquad,int circular,FILE * file)506 eval_consensus_structure_simple_v(const char **alignment,
507 const char *structure,
508 int verbosity_level,
509 int gquad,
510 int circular,
511 FILE *file)
512 {
513 char *str;
514 int cp;
515 float e;
516 vrna_md_t md;
517
518 vrna_md_set_default(&md);
519
520 md.circ = circular;
521 md.gquad = gquad;
522
523 /* create fold_compound with default parameters and without DP matrices */
524 vrna_fold_compound_t *fc = vrna_fold_compound_comparative(alignment, &md, VRNA_OPTION_DEFAULT);
525
526 /* splice-out '&' strand break identifier, if present in structure */
527 str = vrna_cut_point_remove(structure, &cp);
528
529 /* evaluate structure */
530 e = vrna_eval_structure_v(fc, str, verbosity_level, file);
531
532 /* free fold_compound */
533 vrna_fold_compound_free(fc);
534 free(str);
535
536 return e;
537 }
538
539
540 /*
541 #################################
542 # DEPRECATED functions below #
543 #################################
544 */
545
546 #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY
547
548 PRIVATE vrna_fold_compound_t *
recycle_last_call(const char * string,vrna_param_t * P)549 recycle_last_call(const char *string,
550 vrna_param_t *P)
551 {
552 vrna_fold_compound_t *fc;
553 vrna_md_t *md;
554 int cleanup;
555 char *seq;
556
557 fc = NULL;
558 cleanup = 0;
559
560 if (P) {
561 md = &(P->model_details);
562 } else {
563 md = (vrna_md_t *)vrna_alloc(sizeof(vrna_md_t));
564 set_model_details(md);
565 cleanup = 1;
566 }
567
568 if (string) {
569 if (backward_compat_compound) {
570 if (!strcmp(string, backward_compat_compound->sequence)) {
571 /* check if sequence is the same as before */
572 md->window_size = (int)backward_compat_compound->length;
573 md->max_bp_span = (int)backward_compat_compound->length;
574 /* check if model_details are the same as before */
575 if (!memcmp(md, &(backward_compat_compound->params->model_details), sizeof(vrna_md_t)))
576 /* re-use previous vrna_fold_compound_t */
577 fc = backward_compat_compound;
578 }
579 }
580 }
581
582 /* prepare a new global vrna_fold_compound_t with current settings */
583 if (!fc) {
584 vrna_fold_compound_free(backward_compat_compound);
585 seq = vrna_cut_point_insert(string, cut_point);
586 backward_compat_compound = fc = vrna_fold_compound(seq, md, VRNA_OPTION_EVAL_ONLY);
587 if (P) {
588 free(fc->params);
589 fc->params = get_updated_params(P, 1);
590 }
591
592 free(seq);
593 }
594
595 if (cleanup)
596 free(md);
597
598 return fc;
599 }
600
601
602 PUBLIC float
energy_of_struct(const char * string,const char * structure)603 energy_of_struct(const char *string,
604 const char *structure)
605 {
606 float en;
607 vrna_fold_compound_t *fc;
608
609 fc = recycle_last_call(string, NULL);
610
611 if (eos_debug > 0)
612 en = vrna_eval_structure_verbose(fc, structure, NULL);
613 else
614 en = vrna_eval_structure(fc, structure);
615
616 return en;
617 }
618
619
620 PUBLIC int
energy_of_struct_pt(const char * string,short * pt,short * s,short * s1)621 energy_of_struct_pt(const char *string,
622 short *pt,
623 short *s,
624 short *s1)
625 {
626 int en;
627 vrna_fold_compound_t *fc;
628
629 if (pt && string) {
630 if (pt[0] != (short)strlen(string)) {
631 vrna_message_warning("energy_of_struct_pt: "
632 "string and structure have unequal length (%d vs. %d)",
633 strlen(string),
634 pt[0]);
635 return INF;
636 }
637
638 fc = recycle_last_call(string, NULL);
639 en = vrna_eval_structure_pt_v(fc, pt, eos_debug, NULL);
640
641 return en;
642 } else {
643 return INF;
644 }
645 }
646
647
648 PUBLIC float
energy_of_circ_struct(const char * string,const char * structure)649 energy_of_circ_struct(const char *string,
650 const char *structure)
651 {
652 float en;
653 vrna_fold_compound_t *fc;
654
655 fc = recycle_last_call(string, NULL);
656
657 fc->params->model_details.circ = 1;
658
659 if (eos_debug > 0)
660 en = vrna_eval_structure_verbose(fc, structure, NULL);
661 else
662 en = vrna_eval_structure(fc, structure);
663
664 return en;
665 }
666
667
668 PUBLIC float
energy_of_structure(const char * string,const char * structure,int verbosity_level)669 energy_of_structure(const char *string,
670 const char *structure,
671 int verbosity_level)
672 {
673 vrna_fold_compound_t *fc;
674
675 fc = recycle_last_call(string, NULL);
676
677 return vrna_eval_structure_v(fc, structure, verbosity_level, NULL);
678 }
679
680
681 PUBLIC float
energy_of_struct_par(const char * string,const char * structure,vrna_param_t * parameters,int verbosity_level)682 energy_of_struct_par(const char *string,
683 const char *structure,
684 vrna_param_t *parameters,
685 int verbosity_level)
686 {
687 vrna_fold_compound_t *fc;
688
689 fc = recycle_last_call(string, parameters);
690
691 return vrna_eval_structure_v(fc, structure, verbosity_level, NULL);
692 }
693
694
695 PUBLIC float
energy_of_gquad_structure(const char * string,const char * structure,int verbosity_level)696 energy_of_gquad_structure(const char *string,
697 const char *structure,
698 int verbosity_level)
699 {
700 vrna_fold_compound_t *fc;
701
702 fc = recycle_last_call(string, NULL);
703
704 fc->params->model_details.gquad = 1;
705
706 return vrna_eval_structure_v(fc, structure, verbosity_level, NULL);
707 }
708
709
710 PUBLIC float
energy_of_gquad_struct_par(const char * string,const char * structure,vrna_param_t * parameters,int verbosity_level)711 energy_of_gquad_struct_par(const char *string,
712 const char *structure,
713 vrna_param_t *parameters,
714 int verbosity_level)
715 {
716 vrna_fold_compound_t *fc;
717
718 fc = recycle_last_call(string, parameters);
719
720 fc->params->model_details.gquad = 1;
721
722 return vrna_eval_structure_v(fc, structure, verbosity_level, NULL);
723 }
724
725
726 PUBLIC int
energy_of_structure_pt(const char * string,short * pt,short * s,short * s1,int verbosity_level)727 energy_of_structure_pt(const char *string,
728 short *pt,
729 short *s,
730 short *s1,
731 int verbosity_level)
732 {
733 int en;
734 vrna_fold_compound_t *fc;
735
736 if (pt && string) {
737 if (pt[0] != (short)strlen(string)) {
738 vrna_message_warning("energy_of_structure_pt: "
739 "string and structure have unequal length (%d vs. %d)",
740 strlen(string),
741 pt[0]);
742 return INF;
743 }
744
745 fc = recycle_last_call(string, NULL);
746 en = vrna_eval_structure_pt_v(fc, pt, verbosity_level, NULL);
747
748 return en;
749 } else {
750 return INF;
751 }
752 }
753
754
755 PUBLIC int
energy_of_struct_pt_par(const char * string,short * pt,short * s,short * s1,vrna_param_t * parameters,int verbosity_level)756 energy_of_struct_pt_par(const char *string,
757 short *pt,
758 short *s,
759 short *s1,
760 vrna_param_t *parameters,
761 int verbosity_level)
762 {
763 int en;
764 vrna_fold_compound_t *fc;
765
766 if (pt && string) {
767 if (pt[0] != (short)strlen(string)) {
768 vrna_message_warning("energy_of_struct_pt_par: "
769 "string and structure have unequal length (%d vs. %d)",
770 strlen(string),
771 pt[0]);
772 return INF;
773 }
774
775 fc = recycle_last_call(string, parameters);
776 en = vrna_eval_structure_pt_v(fc, pt, verbosity_level, NULL);
777
778 return en;
779 } else {
780 return INF;
781 }
782 }
783
784
785 PUBLIC float
energy_of_circ_structure(const char * string,const char * structure,int verbosity_level)786 energy_of_circ_structure(const char *string,
787 const char *structure,
788 int verbosity_level)
789 {
790 vrna_fold_compound_t *fc;
791
792 fc = recycle_last_call(string, NULL);
793
794 fc->params->model_details.circ = 1;
795
796 return vrna_eval_structure_v(fc, structure, verbosity_level, NULL);
797 }
798
799
800 PUBLIC float
energy_of_circ_struct_par(const char * string,const char * structure,vrna_param_t * parameters,int verbosity_level)801 energy_of_circ_struct_par(const char *string,
802 const char *structure,
803 vrna_param_t *parameters,
804 int verbosity_level)
805 {
806 vrna_fold_compound_t *fc;
807
808 fc = recycle_last_call(string, parameters);
809
810 fc->params->model_details.circ = 1;
811
812 return vrna_eval_structure_v(fc, structure, verbosity_level, NULL);
813 }
814
815
816 PUBLIC int
loop_energy(short * pt,short * s,short * s1,int i)817 loop_energy(short *pt,
818 short *s,
819 short *s1,
820 int i)
821 {
822 int en, u;
823 char *seq;
824 vrna_md_t md;
825 vrna_fold_compound_t *fc;
826
827 set_model_details(&md);
828
829 /* convert encoded sequence back to actual string */
830 seq = (char *)vrna_alloc(sizeof(char) * (s[0] + 1));
831 for (u = 1; u <= s[0]; u++)
832 seq[u - 1] = vrna_nucleotide_decode(s[u], &md);
833 seq[u - 1] = '\0';
834
835 fc = recycle_last_call(seq, NULL);
836 en = vrna_eval_loop_pt_v(fc, i, pt, eos_debug);
837
838 free(seq);
839
840 return en;
841 }
842
843
844 PUBLIC float
energy_of_move(const char * string,const char * structure,int m1,int m2)845 energy_of_move(const char *string,
846 const char *structure,
847 int m1,
848 int m2)
849 {
850 float en;
851 vrna_fold_compound_t *fc;
852
853 fc = recycle_last_call(string, NULL);
854 en = vrna_eval_move(fc, structure, m1, m2);
855
856 return en;
857 }
858
859
860 PUBLIC int
energy_of_move_pt(short * pt,short * s,short * s1,int m1,int m2)861 energy_of_move_pt(short *pt,
862 short *s,
863 short *s1,
864 int m1,
865 int m2)
866 {
867 int en, u;
868 char *seq;
869 vrna_md_t md;
870 vrna_fold_compound_t *fc;
871
872 set_model_details(&md);
873
874 /* convert encoded sequence back to actual string */
875 seq = (char *)vrna_alloc(sizeof(char) * (s[0] + 1));
876 for (u = 1; u <= s[0]; u++)
877 seq[u - 1] = vrna_nucleotide_decode(s[u], &md);
878 seq[u - 1] = '\0';
879
880 fc = recycle_last_call(seq, NULL);
881 en = vrna_eval_move_pt(fc, pt, m1, m2);
882
883 free(seq);
884
885 return en;
886 }
887
888
889 PRIVATE vrna_param_t *
get_updated_params(vrna_param_t * parameters,int compat)890 get_updated_params(vrna_param_t *parameters,
891 int compat)
892 {
893 vrna_param_t *P = NULL;
894
895 if (parameters) {
896 P = vrna_params_copy(parameters);
897 } else {
898 vrna_md_t md;
899 if (compat)
900 set_model_details(&md);
901 else
902 vrna_md_set_default(&md);
903
904 md.temperature = temperature;
905 P = vrna_params(&md);
906 }
907
908 vrna_md_update(&(P->model_details));
909 return P;
910 }
911
912
913 #endif
914