int main(int argc, char *argv[]) { char *line; char *sequence; char *structure = NULL; char fname[21]; char *ParamFile = NULL; char *ns_bases = NULL, *c; int i, length, l, sym, r; int istty; double deltaf, deltap=0; int delta=100; int n_back = 0; int noconv = 0; int circ=0; int dos=0; int zuker=0; do_backtrack = 1; dangles = 2; for (i=1; i<argc; i++) { if (argv[i][0]=='-') switch ( argv[i][1] ) { case 'T': if (argv[i][2]!='\0') usage(); if(i==argc-1) usage(); r=sscanf(argv[++i], "%lf", &temperature); if (r!=1) usage(); break; case 'p': if (argv[i][2]!='\0') usage(); if(i==argc-1) usage(); (void) sscanf(argv[++i], "%d", &n_back); init_rand(); break; case 'n': if ( strcmp(argv[i], "-noGU" )==0) noGU=1; if ( strcmp(argv[i], "-noCloseGU" ) ==0) no_closingGU=1; if ( strcmp(argv[i], "-noLP")==0) noLonelyPairs=1; if ( strcmp(argv[i], "-nsp") ==0) { if (i==argc-1) usage(); ns_bases = argv[++i]; } if ( strcmp(argv[i], "-noconv")==0) noconv=1; break; case '4': tetra_loop=0; break; case 'C': fold_constrained=1; break; case 'D': dos=1; print_energy = -999999; break; case 'd': dangles=0; if (argv[i][2]!='\0') { r=sscanf(argv[i]+2, "%d", &dangles); if (r!=1) usage(); } break; case 'P': if (i==argc-1) usage(); ParamFile = argv[++i]; break; case 's': subopt_sorted=1; break; case 'l': if (strcmp(argv[i],"-logML")==0) { logML=1; break; } else usage(); break; case 'e': if (i>=argc-1) usage(); if (strcmp(argv[i],"-ep")==0) r=sscanf(argv[++i], "%lf", &deltap); else { r=sscanf(argv[++i], "%lf", &deltaf); delta = (int) (0.1+deltaf*100); } if (r!=1) usage(); break; case 'c': if ( strcmp(argv[i], "-circ")==0) circ=1; break; case 'z': zuker=1; break; default: usage(); } } if ((zuker)&&(circ)) { printf("Sorry, zuker subopts not yet implemented for circfold\n"); usage(); } if ((zuker)&&(n_back>0)) { printf("Cna't do zuker subopts and stochastic subopts at the same time\n"); usage(); } if (ParamFile != NULL) read_parameter_file(ParamFile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c) { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } istty = isatty(fileno(stdout))&&isatty(fileno(stdin)); if ((fold_constrained)&&(istty)) { printf("Input constraints using the following notation:\n"); /* printf("| : paired with another base\n"); */ printf(". : no constraint at all\n"); printf("x : base must not pair\n"); } do { /* main loop: continue until end of file */ cut_point = -1; if (istty) { printf("\nInput string (upper or lower case); @ to quit\n"); if (!zuker)printf("Use '&' to connect 2 sequences that shall form a complex.\n"); printf("%s\n", scale); } 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, ">%20s", fname); free(line); if ((line = get_line(stdin))==NULL) break;; } if ((line==NULL)||strcmp(line,"@")==0) break; sequence = tokenize(line); /* frees line */ length = (int) strlen(sequence); structure = (char *) space((unsigned) length+1); if (fold_constrained) { char *cstruc; cstruc = tokenize(get_line(stdin)); if (cstruc!=NULL) { strncpy(structure, cstruc, length); for (i=0; i<length; i++) if (structure[i]=='|') nrerror("constraints of type '|' not allowed"); free(cstruc); } } for (l = 0; l < length; l++) { sequence[l] = toupper(sequence[l]); if (!noconv && sequence[l] == 'T') sequence[l] = 'U'; } if (istty) { if (cut_point == -1) printf("length = %d\n", length); else printf("length1 = %d\nlength2 = %d\n", cut_point-1, length-cut_point+1); } if ((logML!=0 || dangles==1 || dangles==3) && dos==0) if (deltap<=0) deltap=delta/100. +0.001; if (deltap>0) print_energy = deltap; /* first lines of output (suitable for sort +1n) */ if (fname[0] != '\0') printf("> %s [%d]\n", fname, delta); if (n_back>0) { /* stochastic backtrack */ double mfe, kT; char *ss; st_back=1; ss = (char *) space(strlen(sequence)+1); strncpy(ss, structure, length); mfe = fold(sequence, ss); kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(1.03*mfe)/kT/length); strncpy(ss, structure, length); /* ignore return value, we are not interested in the free energy */ (circ) ? (void) pf_circ_fold(sequence, ss) : (void) pf_fold(sequence, ss); free(ss); for (i=0; i<n_back; i++) { char *s; s =(circ) ? pbacktrack_circ(sequence) : pbacktrack(sequence); printf("%s\n", s); free(s); } free_pf_arrays(); } else if (!zuker) { /* normal subopt */ (circ) ? subopt_circ(sequence, structure, delta, stdout) : subopt(sequence, structure, delta, stdout); if (dos) { int i; for (i=0; i<= MAXDOS && i<=delta/10; i++) { printf("%4d %6d\n", i, density_of_states[i]); } } } else { /* Zuker suboptimals */ SOLUTION *zr; int i; if (cut_point!=-1) { printf("Sorry, zuker subopts not yet implemented for cofold\n"); usage(); } zr = zukersubopt(sequence); putoutzuker(zr); (void)fflush(stdout); for (i=0; zr[i].structure; i++) { free(zr[i].structure); } free(zr); } (void)fflush(stdout); free(sequence); free(structure); } while (1); return 0; }
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, noPS=0, istty; int noconv=0; int circ=0; AjPSeq seq = NULL; AjPFile confile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPFile essfile = NULL; AjPFile dotfilea = NULL; AjPFile dotfileb = NULL; AjPStr seqstring = NULL; AjPStr constring = NULL; AjPStr seqname = NULL; float eT = 0.; AjBool eGU; AjBool ecirc = ajFalse; AjBool eclose; AjBool lonely; AjBool convert; AjPStr ensbases = NULL; AjBool etloop; AjPStr eenergy = NULL; char ewt = '\0'; float escale = 0.; AjPStr edangles = NULL; char edangle = '\0'; ajint len; embInitPV("vrnafold",argc,argv,"VIENNA",VERSION); seqstring = ajStrNew(); constring = ajStrNew(); seqname = ajStrNew(); seq = ajAcdGetSeq("sequence"); confile = ajAcdGetInfile("constraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); ecirc = ajAcdGetBoolean("circular"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); convert = ajAcdGetBoolean("convert"); ensbases = ajAcdGetString("nsbases"); etloop = ajAcdGetBoolean("tetraloop"); eenergy = ajAcdGetListSingle("energy"); escale = ajAcdGetFloat("scale"); edangles = ajAcdGetListSingle("dangles"); outf = ajAcdGetOutfile("outfile"); essfile = ajAcdGetOutfile("ssoutfile"); /* dotfilea = ajAcdGetOutfile("adotoutfile"); dotfileb = ajAcdGetOutfile("bdotoutfile"); */ do_backtrack = 2; pf = 0; string = NULL; istty = 0; temperature = (double) eT; circ = !!ecirc; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; noconv = (convert) ? 0 : 1; ns_bases = (ajStrGetLen(ensbases)) ? MAJSTRGETPTR(ensbases) : NULL; tetra_loop = !!etloop; ewt = *ajStrGetPtr(eenergy); if(ewt == '0') energy_set = 0; else if(ewt == '1') energy_set = 1; else if(ewt == '2') energy_set = 2; sfact = (double) escale; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(circ && noLonelyPairs) { ajWarn("Depending on the origin of the circular sequence\n" "some structures may be missed when using -noLP\nTry " "rotating your sequence a few times\n"); } if(paramfile) read_parameter_file(paramfile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } if(confile) vienna_GetConstraints(confile,&constring); string = NULL; structure = NULL; length = ajSeqGetLen(seq); string = (char *) space(length+1); strcpy(string,ajSeqGetSeqC(seq)); len = ajStrGetLen(constring); structure = (char *) space(length+1); if(len) { fold_constrained = 1; strcpy(structure,ajStrGetPtr(constring)); } for (l = 0; l < length; l++) { string[l] = toupper(string[l]); if (!noconv && string[l] == 'T') string[l] = 'U'; } /* initialize_fold(length); */ if (circ) min_en = circfold(string, structure); else min_en = fold(string, structure); ajFmtPrintF(outf,"%s\n%s", string, structure); if (istty) printf("\n minimum free energy = %6.2f kcal/mol\n", min_en); else ajFmtPrintF(outf," (%6.2f)\n", min_en); if (!noPS) { if (length<2000) (void) PS_rna_plot(string, structure, essfile); else ajWarn("Structure too long, not doing xy_plot\n"); } if (length>=2000) free_arrays(); if (pf) { char *pf_struc; pf_struc = (char *) space((unsigned) length+1); if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = (circ) ? energy_of_circ_struct(string, structure) : 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) ajWarn("scaling factor %f\n", pf_scale); (circ) ? init_pf_circ_fold(length) : init_pf_fold(length); if (cstruc!=NULL) strncpy(pf_struc, cstruc, length+1); energy = (circ) ? pf_circ_fold(string, pf_struc) : pf_fold(string, pf_struc); if (do_backtrack) { ajFmtPrintF(outf,"%s", pf_struc); ajFmtPrintF(outf," [%6.2f]\n", energy); } if ((istty)||(!do_backtrack)) ajFmtPrintF(outf," free energy of ensemble = %6.2f kcal/mol\n", energy); if (do_backtrack) { plist *pl1,*pl2; char *cent; double dist, cent_en; cent = centroid(length, &dist); cent_en = (circ) ? energy_of_circ_struct(string, cent) : energy_of_struct(string, cent); ajFmtPrintF(outf,"%s {%6.2f d=%.2f}\n", cent, cent_en, dist); free(cent); pl1 = make_plist(length, 1e-5); pl2 = b2plist(structure); (void) PS_dot_plot_list(string, dotfilea, pl1, pl2, ""); free(pl2); if (do_backtrack==2) { pl2 = stackProb(1e-5); PS_dot_plot_list(string, dotfileb, pl1, pl2, "Probabilities for stacked pairs (i,j)(i+1,j-1)"); free(pl2); } free(pl1); free(pf_struc); } ajFmtPrintF(outf," frequency of mfe structure in ensemble %g; ", exp((energy-min_en)/kT)); if (do_backtrack) ajFmtPrintF(outf,"ensemble diversity %-6.2f", mean_bp_dist(length)); ajFmtPrintF(outf,"\n"); free_pf_arrays(); } if (cstruc!=NULL) free(cstruc); free(string); free(structure); ajStrDel(&seqstring); ajStrDel(&constring); ajStrDel(&seqname); ajStrDel(&ensbases); ajStrDel(&eenergy); ajStrDel(&edangles); ajSeqDel(&seq); ajFileClose(&confile); ajFileClose(¶mfile); ajFileClose(&outf); ajFileClose(&essfile); /* ajFileClose(&dotfilea); ajFileClose(&dotfileb); */ if (length<2000) free_arrays(); embExit(); return 0; }
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, noPS=0, istty; int noconv=0; int circ=0; do_backtrack = 1; string=NULL; for (i=1; i<argc; i++) { if (argv[i][0]=='-') switch ( argv[i][1] ) { case 'T': if (argv[i][2]!='\0') usage(); if(i==argc-1) usage(); r=sscanf(argv[++i], "%lf", &temperature); if (!r) usage(); break; case 'p': pf=1; if (argv[i][2]!='\0') (void) sscanf(argv[i]+2, "%d", &do_backtrack); break; case 'n': if ( strcmp(argv[i], "-noGU")==0) noGU=1; if ( strcmp(argv[i], "-noCloseGU")==0) no_closingGU=1; if ( strcmp(argv[i], "-noLP")==0) noLonelyPairs=1; if ( strcmp(argv[i], "-noPS")==0) noPS=1; if ( strcmp(argv[i], "-nsp") ==0) { if (i==argc-1) usage(); ns_bases = argv[++i]; } if ( strcmp(argv[i], "-noconv")==0) noconv=1; break; case '4': tetra_loop=0; break; case 'e': if(i==argc-1) usage(); r=sscanf(argv[++i],"%d", &energy_set); if (!r) usage(); break; case 'C': fold_constrained=1; break; case 'c': if ( strcmp(argv[i], "-circ")==0) circ=1; break; case 'S': if(i==argc-1) usage(); r=sscanf(argv[++i],"%lf", &sfact); if (!r) usage(); break; case 'd': dangles=0; if (argv[i][2]!='\0') { r=sscanf(argv[i]+2, "%d", &dangles); if (r!=1) usage(); } break; case 'P': if (i==argc-1) usage(); ParamFile = argv[++i]; break; default: usage(); } } if (circ && noLonelyPairs) fprintf(stderr, "warning, depending on the origin of the circular sequence, some structures may be missed when using -noLP\nTry rotating your sequence a few times\n"); if (ParamFile != NULL) read_parameter_file(ParamFile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } istty = isatty(fileno(stdout))&&isatty(fileno(stdin)); if ((fold_constrained)&&(istty)) { printf("Input constraints using the following notation:\n"); printf("| : paired with another base\n"); printf(". : no constraint at all\n"); printf("x : base must not pair\n"); printf("< : base i is paired with a base j<i\n"); printf("> : 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 (!noPS) { if (length<2000) (void) PS_rna_plot(string, structure, ffname); else fprintf(stderr,"INFO: structure too long, not doing xy_plot\n"); } if (length>2000) free_arrays(); if (pf) { char *pf_struc; pf_struc = (char *) space((unsigned) length+1); if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = (circ) ? energy_of_circ_struct(string, structure) : 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); (circ) ? init_pf_circ_fold(length) : init_pf_fold(length); if (cstruc!=NULL) strncpy(pf_struc, cstruc, length+1); energy = (circ) ? pf_circ_fold(string, pf_struc) : pf_fold(string, pf_struc); if (do_backtrack) { printf("%s", pf_struc); 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); if (do_backtrack) { plist *pl1,*pl2; char *cent; double dist, cent_en; cent = centroid(length, &dist); cent_en = (circ) ? energy_of_circ_struct(string, cent) :energy_of_struct(string, cent); printf("%s {%6.2f d=%.2f}\n", cent, cent_en, dist); free(cent); if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_dp.ps"); } else strcpy(ffname, "dot.ps"); pl1 = make_plist(length, 1e-5); pl2 = b2plist(structure); (void) PS_dot_plot_list(string, ffname, pl1, pl2, ""); free(pl2); if (do_backtrack==2) { pl2 = stackProb(1e-5); if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_dp2.ps"); } else strcpy(ffname, "dot2.ps"); PS_dot_plot_list(string, ffname, pl1, pl2, "Probabilities for stacked pairs (i,j)(i+1,j-1)"); free(pl2); } free(pl1); free(pf_struc); } 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)); printf("\n"); free_pf_arrays(); } if (cstruc!=NULL) free(cstruc); (void) fflush(stdout); free(string); free(structure); } while (1); return 0; }
int main(int argc, char *argv[]) { char *sequence; char *structure = NULL; char *ns_bases = NULL, *c; int i, length, l, sym; int istty; double deltap=0.; int delta=100; int n_back = 0; int noconv=0; int circ=0; int dos=0; AjPSeq seq = NULL; AjPFile confile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPStr constring = NULL; float eT = 0.; AjBool eGU; AjBool eclose; AjBool lonely; AjBool convert; AjPStr ensbases = NULL; AjBool etloop; AjPStr edangles = NULL; char edangle = '\0'; ajint len; float erange; float prange; embInitPV("vrnasubopt",argc,argv,"VIENNA",VERSION); constring = ajStrNew(); seq = ajAcdGetSeq("sequence"); confile = ajAcdGetInfile("constraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); circ = !!ajAcdGetBoolean("circular"); dos = !!ajAcdGetBoolean("dos"); eGU = ajAcdGetBoolean("gu"); eclose = ajAcdGetBoolean("closegu"); lonely = ajAcdGetBoolean("lp"); convert = ajAcdGetBoolean("convert"); ensbases = ajAcdGetString("nsbases"); etloop = ajAcdGetBoolean("tetraloop"); erange = ajAcdGetFloat("erange"); prange = ajAcdGetFloat("prange"); subopt_sorted = !!ajAcdGetBoolean("sort"); logML = !!ajAcdGetBoolean("logml"); n_back = ajAcdGetInt("nrandom"); edangles = ajAcdGetListSingle("dangles"); outf = ajAcdGetOutfile("outfile"); if(dos) print_energy = -999999; do_backtrack = 1; istty = 0; temperature = (double) eT; noGU = (eGU) ? 0 : 1; no_closingGU = (eclose) ? 0 : 1; noLonelyPairs = (lonely) ? 0 : 1; noconv = (convert) ? 0 : 1; ns_bases = (ajStrGetLen(ensbases)) ? MAJSTRGETPTR(ensbases) : NULL; tetra_loop = !!etloop; delta = (int) (0.1 + erange * 100); deltap = prange; edangle = *ajStrGetPtr(edangles); if(edangle == '0') dangles = 0; else if(edangle == '1') dangles = 1; else if(edangle == '2') dangles = 2; else if(edangle == '3') dangles = 3; if(paramfile) read_parameter_file(paramfile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c) { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } if(confile) vienna_GetConstraints(confile,&constring); if(n_back) init_rand(); sequence = NULL; structure = NULL; length = ajSeqGetLen(seq); sequence = (char *) space(length+1); strcpy(sequence,ajSeqGetSeqC(seq)); len = ajStrGetLen(constring); structure = (char *) space(length+1); if(len) { fold_constrained = 1; strcpy(structure,ajStrGetPtr(constring)); } istty = 0; if (fold_constrained) { for (i=0; i<length; i++) if (structure[i]=='|') ajFatal("Constraints of type '|' are not allowed\n"); } for (l = 0; l < length; l++) { sequence[l] = toupper(sequence[l]); if (!noconv && sequence[l] == 'T') sequence[l] = 'U'; } if ((logML!=0 || dangles==1 || dangles==3) && dos==0) if (deltap<=0) deltap=delta/100. +0.001; if (deltap>0) print_energy = deltap; /* first lines of output (suitable for sort +1n) */ ajFmtPrintF(outf,"> %s [%d]\n", ajSeqGetNameC(seq), delta); if(n_back>0) { int i; double mfe, kT; char *ss; st_back=1; ss = (char *) space(strlen(sequence)+1); strncpy(ss, structure, length); mfe = (circ) ? circfold(sequence, ss) : fold(sequence, ss); kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(1.03*mfe)/kT/length); strncpy(ss, structure, length); /* ** we are not interested in the free energy but in the bppm, so we ** drop free energy into the void */ (circ) ? (void) pf_circ_fold(sequence, ss) : (void) pf_fold(sequence, ss); free(ss); for (i=0; i<n_back; i++) { char *s; s = (circ) ? pbacktrack_circ(sequence) : pbacktrack(sequence); ajFmtPrintF(outf,"%s\n", s); free(s); } free_pf_arrays(); } else { (circ) ? subopt_circ(sequence, structure, delta, ajFileGetFileptr(outf)) : subopt(sequence, structure, delta, ajFileGetFileptr(outf)); } free(sequence); free(structure); ajSeqDel(&seq); ajStrDel(&ensbases); ajStrDel(&edangles); ajFileClose(&confile); ajFileClose(&outf); ajFileClose(¶mfile); embExit(); return 0; }
int main(int argc, char *argv[]){ struct RNAsubopt_args_info args_info; unsigned int input_type; char fname[80], *cstruc, *sequence, *c, *input_string; char *structure = NULL, *ParamFile = NULL, *ns_bases = NULL; int i, length, l, sym, istty; double deltaf, deltap; int delta, n_back, noconv, circular, dos, zuker; do_backtrack = 1; dangles = 2; delta = 100; deltap = n_back = noconv = circular = dos = zuker = 0; /* ############################################# # check the command line parameters ############################################# */ if(RNAsubopt_cmdline_parser (argc, argv, &args_info) != 0) exit(1); /* temperature */ if(args_info.temp_given) temperature = args_info.temp_arg; /* structure constraint */ if(args_info.constraint_given) fold_constrained=1; /* do not take special tetra loop energies into account */ if(args_info.noTetra_given) tetra_loop=0; /* set dangle model */ if(args_info.dangles_given) dangles = args_info.dangles_arg; /* do not allow weak pairs */ if(args_info.noLP_given) noLonelyPairs = 1; /* do not allow wobble pairs (GU) */ if(args_info.noGU_given) noGU = 1; /* do not allow weak closing pairs (AU,GU) */ if(args_info.noClosingGU_given) no_closingGU = 1; /* do not convert DNA nucleotide "T" to appropriate RNA "U" */ if(args_info.noconv_given) noconv = 1; /* take another energy parameter set */ if(args_info.paramFile_given) ParamFile = strdup(args_info.paramFile_arg); /* Allow other pairs in addition to the usual AU,GC,and GU pairs */ if(args_info.nsp_given) ns_bases = strdup(args_info.nsp_arg); /* energy range */ if(args_info.deltaEnergy_given) delta = (int) (0.1+args_info.deltaEnergy_arg*100); /* energy range after post evaluation */ if(args_info.deltaEnergyPost_given) deltap = args_info.deltaEnergyPost_arg; /* sorted output */ if(args_info.sorted_given) subopt_sorted = 1; /* assume RNA sequence to be circular */ if(args_info.circ_given) circular=1; /* stochastic backtracking */ if(args_info.stochBT_given){ n_back = args_info.stochBT_arg; init_rand(); } /* density of states */ if(args_info.dos_given){ dos = 1; print_energy = -999999; } /* logarithmic multiloop energies */ if(args_info.logML_given) logML = 1; /* zuker subopts */ if(args_info.zuker_given) zuker = 1; if(zuker){ if(circular){ warn_user("Sorry, zuker subopts not yet implemented for circfold"); RNAsubopt_cmdline_parser_print_help(); exit(1); } else if(n_back>0){ warn_user("Can't do zuker subopts and stochastic subopts at the same time"); RNAsubopt_cmdline_parser_print_help(); exit(1); } } /* free allocated memory of command line data structure */ RNAsubopt_cmdline_parser_free(&args_info); /* ############################################# # begin initializing ############################################# */ if (ParamFile != NULL) read_parameter_file(ParamFile); if (ns_bases != NULL) { nonstandards = space(33); c=ns_bases; i=sym=0; if (*c=='-') { sym=1; c++; } while (*c!='\0') { if (*c!=',') { nonstandards[i++]=*c++; nonstandards[i++]=*c; if ((sym)&&(*c!=*(c-1))) { nonstandards[i++]=*c; nonstandards[i++]=*(c-1); } } c++; } } istty = isatty(fileno(stdout))&&isatty(fileno(stdin)); if(fold_constrained && istty) print_tty_constraint(VRNA_CONSTRAINT_DOT | VRNA_CONSTRAINT_X); /* ############################################# # main loop: continue until end of file ############################################# */ do { cut_point = -1; /* ######################################################## # handle user input from 'stdin' ######################################################## */ if(istty){ if (!zuker) printf("Use '&' to connect 2 sequences that shall form a complex.\n"); print_tty_input_seq(); } /* extract filename from fasta header if available */ fname[0] = '\0'; while((input_type = get_input_line(&input_string, 0)) == VRNA_INPUT_FASTA_HEADER){ printf(">%s\n", input_string); (void) sscanf(input_string, "%42s", fname); free(input_string); } /* break on any error, EOF or quit request */ if(input_type & (VRNA_INPUT_QUIT | VRNA_INPUT_ERROR)){ break;} /* else assume a proper sequence of letters of a certain alphabet (RNA, DNA, etc.) */ else{ sequence = tokenize(input_string); /* frees input_string */ length = (int) strlen(sequence); } structure = (char *) space((unsigned) length+1); if(noconv) str_RNA2RNA(sequence); else str_DNA2RNA(sequence); if(istty){ if (cut_point == -1) printf("length = %d\n", length); else printf("length1 = %d\nlength2 = %d\n", cut_point-1, length-cut_point+1); } /* get structure constraint or break if necessary, entering an empty line results in a warning */ if (fold_constrained) { input_type = get_input_line(&input_string, VRNA_INPUT_NOSKIP_COMMENTS); if(input_type & VRNA_INPUT_QUIT){ break;} else if((input_type & VRNA_INPUT_MISC) && (strlen(input_string) > 0)){ cstruc = tokenize(input_string); strncpy(structure, cstruc, length); for (i=0; i<length; i++) if (structure[i]=='|') nrerror("constraints of type '|' not allowed"); free(cstruc); } else warn_user("constraints missing"); } /* ######################################################## # done with 'stdin' handling, now init everything properly ######################################################## */ if((logML != 0 || dangles==1 || dangles==3) && dos == 0) if(deltap<=0) deltap = delta/100. + 0.001; if (deltap>0) print_energy = deltap; /* first lines of output (suitable for sort +1n) */ if (fname[0] != '\0') printf("> %s [%d]\n", fname, delta); /* stochastic backtracking */ if(n_back>0){ double mfe, kT; char *ss; st_back=1; ss = (char *) space(strlen(sequence)+1); strncpy(ss, structure, length); mfe = fold(sequence, ss); kT = (temperature+273.15)*1.98717/1000.; /* in Kcal */ pf_scale = exp(-(1.03*mfe)/kT/length); strncpy(ss, structure, length); /* ignore return value, we are not interested in the free energy */ (circular) ? (void) pf_circ_fold(sequence, ss) : (void) pf_fold(sequence, ss); free(ss); for (i=0; i<n_back; i++) { char *s; s =(circular) ? pbacktrack_circ(sequence) : pbacktrack(sequence); printf("%s\n", s); free(s); } free_pf_arrays(); } /* normal subopt */ else if(!zuker){ (circular) ? subopt_circ(sequence, structure, delta, stdout) : subopt(sequence, structure, delta, stdout); if (dos) { int i; for (i=0; i<= MAXDOS && i<=delta/10; i++) { printf("%4d %6d\n", i, density_of_states[i]); } } } /* Zuker suboptimals */ else{ SOLUTION *zr; int i; if (cut_point!=-1) { nrerror("Sorry, zuker subopts not yet implemented for cofold\n"); } zr = zukersubopt(sequence); putoutzuker(zr); (void)fflush(stdout); for (i=0; zr[i].structure; i++) { free(zr[i].structure); } free(zr); } (void)fflush(stdout); free(sequence); free(structure); } while (1); return 0; }