int main(int argc, char *argv[]) { struct RNAcofold_args_info args_info; unsigned int input_type; char *string, *input_string; char *structure, *cstruc, *rec_sequence, *orig_sequence, *rec_id, **rec_rest; char fname[FILENAME_MAX_LENGTH], ffname[FILENAME_MAX_LENGTH]; char *ParamFile; char *ns_bases, *c; char *Concfile; int i, length, l, sym, r, cl; double min_en; double kT, sfact, betaScale; int pf, istty; int noconv, noPS; int doT; /*compute dimere free energies etc.*/ int doC; /*toggle to compute concentrations*/ int doQ; /*toggle to compute prob of base being paired*/ int cofi; /*toggle concentrations stdin / file*/ plist *prAB; plist *prAA; /*pair probabilities of AA dimer*/ plist *prBB; plist *prA; plist *prB; plist *mfAB; plist *mfAA; /*pair mfobabilities of AA dimer*/ plist *mfBB; plist *mfA; plist *mfB; double *ConcAandB; unsigned int rec_type, read_opt; pf_paramT *pf_parameters; model_detailsT md; /* ############################################# # init variables and parameter options ############################################# */ dangles = 2; sfact = 1.07; bppmThreshold = 1e-5; noconv = 0; noPS = 0; do_backtrack = 1; pf = 0; doT = 0; doC = 0; doQ = 0; cofi = 0; betaScale = 1.; gquad = 0; ParamFile = NULL; pf_parameters = NULL; string = NULL; Concfile = NULL; structure = NULL; cstruc = NULL; ns_bases = NULL; rec_type = read_opt = 0; rec_id = rec_sequence = orig_sequence = NULL; rec_rest = NULL; set_model_details(&md); /* ############################################# # check the command line prameters ############################################# */ if(RNAcofold_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) md.special_hp = tetra_loop=0; /* set dangle model */ if(args_info.dangles_given){ if((args_info.dangles_arg < 0) || (args_info.dangles_arg > 3)) warn_user("required dangle model not implemented, falling back to default dangles=2"); else md.dangles = dangles = args_info.dangles_arg; } /* do not allow weak pairs */ if(args_info.noLP_given) md.noLP = noLonelyPairs = 1; /* do not allow wobble pairs (GU) */ if(args_info.noGU_given) md.noGU = noGU = 1; /* do not allow weak closing pairs (AU,GU) */ if(args_info.noClosingGU_given) md.noGUclosure = no_closingGU = 1; /* gquadruplex support */ if(args_info.gquad_given) md.gquad = gquad = 1; /* enforce canonical base pairs in any case? */ if(args_info.canonicalBPonly_given) md.canonicalBPonly = canonicalBPonly = 1; /* do not convert DNA nucleotide "T" to appropriate RNA "U" */ if(args_info.noconv_given) noconv = 1; /* set energy model */ if(args_info.energyModel_given) energy_set = args_info.energyModel_arg; /* */ if(args_info.noPS_given) noPS = 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); /* set pf scaling factor */ if(args_info.pfScale_given) sfact = args_info.pfScale_arg; if(args_info.all_pf_given) doT = pf = 1; /* concentrations from stdin */ if(args_info.concentrations_given) doC = doT = pf = 1; /* set the bppm threshold for the dotplot */ if(args_info.bppmThreshold_given) bppmThreshold = MIN2(1., MAX2(0.,args_info.bppmThreshold_arg)); /* concentrations in file */ if(args_info.betaScale_given) betaScale = args_info.betaScale_arg; if(args_info.concfile_given){ Concfile = strdup(args_info.concfile_arg); doC = cofi = doT = pf = 1; } /* partition function settings */ if(args_info.partfunc_given){ pf = 1; if(args_info.partfunc_arg != -1) do_backtrack = args_info.partfunc_arg; } /* free allocated memory of command line data structure */ RNAcofold_cmdline_parser_free (&args_info); /* ############################################# # begin initializing ############################################# */ if(pf && gquad){ nrerror("G-Quadruplex support is currently not available for partition function computations"); } 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)); /* print user help if we get input from tty */ if(istty){ printf("Use '&' to connect 2 sequences that shall form a complex.\n"); if(fold_constrained){ print_tty_constraint(VRNA_CONSTRAINT_DOT | VRNA_CONSTRAINT_X | VRNA_CONSTRAINT_ANG_BRACK | VRNA_CONSTRAINT_RND_BRACK); print_tty_input_seq_str("Input sequence (upper or lower case) followed by structure constraint\n"); } else print_tty_input_seq(); } /* set options we wanna pass to read_record */ if(istty) read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES; if(!fold_constrained) read_opt |= VRNA_INPUT_NO_REST; /* ############################################# # main loop: continue until end of file ############################################# */ while( !((rec_type = read_record(&rec_id, &rec_sequence, &rec_rest, read_opt)) & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){ /* ######################################################## # init everything according to the data we've read ######################################################## */ if(rec_id){ if(!istty) printf("%s\n", rec_id); (void) sscanf(rec_id, ">%" XSTR(FILENAME_ID_LENGTH) "s", fname); } else fname[0] = '\0'; cut_point = -1; rec_sequence = tokenize(rec_sequence); /* frees input_string and sets cut_point */ length = (int) strlen(rec_sequence); structure = (char *) space((unsigned) length+1); /* parse the rest of the current dataset to obtain a structure constraint */ if(fold_constrained){ cstruc = NULL; int cp = cut_point; unsigned int coptions = (rec_id) ? VRNA_CONSTRAINT_MULTILINE : 0; coptions |= VRNA_CONSTRAINT_DOT | VRNA_CONSTRAINT_X | VRNA_CONSTRAINT_ANG_BRACK | VRNA_CONSTRAINT_RND_BRACK; getConstraint(&cstruc, (const char **)rec_rest, coptions); cstruc = tokenize(cstruc); if(cut_point != cp) nrerror("cut point in sequence and structure constraint differs"); cl = (cstruc) ? (int)strlen(cstruc) : 0; if(cl == 0) warn_user("structure constraint is missing"); else if(cl < length) warn_user("structure constraint is shorter than sequence"); else if(cl > length) nrerror("structure constraint is too long"); if(cstruc) strncpy(structure, cstruc, sizeof(char)*(cl+1)); } /* convert DNA alphabet to RNA if not explicitely switched off */ if(!noconv) str_DNA2RNA(rec_sequence); /* store case-unmodified sequence */ orig_sequence = strdup(rec_sequence); /* convert sequence to uppercase letters only */ str_uppercase(rec_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); } /* ######################################################## # begin actual computations ######################################################## */ if (doC) { FILE *fp; if (cofi) { /* read from file */ fp = fopen(Concfile, "r"); if (fp==NULL) { fprintf(stderr, "could not open concentration file %s", Concfile); nrerror("\n"); } ConcAandB = read_concentrations(fp); fclose(fp); } else { printf("Please enter concentrations [mol/l]\n format: ConcA ConcB\n return to end\n"); ConcAandB = read_concentrations(stdin); } } /*compute mfe of AB dimer*/ min_en = cofold(rec_sequence, structure); assign_plist_from_db(&mfAB, structure, 0.95); { char *pstring, *pstruct; if (cut_point == -1) { pstring = strdup(orig_sequence); pstruct = strdup(structure); } else { pstring = costring(orig_sequence); pstruct = costring(structure); } printf("%s\n%s", pstring, pstruct); 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 (!noPS) { char annot[512] = ""; if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_ss.ps"); } else { strcpy(ffname, "rna.ps"); } if (cut_point >= 0) sprintf(annot, "1 %d 9 0 0.9 0.2 omark\n%d %d 9 1 0.1 0.2 omark\n", cut_point-1, cut_point+1, length+1); if(gquad){ if (!noPS) (void) PS_rna_plot_a_gquad(pstring, pstruct, ffname, annot, NULL); } else { if (!noPS) (void) PS_rna_plot_a(pstring, pstruct, ffname, annot, NULL); } } free(pstring); free(pstruct); } if (length>2000) free_co_arrays(); /*compute partition function*/ if (pf) { cofoldF AB, AA, BB; FLT_OR_DBL *probs; if (dangles==1) { dangles=2; /* recompute with dangles as in pf_fold() */ min_en = energy_of_structure(rec_sequence, structure, 0); dangles=1; } kT = (betaScale*((temperature+K0)*GASCONST))/1000.; /* in Kcal */ pf_scale = exp(-(sfact*min_en)/kT/length); if (length>2000) fprintf(stderr, "scaling factor %f\n", pf_scale); pf_parameters = get_boltzmann_factors(temperature, betaScale, md, pf_scale); if (cstruc!=NULL) strncpy(structure, cstruc, length+1); AB = co_pf_fold_par(rec_sequence, structure, pf_parameters, do_backtrack, fold_constrained); if (do_backtrack) { char *costruc; costruc = (char *) space(sizeof(char)*(strlen(structure)+2)); if (cut_point<0) printf("%s", structure); else { strncpy(costruc, structure, cut_point-1); strcat(costruc, "&"); strcat(costruc, structure+cut_point-1); printf("%s", costruc); } if (!istty) printf(" [%6.2f]\n", AB.FAB); else printf("\n");/*8.6.04*/ } if ((istty)||(!do_backtrack)) printf(" free energy of ensemble = %6.2f kcal/mol\n", AB.FAB); printf(" frequency of mfe structure in ensemble %g", exp((AB.FAB-min_en)/kT)); printf(" , delta G binding=%6.2f\n", AB.FcAB - AB.FA - AB.FB); probs = export_co_bppm(); assign_plist_from_pr(&prAB, probs, length, bppmThreshold); /* if (doQ) make_probsum(length,fname); */ /*compute prob of base paired*/ /* free_co_arrays(); */ if (doT) { /* cofold of all dimers, monomers */ int Blength, Alength; char *Astring, *Bstring, *orig_Astring, *orig_Bstring; char *Newstring; char Newname[30]; char comment[80]; if (cut_point<0) { printf("Sorry, i cannot do that with only one molecule, please give me two or leave it\n"); free(mfAB); free(prAB); continue; } if (dangles==1) dangles=2; Alength=cut_point-1; /*length of first molecule*/ Blength=length-cut_point+1; /*length of 2nd molecule*/ Astring=(char *)space(sizeof(char)*(Alength+1));/*Sequence of first molecule*/ Bstring=(char *)space(sizeof(char)*(Blength+1));/*Sequence of second molecule*/ strncat(Astring,rec_sequence,Alength); strncat(Bstring,rec_sequence+Alength,Blength); orig_Astring=(char *)space(sizeof(char)*(Alength+1));/*Sequence of first molecule*/ orig_Bstring=(char *)space(sizeof(char)*(Blength+1));/*Sequence of second molecule*/ strncat(orig_Astring,orig_sequence,Alength); strncat(orig_Bstring,orig_sequence+Alength,Blength); /* compute AA dimer */ AA=do_partfunc(Astring, Alength, 2, &prAA, &mfAA, pf_parameters); /* compute BB dimer */ BB=do_partfunc(Bstring, Blength, 2, &prBB, &mfBB, pf_parameters); /*free_co_pf_arrays();*/ /* compute A monomer */ do_partfunc(Astring, Alength, 1, &prA, &mfA, pf_parameters); /* compute B monomer */ do_partfunc(Bstring, Blength, 1, &prB, &mfB, pf_parameters); compute_probabilities(AB.F0AB, AB.FA, AB.FB, prAB, prA, prB, Alength); compute_probabilities(AA.F0AB, AA.FA, AA.FA, prAA, prA, prA, Alength); compute_probabilities(BB.F0AB, BB.FA, BB.FA, prBB, prA, prB, Blength); printf("Free Energies:\nAB\t\tAA\t\tBB\t\tA\t\tB\n%.6f\t%6f\t%6f\t%6f\t%6f\n", AB.FcAB, AA.FcAB, BB.FcAB, AB.FA, AB.FB); if (doC) { do_concentrations(AB.FcAB, AA.FcAB, BB.FcAB, AB.FA, AB.FB, ConcAandB); free(ConcAandB);/*freeen*/ } if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_dp5.ps"); } else strcpy(ffname, "dot5.ps"); /*output of the 5 dot plots*/ /*AB dot_plot*/ /*write Free Energy into comment*/ sprintf(comment,"\n%%Heterodimer AB FreeEnergy= %.9f\n", AB.FcAB); /*reset cut_point*/ cut_point=Alength+1; /*write New name*/ strcpy(Newname,"AB"); strcat(Newname,ffname); (void)PS_dot_plot_list(orig_sequence, Newname, prAB, mfAB, comment); /*AA dot_plot*/ sprintf(comment,"\n%%Homodimer AA FreeEnergy= %.9f\n",AA.FcAB); /*write New name*/ strcpy(Newname,"AA"); strcat(Newname,ffname); /*write AA sequence*/ Newstring=(char*)space((2*Alength+1)*sizeof(char)); strcpy(Newstring,orig_Astring); strcat(Newstring,orig_Astring); (void)PS_dot_plot_list(Newstring, Newname, prAA, mfAA, comment); free(Newstring); /*BB dot_plot*/ sprintf(comment,"\n%%Homodimer BB FreeEnergy= %.9f\n",BB.FcAB); /*write New name*/ strcpy(Newname,"BB"); strcat(Newname,ffname); /*write BB sequence*/ Newstring=(char*)space((2*Blength+1)*sizeof(char)); strcpy(Newstring,orig_Bstring); strcat(Newstring,orig_Bstring); /*reset cut_point*/ cut_point=Blength+1; (void)PS_dot_plot_list(Newstring, Newname, prBB, mfBB, comment); free(Newstring); /*A dot plot*/ /*reset cut_point*/ cut_point=-1; sprintf(comment,"\n%%Monomer A FreeEnergy= %.9f\n",AB.FA); /*write New name*/ strcpy(Newname,"A"); strcat(Newname,ffname); /*write BB sequence*/ (void)PS_dot_plot_list(orig_Astring, Newname, prA, mfA, comment); /*B monomer dot plot*/ sprintf(comment,"\n%%Monomer B FreeEnergy= %.9f\n",AB.FB); /*write New name*/ strcpy(Newname,"B"); strcat(Newname,ffname); /*write BB sequence*/ (void)PS_dot_plot_list(orig_Bstring, Newname, prB, mfB, comment); free(Astring); free(Bstring); free(orig_Astring); free(orig_Bstring); free(prAB); free(prAA); free(prBB); free(prA); free(prB); free(mfAB); free(mfAA); free(mfBB); free(mfA); free(mfB); } /*end if(doT)*/ free(pf_parameters); }/*end if(pf)*/ if (do_backtrack) { if (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_dp.ps"); } else strcpy(ffname, "dot.ps"); if (!doT) { if (pf) { (void) PS_dot_plot_list(rec_sequence, ffname, prAB, mfAB, "doof"); free(prAB);} free(mfAB); } } if (!doT) free_co_pf_arrays(); (void) fflush(stdout); /* clean up */ if(cstruc) free(cstruc); if(rec_id) free(rec_id); free(rec_sequence); free(orig_sequence); free(structure); /* free the rest of current dataset */ if(rec_rest){ for(i=0;rec_rest[i];i++) free(rec_rest[i]); free(rec_rest); } rec_id = rec_sequence = orig_sequence = structure = cstruc = NULL; rec_rest = NULL; /* print user help for the next round if we get input from tty */ if(istty){ printf("Use '&' to connect 2 sequences that shall form a complex.\n"); if(fold_constrained){ print_tty_constraint(VRNA_CONSTRAINT_DOT | VRNA_CONSTRAINT_X | VRNA_CONSTRAINT_ANG_BRACK | VRNA_CONSTRAINT_RND_BRACK); print_tty_input_seq_str("Input sequence (upper or lower case) followed by structure constraint\n"); } else print_tty_input_seq(); } } return EXIT_SUCCESS; }
/*--------------------------------------------------------------------------*/ int main(int argc, char *argv[]){ struct RNAplfold_args_info args_info; unsigned int error = 0; char fname[FILENAME_MAX_LENGTH], ffname[FILENAME_MAX_LENGTH], *c, *structure, *ParamFile, *ns_bases, *rec_sequence, *rec_id, **rec_rest, *orig_sequence; unsigned int input_type; int i, length, l, sym, r, istty, winsize, pairdist; float cutoff; int tempwin, temppair, tempunpaired; FILE *pUfp = NULL, *spup = NULL; double **pup = NULL; /*prob of being unpaired, lengthwise*/ int noconv, plexoutput, simply_putout, openenergies, binaries; plist *pl, *dpp = NULL; unsigned int rec_type, read_opt; double betaScale; pf_paramT *pf_parameters; model_detailsT md; dangles = 2; cutoff = 0.01; winsize = 70; pairdist = 0; unpaired = 0; betaScale = 1.; simply_putout = plexoutput = openenergies = noconv = 0;binaries=0; tempwin = temppair = tempunpaired = 0; structure = ParamFile = ns_bases = NULL; rec_type = read_opt = 0; rec_id = rec_sequence = orig_sequence = NULL; rec_rest = NULL; pf_parameters = NULL; set_model_details(&md); /* ############################################# # check the command line parameters ############################################# */ if(RNAplfold_cmdline_parser (argc, argv, &args_info) != 0) exit(1); /* temperature */ if(args_info.temp_given) temperature = args_info.temp_arg; /* do not take special tetra loop energies into account */ if(args_info.noTetra_given) md.special_hp = tetra_loop=0; /* set dangle model */ if(args_info.dangles_given){ if((args_info.dangles_arg != 0) && (args_info.dangles_arg != 2)) warn_user("required dangle model not implemented, falling back to default dangles=2"); else md.dangles = dangles = args_info.dangles_arg; } /* do not allow weak pairs */ if(args_info.noLP_given) md.noLP = noLonelyPairs = 1; /* do not allow wobble pairs (GU) */ if(args_info.noGU_given) md.noGU = noGU = 1; /* do not allow weak closing pairs (AU,GU) */ if(args_info.noClosingGU_given) md.noGUclosure = no_closingGU = 1; /* do not convert DNA nucleotide "T" to appropriate RNA "U" */ if(args_info.noconv_given) noconv = 1; /* set energy model */ if(args_info.energyModel_given) energy_set = args_info.energyModel_arg; /* 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); /* set the maximum base pair span */ if(args_info.span_given) pairdist = args_info.span_arg; /* set the pair probability cutoff */ if(args_info.cutoff_given) cutoff = args_info.cutoff_arg; /* set the windowsize */ if(args_info.winsize_given) winsize = args_info.winsize_arg; /* set the length of unstructured region */ if(args_info.ulength_given) unpaired = args_info.ulength_arg; /* compute opening energies */ if(args_info.opening_energies_given) openenergies = 1; /* print output on the fly */ if(args_info.print_onthefly_given) simply_putout = 1; /* turn on RNAplex output */ if(args_info.plex_output_given) plexoutput = 1; /* turn on binary output*/ if(args_info.binaries_given) binaries = 1; if(args_info.betaScale_given) betaScale = args_info.betaScale_arg; /* check for errorneous parameter options */ if((pairdist < 0) || (cutoff < 0.) || (unpaired < 0) || (winsize < 0)){ RNAplfold_cmdline_parser_print_help(); exit(EXIT_FAILURE); } /* free allocated memory of command line data structure */ RNAplfold_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++; } } /* check parameter options again and reset to reasonable values if needed */ if(openenergies && !unpaired) unpaired = 31; if(pairdist == 0) pairdist = winsize; if(pairdist > winsize){ fprintf(stderr, "pairdist (-L %d) should be <= winsize (-W %d);" "Setting pairdist=winsize\n",pairdist, winsize); pairdist = winsize; } if(dangles % 2){ warn_user("using default dangles = 2"); dangles = 2; } istty = isatty(fileno(stdout))&&isatty(fileno(stdin)); read_opt |= VRNA_INPUT_NO_REST; if(istty){ print_tty_input_seq(); read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES; } /* ############################################# # main loop: continue until end of file ############################################# */ while( !((rec_type = read_record(&rec_id, &rec_sequence, &rec_rest, read_opt)) & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){ /* ######################################################## # init everything according to the data we've read ######################################################## */ if(rec_id){ if(!istty) printf("%s\n", rec_id); (void) sscanf(rec_id, ">%" XSTR(FILENAME_ID_LENGTH) "s", fname); } else fname[0] = '\0'; length = (int)strlen(rec_sequence); structure = (char *) space((unsigned) length+1); /* convert DNA alphabet to RNA if not explicitely switched off */ if(!noconv) str_DNA2RNA(rec_sequence); /* store case-unmodified sequence */ orig_sequence = strdup(rec_sequence); /* convert sequence to uppercase letters only */ str_uppercase(rec_sequence); if(istty) printf("length = %d\n", length); /* ######################################################## # done with 'stdin' handling ######################################################## */ if(length > 1000000){ if(!simply_putout && !unpaired){ printf("Switched to simple output mode!!!\n"); simply_putout = 1; } } if(unpaired && simply_putout){ printf("Output simplification not possible if unpaired is switched on\n"); simply_putout = 0; } /* restore winsize if altered before */ if(tempwin != 0){ winsize = tempwin; tempwin = 0; } /* restore pairdist if altered before */ if(temppair != 0){ pairdist = temppair; temppair = 0; } /* restore ulength if altered before */ if(tempunpaired != 0){ unpaired = tempunpaired; tempunpaired = 0; } /* adjust winsize, pairdist and ulength if necessary */ if(length < winsize){ fprintf(stderr, "WARN: window size %d larger than sequence length %d\n", winsize, length); tempwin = winsize; winsize = length; if (pairdist>winsize) { temppair=pairdist; pairdist=winsize; } if (unpaired>winsize) { tempunpaired=unpaired; unpaired=winsize; } } /* ######################################################## # begin actual computations ######################################################## */ if (length >= 5){ /* construct output file names */ char fname1[FILENAME_MAX_LENGTH], fname2[FILENAME_MAX_LENGTH], fname3[FILENAME_MAX_LENGTH], fname4[FILENAME_MAX_LENGTH], fname_t[FILENAME_MAX_LENGTH]; strcpy(fname_t, (fname[0] != '\0') ? fname : "plfold"); strcpy(fname1, fname_t); strcpy(fname2, fname_t); strcpy(fname3, fname_t); strcpy(fname4, fname_t); strcpy(ffname, fname_t); strcat(fname1, "_lunp"); strcat(fname2, "_basepairs"); strcat(fname3, "_uplex"); if(binaries){ strcat(fname4, "_openen_bin"); } else{ strcat(fname4, "_openen"); } strcat(ffname, "_dp.ps"); pf_parameters = get_boltzmann_factors(temperature, betaScale, md, -1); if(unpaired > 0){ pup =(double **) space((length+1)*sizeof(double *)); pup[0] =(double *) space(sizeof(double)); /*I only need entry 0*/ pup[0][0] = unpaired; } pUfp = spup = NULL; if(simply_putout){ spup = fopen(fname2, "w"); pUfp = (unpaired > 0) ? fopen(fname1, "w") : NULL; pl = pfl_fold_par(rec_sequence, winsize, pairdist, cutoff, pup, &dpp, pUfp, spup, pf_parameters); if(pUfp != NULL) fclose(pUfp); if(spup != NULL) fclose(spup); } else{ pl = pfl_fold_par(rec_sequence, winsize, pairdist, cutoff, pup, &dpp, pUfp, spup, pf_parameters); PS_dot_plot_turn(orig_sequence, pl, ffname, pairdist); if (unpaired > 0){ if(plexoutput){ pUfp = fopen(fname3, "w"); putoutphakim_u(pup,length, unpaired, pUfp); fclose(pUfp); } pUfp = fopen(openenergies ? fname4 : fname1, "w"); if(binaries){ putoutpU_prob_bin_par(pup, length, unpaired, pUfp, openenergies, pf_parameters); } else{ putoutpU_prob_par(pup, length, unpaired, pUfp, openenergies, pf_parameters); } fclose(pUfp); } } if(pl) free(pl); if(unpaired > 0){ free(pup[0]); free(pup); } free(pf_parameters); } (void) fflush(stdout); /* clean up */ if(rec_id) free(rec_id); free(rec_sequence); free(orig_sequence); free(structure); rec_id = rec_sequence = orig_sequence = NULL; rec_rest = NULL; /* print user help for the next round if we get input from tty */ if(istty) print_tty_input_seq(); } return EXIT_SUCCESS; }
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; }
int main(int argc, char *argv[]){ struct RNAheat_args_info args_info; char *string, *input_string, *ns_bases, *c, *ParamFile, *rec_sequence, *rec_id, **rec_rest, *orig_sequence; int i, length, l, sym; float T_min, T_max, h; int mpoints, istty, noconv = 0; unsigned int input_type; unsigned int rec_type, read_opt; string = ParamFile = ns_bases = NULL; T_min = 0.; T_max = 100.; h = 1; mpoints = 2; dangles = 2; /* dangles can be 0 (no dangles) or 2, default is 2 */ rec_type = read_opt = 0; rec_id = rec_sequence = orig_sequence = NULL; rec_rest = NULL; /* ############################################# # check the command line parameters ############################################# */ if(RNAheat_cmdline_parser(argc, argv, &args_info) != 0) exit(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){ if((args_info.dangles_arg != 0) && (args_info.dangles_arg != 2)) warn_user("required dangle model not implemented, falling back to default dangles=2"); else 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; /* set energy model */ if(args_info.energyModel_given) energy_set = args_info.energyModel_arg; /* 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); /* Tmin */ if(args_info.Tmin_given) T_min = args_info.Tmin_arg; /* Tmax */ if(args_info.Tmax_given) T_max = args_info.Tmax_arg; /* step size */ if(args_info.stepsize_given) h = args_info.stepsize_arg; /* ipoints */ if(args_info.ipoints_given){ mpoints = args_info.ipoints_arg; if (mpoints < 1) mpoints = 1; if (mpoints > 100) mpoints = 100; } /* free allocated memory of command line data structure */ RNAheat_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)); read_opt |= VRNA_INPUT_NO_REST; if(istty){ print_tty_input_seq(); read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES; } /* ############################################# # main loop: continue until end of file ############################################# */ while( !((rec_type = read_record(&rec_id, &rec_sequence, &rec_rest, read_opt)) & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){ /* ######################################################## # init everything according to the data we've read ######################################################## */ if(rec_id && !istty) printf("%s\n", rec_id); length = (int)strlen(rec_sequence); /* convert DNA alphabet to RNA if not explicitely switched off */ if(!noconv) str_DNA2RNA(rec_sequence); /* store case-unmodified sequence */ orig_sequence = strdup(rec_sequence); /* convert sequence to uppercase letters only */ str_uppercase(rec_sequence); if(istty) printf("length = %d\n", length); /* ######################################################## # done with 'stdin' handling ######################################################## */ heat_capacity(rec_sequence, T_min, T_max, h, mpoints); (void) fflush(stdout); /* clean up */ if(rec_id) free(rec_id); free(rec_sequence); free(orig_sequence); rec_id = rec_sequence = orig_sequence = NULL; rec_rest = NULL; /* print user help for the next round if we get input from tty */ if(istty) print_tty_input_seq(); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]){ struct RNAheat_args_info args_info; char *string, *input_string, *ns_bases, *c, *ParamFile; int i, length, l, sym; float T_min, T_max, h; int mpoints, istty, noconv = 0; unsigned int input_type; string = ParamFile = ns_bases = NULL; T_min = 0.; T_max = 100.; h = 1; mpoints = 2; dangles = 2; /* dangles can be 0 (no dangles) or 2, default is 2 */ /* ############################################# # check the command line parameters ############################################# */ if(RNAheat_cmdline_parser(argc, argv, &args_info) != 0) exit(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; if(dangles % 2){ warn_user("using default dangles = 2"); dangles = 2; } } /* 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; /* set energy model */ if(args_info.energyModel_given) energy_set = args_info.energyModel_arg; /* 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); /* Tmin */ if(args_info.Tmin_given) T_min = args_info.Tmin_arg; /* Tmax */ if(args_info.Tmax_given) T_max = args_info.Tmax_arg; /* step size */ if(args_info.stepsize_given) h = args_info.stepsize_arg; /* ipoints */ if(args_info.ipoints_given){ mpoints = args_info.ipoints_arg; if (mpoints < 1) mpoints = 1; if (mpoints > 100) mpoints = 100; } /* free allocated memory of command line data structure */ RNAheat_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)); /* ############################################# # main loop: continue until end of file ############################################# */ do { /* ######################################################## # handle user input from 'stdin' ######################################################## */ if(istty) print_tty_input_seq(); /* skip fasta headers and comments */ while((input_type = get_input_line(&input_string, 0)) & VRNA_INPUT_FASTA_HEADER){ printf(">%s\n", input_string); /* skip fasta headers and comments */ 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{ string = strdup(input_string); length = (int) strlen(string); free(input_string); } if(noconv) str_RNA2RNA(string); else str_DNA2RNA(string); if (istty) printf("length = %d\n", length); heat_capacity(string, T_min, T_max, h, mpoints); free(string); (void) fflush(stdout); } while (1); return 0; }
int main(int argc, char *argv[]){ struct RNALfold_args_info args_info; char *input_string, *c, *string, *structure, *ParamFile, *ns_bases; int i, length, l, sym, r, istty, noconv, maxdist; double energy, min_en; unsigned int input_type; string = structure = ParamFile = ns_bases = NULL; do_backtrack = 1; noconv = 0; maxdist = 150; /* ############################################# # check the command line parameters ############################################# */ if(RNALfold_cmdline_parser (argc, argv, &args_info) != 0) exit(1); /* temperature */ if(args_info.temp_given) temperature = args_info.temp_arg; /* 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; /* set energy model */ if(args_info.energyModel_given) energy_set = args_info.energyModel_arg; /* 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); /* set the maximum base pair span */ if(args_info.span_given) maxdist = args_info.span_arg; /* check for errorneous parameter options */ if(maxdist < 0){ RNALfold_cmdline_parser_print_help(); exit(EXIT_FAILURE); } /* free allocated memory of command line data structure */ RNALfold_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)); /* ############################################# # main loop: continue until end of file ############################################# */ do{ /* ######################################################## # handle user input from 'stdin' ######################################################## */ if(istty) print_tty_input_seq(); /* skip fasta header and comment lines */ while((input_type = get_input_line(&input_string, 0)) & VRNA_INPUT_FASTA_HEADER){ printf(">%s\n", input_string); 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{ length = (int) strlen(input_string); string = strdup(input_string); free(input_string); } printf("%s\n", string); structure = (char *) space((unsigned) length+1); if(noconv) str_RNA2RNA(string); else str_DNA2RNA(string); if(istty) printf("length = %d\n", length); /* ######################################################## # done with 'stdin' handling ######################################################## */ /* initialize_fold(length); */ update_fold_params(); min_en = Lfold((const char *)string, structure, maxdist); printf("%s", 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); free(string); free(structure); } while (1); return 0; }