WSTester updated to work plus hopefully all the other changes that need to go into...
[jabaws.git] / binaries / src / ViennaRNA / Progs / RNAparconv.c
1 /*
2 ###################################
3 # Access to RNAlib routines to    #
4 # convert energy parameter files  #
5 # from ViennaRNAPackage 1.8.4 to  #
6 # 2.0 format                      #
7 #                                 #
8 # Ronny Lorenz                    #
9 ###################################
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <math.h>
15 #include <ctype.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include "utils.h"
19 #include "convert_epars.h"
20 #include "RNAparconv_cmdl.h"
21
22 int main(int argc, char *argv[]){
23   struct  RNAparconv_args_info  args_info;
24   char                          *ifileName, *ofileName;
25   int                           i, silent;
26   unsigned int                  options;
27
28   ifileName = ofileName = NULL;
29   silent    = 0;
30   options   = VRNA_CONVERT_OUTPUT_ALL;
31
32   /*
33   #############################################
34   # check the command line parameters
35   #############################################
36   */
37   if(RNAparconv_cmdline_parser (argc, argv, &args_info) != 0) exit(1);
38
39   /* use input file */
40   if(args_info.input_given)             ifileName = strdup(args_info.input_arg);
41   /* use output file */
42   if(args_info.output_given)            ofileName = strdup(args_info.output_arg);
43   /* output without (special) hairpin energies + enthalpies */
44   if(args_info.without_HairpinE_given)  options &= ~(VRNA_CONVERT_OUTPUT_HP
45                                                     |VRNA_CONVERT_OUTPUT_SPECIAL_HP);
46   /* output without stacking energies + enthalpies */
47   if(args_info.without_StackE_given)    options &= ~VRNA_CONVERT_OUTPUT_STACK;
48   /* output without 5' dangle energies + enthalpies */
49   if(args_info.without_Dangle5_given)   options &= ~VRNA_CONVERT_OUTPUT_DANGLE5;
50   /* output without 3' dangle energies + enthalpies */
51   if(args_info.without_Dangle3_given)   options &= ~VRNA_CONVERT_OUTPUT_DANGLE3;
52   /* output without interior loop energies + enthalpies */
53   if(args_info.without_IntE_given)      options &= ~(VRNA_CONVERT_OUTPUT_NINIO
54                                                     |VRNA_CONVERT_OUTPUT_INT
55                                                     |VRNA_CONVERT_OUTPUT_INT_11
56                                                     |VRNA_CONVERT_OUTPUT_INT_21
57                                                     |VRNA_CONVERT_OUTPUT_INT_22);
58   /* output without bulge loop energies + enthalpies */
59   if(args_info.without_BulgeE_given)    options &= ~VRNA_CONVERT_OUTPUT_BULGE;
60   /* output without multi loop energies + enthalpies */
61   if(args_info.without_MultiE_given)    options &= ~VRNA_CONVERT_OUTPUT_ML;
62   /* output without misc energies + enthalpies */
63   if(args_info.without_Misc_given)      options &= ~VRNA_CONVERT_OUTPUT_MISC;
64   /* output without hairpin mismatch energies + enthalpies */
65   if(args_info.without_MismatchH_given) options &= ~VRNA_CONVERT_OUTPUT_MM_HP;
66   /* output without interior loop mismatch energies + enthalpies */
67   if(args_info.without_MismatchI_given) options &= ~(VRNA_CONVERT_OUTPUT_MM_INT
68                                                     |VRNA_CONVERT_OUTPUT_MM_INT_1N
69                                                     |VRNA_CONVERT_OUTPUT_MM_INT_23);
70   /* output without multi loop mismatch energies + enthalpies */
71   if(args_info.without_MismatchM_given) options &= ~VRNA_CONVERT_OUTPUT_MM_MULTI;
72   /* output without exterior loop mismatch energies + enthalpies */
73   if(args_info.without_MismatchE_given) options &= ~VRNA_CONVERT_OUTPUT_MM_EXT;
74
75   /* output given energy parameters only */
76   if(args_info.vanilla_given)           options |= VRNA_CONVERT_OUTPUT_VANILLA;
77
78   /* just dump Vienna 1.8.4 parameters in new format */
79   if(args_info.dump_given)              options |= VRNA_CONVERT_OUTPUT_DUMP;
80
81   /* file names given as unnamed option? */
82   for(i = 0; i < args_info.inputs_num; i++){
83     if(ifileName == NULL)       ifileName = strdup(args_info.inputs[i]);
84     else if(ofileName == NULL)  ofileName = strdup(args_info.inputs[i]);
85     else{
86       RNAparconv_cmdline_parser_print_help();
87       nrerror("unrecognized or too many parameter options given!");
88     }
89   }
90
91   /* be silent */
92   if(args_info.silent_given) silent = 1;
93
94   /* free allocated memory of command line data structure */
95   RNAparconv_cmdline_parser_free (&args_info);
96
97   /*
98   #############################################
99   # do something
100   #############################################
101   */
102
103   if(ifileName == NULL)
104     if(!(silent || (options & VRNA_CONVERT_OUTPUT_DUMP)))
105       fprintf(stdout, "Enter parameters:\n(Indicate last line of input parameters by typing \"# END\" or EOF\n\n");
106
107   convert_parameter_file(ifileName, ofileName, options);
108
109   return EXIT_SUCCESS;
110 }
111