1 /* Last changed Time-stamp: <2003-04-23 11:56:44 ivo> */
3 Ineractive Access to folding Routines
15 #include "fold_vars.h"
17 #include "read_epars.h"
19 #include "RNALfold_cmdl.h"
22 static char rcsid[] = "$Id: RNALfold.c,v 1.2 2003/07/14 13:38:47 ivo Exp $";
24 int main(int argc, char *argv[]){
25 struct RNALfold_args_info args_info;
26 char *input_string, *c, *string, *structure, *ParamFile, *ns_bases, *rec_sequence, *rec_id, **rec_rest, *orig_sequence;
27 int i, length, l, sym, r, istty, noconv, maxdist, zsc;
28 double energy, min_en, min_z;
29 unsigned int input_type;
30 unsigned int rec_type, read_opt;
32 string = structure = ParamFile = ns_bases = NULL;
40 rec_type = read_opt = 0;
41 rec_id = rec_sequence = orig_sequence = NULL;
45 #############################################
46 # check the command line parameters
47 #############################################
49 if(RNALfold_cmdline_parser (argc, argv, &args_info) != 0) exit(1);
51 if(args_info.temp_given) temperature = args_info.temp_arg;
52 /* do not take special tetra loop energies into account */
53 if(args_info.noTetra_given) tetra_loop=0;
54 /* set dangle model */
55 if(args_info.dangles_given){
56 if((args_info.dangles_arg < 0) || (args_info.dangles_arg > 3))
57 warn_user("required dangle model not implemented, falling back to default dangles=2");
59 dangles = args_info.dangles_arg;
61 /* do not allow weak pairs */
62 if(args_info.noLP_given) noLonelyPairs = 1;
63 /* do not allow wobble pairs (GU) */
64 if(args_info.noGU_given) noGU = 1;
65 /* do not allow weak closing pairs (AU,GU) */
66 if(args_info.noClosingGU_given) no_closingGU = 1;
67 /* do not convert DNA nucleotide "T" to appropriate RNA "U" */
68 if(args_info.noconv_given) noconv = 1;
69 /* set energy model */
70 if(args_info.energyModel_given) energy_set = args_info.energyModel_arg;
71 /* take another energy parameter set */
72 if(args_info.paramFile_given) ParamFile = strdup(args_info.paramFile_arg);
73 /* Allow other pairs in addition to the usual AU,GC,and GU pairs */
74 if(args_info.nsp_given) ns_bases = strdup(args_info.nsp_arg);
75 /* set the maximum base pair span */
76 if(args_info.span_given) maxdist = args_info.span_arg;
77 if(args_info.zscore_given){
80 if(args_info.zscore_arg != -2)
81 min_z = args_info.zscore_arg;
83 nrerror("\'z\' option is available only if compiled with SVM support!");
86 /* gquadruplex support */
87 if(args_info.gquad_given) gquad = 1;
89 /* check for errorneous parameter options */
91 RNALfold_cmdline_parser_print_help();
95 /* free allocated memory of command line data structure */
96 RNALfold_cmdline_parser_free (&args_info);
99 #############################################
101 #############################################
103 if (ParamFile != NULL)
104 read_parameter_file(ParamFile);
106 if (ns_bases != NULL) {
107 nonstandards = space(33);
115 nonstandards[i++]=*c++;
116 nonstandards[i++]=*c;
117 if ((sym)&&(*c!=*(c-1))) {
118 nonstandards[i++]=*c;
119 nonstandards[i++]=*(c-1);
126 istty = isatty(fileno(stdout))&&isatty(fileno(stdin));
127 read_opt |= VRNA_INPUT_NO_REST;
129 print_tty_input_seq();
130 read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES;
133 #############################################
134 # main loop: continue until end of file
135 #############################################
138 !((rec_type = read_record(&rec_id, &rec_sequence, &rec_rest, read_opt))
139 & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){
142 ########################################################
143 # init everything according to the data we've read
144 ########################################################
146 if(rec_id && !istty) printf("%s\n", rec_id);
148 length = (int)strlen(rec_sequence);
150 /* convert DNA alphabet to RNA if not explicitely switched off */
151 if(!noconv) str_DNA2RNA(rec_sequence);
152 /* store case-unmodified sequence */
153 orig_sequence = strdup(rec_sequence);
154 /* convert sequence to uppercase letters only */
155 str_uppercase(rec_sequence);
157 if(istty) printf("length = %d\n", length);
159 ########################################################
160 # done with 'stdin' handling
161 ########################################################
164 min_en = (zsc) ? Lfoldz((const char *)rec_sequence, NULL, maxdist, zsc, min_z) : Lfold((const char *)rec_sequence, NULL, maxdist);
165 printf("%s\n", orig_sequence);
168 printf("\n minimum free energy = %6.2f kcal/mol\n", min_en);
170 printf(" (%6.2f)\n", min_en);
172 (void) fflush(stdout);
175 if(rec_id) free(rec_id);
178 rec_id = rec_sequence = orig_sequence = NULL;
180 /* print user help for the next round if we get input from tty */
182 if(istty) print_tty_input_seq();