1
2/* deactivate ANSI colors in TTY output if we compile for windows */
3#ifndef VRNA_WITHOUT_TTY_COLORS
4# ifdef _WIN32
5#   define VRNA_WITHOUT_TTY_COLORS
6# endif
7#endif
8
9#ifndef INLINE
10# ifdef __GNUC__
11#   define INLINE inline
12# else
13#   define INLINE
14# endif
15#endif
16
17#ifndef VRNA_WITHOUT_TTY_COLORS
18
19#define ANSI_COLOR_BRIGHT     "\x1b[1m"
20#define ANSI_COLOR_UNDERLINE  "\x1b[4m"
21#define ANSI_COLOR_RED        "\x1b[31m"
22#define ANSI_COLOR_GREEN      "\x1b[32m"
23#define ANSI_COLOR_YELLOW     "\x1b[33m"
24#define ANSI_COLOR_BLUE       "\x1b[34m"
25#define ANSI_COLOR_MAGENTA    "\x1b[35m"
26#define ANSI_COLOR_CYAN       "\x1b[36m"
27#define ANSI_COLOR_RED_B      "\x1b[1;31m"
28#define ANSI_COLOR_GREEN_B    "\x1b[1;32m"
29#define ANSI_COLOR_YELLOW_B   "\x1b[1;33m"
30#define ANSI_COLOR_BLUE_B     "\x1b[1;34m"
31#define ANSI_COLOR_MAGENTA_B  "\x1b[1;35m"
32#define ANSI_COLOR_CYAN_B     "\x1b[1;36m"
33#define ANSI_COLOR_RESET      "\x1b[0m"
34
35static INLINE void
36print_fasta_header( FILE *fp,
37                    const char *head){
38
39  if(head){
40    if(isatty(fileno(fp))){
41      fprintf(fp, ANSI_COLOR_YELLOW ">%s" ANSI_COLOR_RESET "\n", head);
42    } else {
43      fprintf(fp, ">%s\n", head);
44    }
45  }
46}
47
48static INLINE void
49print_structure(FILE *fp,
50                const char *structure,
51                const char *data){
52
53  if(structure){
54    if(data){
55      if(isatty(fileno(fp))){
56        fprintf(fp, "%s" ANSI_COLOR_GREEN "%s" ANSI_COLOR_RESET "\n", structure, data);
57      } else {
58        fprintf(fp, "%s%s\n", structure, data);
59      }
60    } else {
61      fprintf(fp, "%s\n", structure);
62    }
63  } else {
64    if(data){
65      if(isatty(fileno(fp))){
66        fprintf(fp, ANSI_COLOR_GREEN "%s" ANSI_COLOR_RESET "\n", data);
67      } else {
68        fprintf(fp, "%s\n", data);
69      }
70    }
71  }
72}
73
74
75static INLINE void
76print_eval_sd_corr(FILE *fp){
77
78  if(isatty(fileno(fp))){
79    fprintf(fp, ANSI_COLOR_BRIGHT "Correcting for presence of structured domains" ANSI_COLOR_RESET "\n");
80  } else {
81    fprintf(fp, "Correcting for presence of structured domains\n");
82  }
83}
84
85
86static INLINE void
87print_eval_ext_loop(FILE  *fp,
88                    int   energy){
89
90  if(isatty(fileno(fp))){
91    fprintf(fp, ANSI_COLOR_CYAN "External loop" ANSI_COLOR_RESET
92                "                           : "
93                ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n", energy);
94  } else {
95    fprintf(fp, "External loop"
96                "                           : "
97                "%5d\n", energy);
98  }
99}
100
101static INLINE void
102print_eval_hp_loop( FILE  *fp,
103                    int   i,
104                    int   j,
105                    char  si,
106                    char  sj,
107                    int   energy){
108
109  if(isatty(fileno(fp))){
110    fprintf(fp, ANSI_COLOR_CYAN "Hairpin  loop" ANSI_COLOR_RESET
111                " (%3d,%3d) "
112                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
113                "              : "
114                ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
115                i, j,
116                si, sj,
117                energy);
118  } else {
119    fprintf(fp, "Hairpin  loop"
120                " (%3d,%3d) %c%c              : "
121                "%5d\n",
122                i, j,
123                si, sj,
124                energy);
125  }
126}
127
128
129static INLINE void
130print_eval_hp_loop_revert(FILE  *fp,
131                          int   i,
132                          int   j,
133                          char  si,
134                          char  sj,
135                          int   energy){
136
137  if(isatty(fileno(fp))){
138    fprintf(fp, ANSI_COLOR_MAGENTA "Hairpin  loop" ANSI_COLOR_RESET
139                " (%3d,%3d) "
140                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
141                "              : "
142                ANSI_COLOR_RED "%5d" ANSI_COLOR_RESET "\n",
143                i, j,
144                si, sj,
145                -energy);
146  } else {
147    fprintf(fp, "Hairpin  loop"
148                " (%3d,%3d) %c%c              : "
149                "%5d\n",
150                i, j,
151                si, sj,
152                -energy);
153  }
154}
155
156
157static INLINE void
158print_eval_int_loop(FILE  *fp,
159                    int   i,
160                    int   j,
161                    char  si,
162                    char  sj,
163                    int   k,
164                    int   l,
165                    char  sk,
166                    char  sl,
167                    int   energy){
168
169  if(isatty(fileno(fp))){
170    fprintf(fp, ANSI_COLOR_CYAN "Interior loop" ANSI_COLOR_RESET
171                " (%3d,%3d) "
172                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
173                "; (%3d,%3d) "
174                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
175                ": "
176                ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
177                i, j,
178                si, sj,
179                k, l,
180                sk, sl,
181                energy);
182  } else {
183    fprintf(fp, "Interior loop"
184                " (%3d,%3d) "
185                "%c%c"
186                "; (%3d,%3d) "
187                "%c%c"
188                ": "
189                "%5d\n",
190                i, j,
191                si, sj,
192                k, l,
193                sk, sl,
194                energy);
195  }
196}
197
198
199static INLINE void
200print_eval_int_loop_revert(FILE  *fp,
201                          int   i,
202                          int   j,
203                          char  si,
204                          char  sj,
205                          int   k,
206                          int   l,
207                          char  sk,
208                          char  sl,
209                          int   energy){
210
211  if(isatty(fileno(fp))){
212    fprintf(fp, ANSI_COLOR_MAGENTA "Interior loop" ANSI_COLOR_RESET
213                " (%3d,%3d) "
214                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
215                "; (%3d,%3d) "
216                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
217                ": "
218                ANSI_COLOR_RED "%5d" ANSI_COLOR_RESET "\n",
219                i, j,
220                si, sj,
221                k, l,
222                sk, sl,
223                -energy);
224  } else {
225    fprintf(fp, "Interior loop"
226                " (%3d,%3d) "
227                "%c%c"
228                "; (%3d,%3d) "
229                "%c%c"
230                ": "
231                "%5d\n",
232                i, j,
233                si, sj,
234                k, l,
235                sk, sl,
236                -energy);
237  }
238}
239
240
241static INLINE void
242print_eval_mb_loop( FILE  *fp,
243                    int   i,
244                    int   j,
245                    char  si,
246                    char  sj,
247                    int   energy){
248
249  if(isatty(fileno(fp))){
250    fprintf(fp, ANSI_COLOR_CYAN "Multi    loop" ANSI_COLOR_RESET
251                " (%3d,%3d) "
252                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
253                "              : "
254                ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
255                i, j,
256                si, sj,
257                energy);
258  } else {
259    fprintf(fp, "Multi    loop"
260                " (%3d,%3d) %c%c              : "
261                "%5d\n",
262                i, j,
263                si, sj,
264                energy);
265  }
266}
267
268
269static INLINE void
270print_eval_mb_loop_revert(FILE  *fp,
271                          int   i,
272                          int   j,
273                          char  si,
274                          char  sj,
275                          int   energy){
276
277  if(isatty(fileno(fp))){
278    fprintf(fp, ANSI_COLOR_MAGENTA "Multi    loop" ANSI_COLOR_RESET
279                " (%3d,%3d) "
280                ANSI_COLOR_BRIGHT "%c%c" ANSI_COLOR_RESET
281                "              : "
282                ANSI_COLOR_RED "%5d" ANSI_COLOR_RESET "\n",
283                i, j,
284                si, sj,
285                -energy);
286  } else {
287    fprintf(fp, "Multi    loop"
288                " (%3d,%3d) %c%c              : "
289                "%5d\n",
290                i, j,
291                si, sj,
292                -energy);
293  }
294}
295
296
297static INLINE void
298print_eval_gquad(FILE  *fp,
299                 int   i,
300                 int   L,
301                 int   l[3],
302                 int   energy){
303
304  if(isatty(fileno(fp))){
305    fprintf(fp, ANSI_COLOR_CYAN "G-Quadruplex " ANSI_COLOR_RESET
306              " (%3d,%3d) "
307              ANSI_COLOR_BRIGHT "L%d  " ANSI_COLOR_RESET
308              "(%2d,%2d,%2d)  : "
309              ANSI_COLOR_GREEN "%5d" ANSI_COLOR_RESET "\n",
310              i, i + 4*L + l[0] + l[1] + l[2] - 1,
311              L, l[0], l[1], l[2],
312              energy);
313  } else {
314    fprintf(fp, "G-Quadruplex "
315              " (%3d,%3d) "
316              "L%d  "
317              "(%2d,%2d,%2d)  : "
318              "%5d\n",
319              i, i + 4*L + l[0] + l[1] + l[2] - 1,
320              L, l[0], l[1], l[2],
321              energy);
322  }
323}
324
325
326static INLINE void
327print_table(FILE *fp,
328            const char *head,
329            const char *line){
330
331  if(head){
332    if(isatty(fileno(fp))){
333      fprintf(fp, ANSI_COLOR_UNDERLINE ANSI_COLOR_BRIGHT "%s" ANSI_COLOR_RESET "\n", head);
334    } else {
335      fprintf(fp, "%s\n", head);
336    }
337  }
338  if(line){
339    if(isatty(fileno(fp))){
340      fprintf(fp, ANSI_COLOR_GREEN "%s" ANSI_COLOR_RESET "\n", line);
341    } else {
342      fprintf(fp, "%s\n", line);
343    }
344  }
345}
346
347static INLINE void
348print_comment(FILE *fp,
349              const char *line){
350
351  if(line){
352    if(isatty(fileno(fp))){
353      fprintf(fp, ANSI_COLOR_CYAN "%s" ANSI_COLOR_RESET "\n", line);
354    } else {
355      fprintf(fp, "%s\n", line);
356    }
357  }
358}
359
360#else
361
362static INLINE void
363print_fasta_header( FILE *fp,
364                    const char *head){
365
366  if(head){
367    fprintf(fp, ">%s\n", head);
368  }
369}
370
371static INLINE void
372print_structure(FILE *fp,
373                const char *structure,
374                const char *data){
375
376  if(structure){
377    if(data){
378      fprintf(fp, "%s%s\n", structure, data);
379    } else {
380      fprintf(fp, "%s\n", structure);
381    }
382  } else {
383    if(data){
384      fprintf(fp, "%s\n", data);
385    }
386  }
387}
388
389
390static INLINE void
391print_eval_sd_corr(FILE *fp){
392
393  fprintf(fp, "Correcting for presence of structured domains\n");
394}
395
396
397static INLINE void
398print_eval_ext_loop(FILE  *fp,
399                    int   energy){
400
401  fprintf(fp, "External loop"
402              "                           : "
403              "%5d\n", energy);
404}
405
406
407static INLINE void
408print_eval_hp_loop( FILE  *fp,
409                    int   i,
410                    int   j,
411                    char  si,
412                    char  sj,
413                    int   energy){
414
415  fprintf(fp, "Hairpin  loop"
416              " (%3d,%3d) %c%c              : "
417              "%5d\n",
418              i, j,
419              si, sj,
420              energy);
421}
422
423
424static INLINE void
425print_eval_hp_loop_revert( FILE  *fp,
426                    int   i,
427                    int   j,
428                    char  si,
429                    char  sj,
430                    int   energy){
431
432  print_eval_hp_loop(fp, i, j, si, sj, -energy);
433}
434
435
436static INLINE void
437print_eval_int_loop(FILE  *fp,
438                    int   i,
439                    int   j,
440                    char  si,
441                    char  sj,
442                    int   k,
443                    int   l,
444                    char  sk,
445                    char  sl,
446                    int   energy){
447
448  fprintf(fp, "Interior loop"
449              " (%3d,%3d) "
450              "%c%c"
451              "; (%3d,%3d) "
452              "%c%c"
453              ": "
454              "%5d\n",
455              i, j,
456              si, sj,
457              k, l,
458              sk, sl,
459              energy);
460}
461
462
463static INLINE void
464print_eval_int_loop_revert(FILE  *fp,
465                    int   i,
466                    int   j,
467                    char  si,
468                    char  sj,
469                    int   k,
470                    int   l,
471                    char  sk,
472                    char  sl,
473                    int   energy){
474
475  print_eval_int_loop(fp, i, j, si, sj, k, l, sk, sl, -energy);
476}
477
478
479static INLINE void
480print_eval_mb_loop( FILE  *fp,
481                    int   i,
482                    int   j,
483                    char  si,
484                    char  sj,
485                    int   energy){
486
487  fprintf(fp, "Multi    loop"
488              " (%3d,%3d) %c%c              : "
489              "%5d\n",
490              i, j,
491              si, sj,
492              energy);
493}
494
495
496static INLINE void
497print_eval_mb_loop_revert( FILE  *fp,
498                    int   i,
499                    int   j,
500                    char  si,
501                    char  sj,
502                    int   energy){
503
504  print_eval_mb_loop(fp, i, j, si, sj, -energy);
505}
506
507
508static INLINE void
509print_eval_gquad(FILE  *fp,
510                 int   i,
511                 int   L,
512                 int   l[3],
513                 int   energy){
514
515  fprintf(fp, "G-Quadruplex "
516              " (%3d,%3d) "
517              "L%d  "
518              "(%2d,%2d,%2d)  : "
519              "%5d\n",
520              i, i + 4*L + l[0] + l[1] + l[2] - 1,
521              L, l[0], l[1], l[2],
522              energy);
523}
524
525
526static INLINE void
527print_table(FILE *fp,
528            const char *head,
529            const char *line){
530
531  if(head){
532    fprintf(fp, "%s\n", head);
533  }
534  if(line){
535    fprintf(fp, "%s\n", line);
536  }
537}
538
539static INLINE void
540print_comment(FILE *fp,
541              const char *line){
542
543  if(line){
544    fprintf(fp, "%s\n", line);
545  }
546}
547
548#endif
549
550