/* Last changed Time-stamp: <2005-09-22 10:10:55 ivo> */ /* Ineractive Access to folding Routines c Ivo L Hofacker Vienna RNA package */ #include #include #include #include #include #include #include "fold.h" #include "part_func.h" #include "fold_vars.h" #include "PS_dot.h" #include "utils.h" extern void read_parameter_file(const char fname[]); extern float circfold(const char *string, char *structure); /*@unused@*/ static char rcsid[] = "$Id: RNAfold.c,v 1.18 2005/10/30 20:07:12 ivo Exp $"; #define PRIVATE static static char scale1[] = "....,....1....,....2....,....3....,....4"; static char scale2[] = "....,....5....,....6....,....7....,....8"; PRIVATE void usage(void); /*--------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char *string, *line; char *structure=NULL, *cstruc=NULL; char fname[13], ffname[20], gfname[20]; char *ParamFile=NULL; char *ns_bases=NULL, *c; int i, length, l, sym, r; double energy, min_en; double kT, sfact=1.07; int pf=0, istty; int noconv=0; int circ=0; do_backtrack = 1; string=NULL; for (i=1; i : base i is paired with a base j>i\n"); printf("matching brackets ( ): base i pairs base j\n"); } do { /* main loop: continue until end of file */ if (istty) { printf("\nInput string (upper or lower case); @ to quit\n"); printf("%s%s\n", scale1, scale2); } fname[0]='\0'; if ((line = get_line(stdin))==NULL) break; /* skip comment lines and get filenames */ while ((*line=='*')||(*line=='\0')||(*line=='>')) { if (*line=='>') (void) sscanf(line, ">%12s", fname); printf("%s\n", line); free(line); if ((line = get_line(stdin))==NULL) break; } if ((line ==NULL) || (strcmp(line, "@") == 0)) break; string = (char *) space(strlen(line)+1); (void) sscanf(line,"%s",string); free(line); length = (int) strlen(string); structure = (char *) space((unsigned) length+1); if (fold_constrained) { cstruc = get_line(stdin); if (cstruc!=NULL) strncpy(structure, cstruc, length); else fprintf(stderr, "constraints missing\n"); } for (l = 0; l < length; l++) { string[l] = toupper(string[l]); if (!noconv && string[l] == 'T') string[l] = 'U'; } if (istty) printf("length = %d\n", length); /* initialize_fold(length); */ if (circ) min_en = circfold(string, structure); else min_en = fold(string, structure); printf("%s\n%s", string, structure); if (istty) printf("\n minimum free energy = %6.2f kcal/mol\n", min_en); else printf(" (%6.2f)\n", min_en); (void) fflush(stdout); if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_ss.ps"); strcpy(gfname, fname); strcat(gfname, "_ss.g"); } else { strcpy(ffname, "rna.ps"); strcpy(gfname, "rna.g"); } if (length<2000) (void) PS_rna_plot(string, structure, ffname); else { struct bond *bp; fprintf(stderr,"INFO: structure too long, not doing xy_plot\n"); /* free mfe arrays but preserve base_pair for PS_dot_plot */ bp = base_pair; base_pair = space(16); free_arrays(); /* free's base_pair */ base_pair = bp; } if (pf) { if (circ) nrerror("Currently no partition function for circular RNAs. Please implement it!"); if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = energy_of_struct(string, structure); dangles=1; } kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(sfact*min_en)/kT/length); if (length>2000) fprintf(stderr, "scaling factor %f\n", pf_scale); init_pf_fold(length); if (cstruc!=NULL) strncpy(structure, cstruc, length+1); energy = pf_fold(string, structure); if (do_backtrack) { printf("%s", structure); if (!istty) printf(" [%6.2f]\n", energy); else printf("\n"); } if ((istty)||(!do_backtrack)) printf(" free energy of ensemble = %6.2f kcal/mol\n", energy); printf(" frequency of mfe structure in ensemble %g; ", exp((energy-min_en)/kT)); if (do_backtrack) { printf("ensemble diversity %-6.2f", mean_bp_dist(length)); if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_dp.ps"); } else strcpy(ffname, "dot.ps"); (void) PS_dot_plot(string, ffname); } printf("\n"); free_pf_arrays(); } if (cstruc!=NULL) free(cstruc); if (length>=2000) free(base_pair); (void) fflush(stdout); free(string); free(structure); } while (1); return 0; } PRIVATE void usage(void) { nrerror("usage:\n" "RNAfold [-p[0]] [-C] [-T temp] [-4] [-d[2|3]] [-noGU] [-noCloseGU]\n" " [-noLP] [-e e_set] [-P paramfile] [-nsp pairs] [-S scale]\n" " [-noconv] [-circ] \n"); }