PUBLIC void print_path(const char *seq, const char *struc) { int d; char *s; s = strdup(struc); if (cut_point == -1) printf("%s\n%s\n", seq, s); /* printf("%s\n%s %6.2f\n", seq, s, energy_of_structure(seq,s,0)); */ else { char *pstruct, *pseq; pstruct = costring(s); pseq = costring(seq); printf("%s\n%s\n", pseq, pstruct); /* printf("%s\n%s %6.2f\n", pseq, pstruct, energy_of_structure(seq,s,0)); */ free(pstruct); free(pseq); } qsort(path, BP_dist, sizeof(move_t), compare_moves_when); for (d=0; d<BP_dist; d++) { int i,j; i = path[d].i; j=path[d].j; if (i<0) { /* delete */ s[(-i)-1] = s[(-j)-1] = '.'; } else { s[i-1] = '('; s[j-1] = ')'; } /* printf("%s %6.2f - %6.2f\n", s, energy_of_structure(seq,s,0), path[d].E/100.0); */ } free(s); }
void log_start_stop(FILE *FP) { int i; fprintf(FP, "#%s\n#%s (%6.2f)\n", costring(GAV.farbe), costring(GAV.startform), GSV.startE); for (i = 0; i < GSV.maxS; i++) { fprintf(FP, "#%s (%6.2f) X%02d\n", costring(GAV.stopform[i]), GAV.sE[i], i+1); } fprintf(FP, "(%-5hu %5hu %5hu)", GAV.subi[0], GAV.subi[1], GAV.subi[2]); costring(NULL); fflush(FP); }
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 RNAeval_args_info args_info; char *string, *structure, *orig_sequence, *tmp; char *rec_sequence, *rec_id, **rec_rest; char fname[FILENAME_MAX_LENGTH]; char *ParamFile; int i, length1, length2; float energy; int istty; int circular=0; int noconv=0; int verbose = 0; unsigned int rec_type, read_opt; string = orig_sequence = ParamFile = NULL; gquad = 0; dangles = 2; /* ############################################# # check the command line parameters ############################################# */ if(RNAeval_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){ 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 dangles = args_info.dangles_arg; } /* 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); /* assume RNA sequence to be circular */ if(args_info.circ_given) circular=1; /* logarithmic multiloop energies */ if(args_info.logML_given) logML = 1; /* be verbose */ if(args_info.verbose_given) verbose = 1; /* gquadruplex support */ if(args_info.gquad_given) gquad = 1; /* free allocated memory of command line data structure */ RNAeval_cmdline_parser_free (&args_info); /* ############################################# # begin initializing ############################################# */ if (ParamFile!=NULL) read_parameter_file(ParamFile); rec_type = read_opt = 0; rec_id = rec_sequence = NULL; rec_rest = NULL; istty = isatty(fileno(stdout)) && isatty(fileno(stdin)); if(circular && gquad){ nrerror("G-Quadruplex support is currently not available for circular RNA structures"); } /* set options we wanna pass to read_record */ if(istty){ read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES; print_tty_input_seq_str("Use '&' to connect 2 sequences that shall form a complex.\n" "Input sequence (upper or lower case) followed by structure"); } /* ############################################# # 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))){ 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; string = tokenize(rec_sequence); length2 = (int) strlen(string); tmp = extract_record_rest_structure((const char **)rec_rest, 0, (rec_id) ? VRNA_OPTION_MULTILINE : 0); if(!tmp) nrerror("structure missing"); structure = tokenize(tmp); length1 = (int) strlen(structure); if(length1 != length2) nrerror("structure and sequence differ in length!"); free(tmp); /* convert DNA alphabet to RNA if not explicitely switched off */ if(!noconv) str_DNA2RNA(string); /* store case-unmodified sequence */ orig_sequence = strdup(string); /* convert sequence to uppercase letters only */ str_uppercase(string); if(istty){ if (cut_point == -1) printf("length = %d\n", length1); else printf("length1 = %d\nlength2 = %d\n", cut_point-1, length1-cut_point+1); } if(gquad) energy = energy_of_gquad_structure(string, structure, verbose); else energy = (circular) ? energy_of_circ_structure(string, structure, verbose) : energy_of_structure(string, structure, verbose); if (cut_point == -1) printf("%s\n%s", orig_sequence, structure); else { char *pstring, *pstruct; pstring = costring(orig_sequence); pstruct = costring(structure); printf("%s\n%s", pstring, pstruct); free(pstring); free(pstruct); } if (istty) printf("\n energy = %6.2f\n", energy); else printf(" (%6.2f)\n", energy); /* clean up */ (void) fflush(stdout); if(rec_id) free(rec_id); free(rec_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 = structure = NULL; rec_rest = NULL; free(string); free(orig_sequence); string = orig_sequence = NULL; /* print user help for the next round if we get input from tty */ if(istty){ print_tty_input_seq_str("Use '&' to connect 2 sequences that shall form a complex.\n" "Input sequence (upper or lower case) followed by structure"); } } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { char *string/*, *line*/; char *structure=NULL, *cstruc=NULL; /*char fname[53], ffname[60]; */ /*char *ParamFile=NULL; */ char *ns_bases=NULL, *c; char *Concfile; int i, length, l, sym/*, r*/; double min_en; double kT, sfact=1.07; int pf=0, istty; int noconv=0; int doT=0; /*compute dimere free energies etc.*/ int doC=0; /*toggle to compute concentrations*/ int doQ=0; /*toggle to compute prob of base being paired*/ int cofi=0; /*toggle concentrations stdin / file*/ struct plist *prAB; struct plist *prAA; /*pair probabilities of AA dimer*/ struct plist *prBB; struct plist *prA; struct plist *prB; struct plist *mfAB; struct plist *mfAA; /*pair mfobabilities of AA dimer*/ struct plist *mfBB; struct plist *mfA; struct plist *mfB; double *ConcAandB; AjPSeq seq1 = NULL; AjPFile confile1 = NULL; AjPSeq seq2 = NULL; AjPFile confile2 = NULL; AjPFile concfile = NULL; AjPFile paramfile = NULL; AjPFile outf = NULL; AjPFile essfile = NULL; AjPFile dotfile = NULL; AjPFile aoutf = NULL; AjPFile aaoutf = NULL; AjPFile boutf = NULL; AjPFile bboutf = NULL; AjPFile aboutf = NULL; AjPStr seqstring1 = NULL; AjPStr constring1 = NULL; AjPStr constring2 = NULL; float eT = 0.; AjBool eGU; 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'; /* AjBool dimers; */ /* AjBool paired; */ embInitPV("vrnacofold",argc,argv,"VIENNA",VERSION); seqstring1 = ajStrNew(); constring1 = ajStrNew(); constring2 = ajStrNew(); seq1 = ajAcdGetSeq("asequence"); confile1 = ajAcdGetInfile("aconstraintfile"); seq2 = ajAcdGetSeq("bsequence"); confile2 = ajAcdGetInfile("bconstraintfile"); paramfile = ajAcdGetInfile("paramfile"); eT = ajAcdGetFloat("temperature"); 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"); /* dimers = ajAcdGetBoolean("dimers"); */ /* paired = ajAcdGetBoolean("paired"); */ outf = ajAcdGetOutfile("outfile"); essfile = ajAcdGetOutfile("ssoutfile"); /* concfile = ajAcdGetInfile("concentrationfile"); */ /* dotfile = ajAcdGetOutfile("dotoutfile"); */ /* aoutf = ajAcdGetOutfile("aoutfile"); aaoutf = ajAcdGetOutfile("aaoutfile"); boutf = ajAcdGetOutfile("boutfile"); bboutf = ajAcdGetOutfile("bboutfile"); aboutf = ajAcdGetOutfile("aboutfile"); */ do_backtrack = 1; pf = 0; doT = 0; doC = 0; cofi = 0; doQ = 0; string = NULL; Concfile = NULL; 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; 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(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++; } } cut_point = -1; ajFmtPrintS(&seqstring1,"%s&%s",ajSeqGetSeqC(seq1),ajSeqGetSeqC(seq2)); string = tokenize(MAJSTRGETPTR(seqstring1)); /* frees line */ length = (int) strlen(string); if (doC) { ConcAandB = read_concentrations(concfile); } structure = (char *) space((unsigned) length+1); if(confile1) { vienna_GetConstraints(confile1,&constring1); vienna_GetConstraints(confile2,&constring2); ajStrAppendK(&constring1,'&'); ajStrAppendS(&constring1,constring2); cstruc = tokenize(MAJSTRGETPTR(constring1)); if (cstruc!=NULL) strncpy(structure, cstruc, length); else ajFatal("Constraints missing\n"); } for (l = 0; l < length; l++) { string[l] = toupper(string[l]); if (!noconv && string[l] == 'T') string[l] = 'U'; } /*compute mfe of AB dimer*/ min_en = cofold(string, structure); mfAB=(struct plist *) space(sizeof(struct plist) * (length+1)); mfAB=get_mfe_plist(mfAB); if (cut_point == -1) ajFmtPrintF(outf,"%s\n%s", string, structure); /*no cofold*/ else { char *pstring, *pstruct; pstring = costring(string); pstruct = costring(structure); ajFmtPrintF(outf,"%s\n%s", pstring, pstruct); free(pstring); free(pstruct); } ajFmtPrintF(outf," (%6.2f)\n", min_en); if (length<2000) (void) PS_rna_plot(string, structure, essfile); else { ajWarn("Structure too long, not doing xy_plot\n"); free_co_arrays(); } /*compute partition function*/ if (pf) { cofoldF AB, AA, BB; 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) ajWarn("scaling factor %f\n", pf_scale); init_co_pf_fold(length); if (cstruc!=NULL) strncpy(structure, cstruc, length+1); AB = co_pf_fold(string, structure); if (do_backtrack) { char *costruc; costruc = (char *) space(sizeof(char)*(strlen(structure)+2)); if (cut_point<0) ajFmtPrintF(outf,"%s", structure); else { strncpy(costruc, structure, cut_point-1); strcat(costruc, "&"); strcat(costruc, structure+cut_point-1); ajFmtPrintF(outf,"%s", costruc); } ajFmtPrintF(outf," [%6.2f]\n", AB.FAB); } if ((istty)||(!do_backtrack)) ajFmtPrintF(outf," free energy of ensemble = %6.2f kcal/mol\n", AB.FAB); ajFmtPrintF(outf," frequency of mfe structure in ensemble %g", exp((AB.FAB-min_en)/kT)); ajFmtPrintF(outf," , delta G binding=%6.2f\n", AB.FcAB - AB.FA - AB.FB); prAB=(struct plist *) space(sizeof(struct plist) * (2*length)); prAB=get_plist(prAB, length,0.00001); /* 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; char *Newstring; /*char Newname[30];*/ char comment[80]; if (cut_point<0) { free(mfAB); free(prAB); ajFatal("Sorry, I cannot do that with only one molecule, " "please give me two\n"); } if (dangles==1) dangles=2; Alength=cut_point-1; /*length of first molecule*/ Blength=length-cut_point+1; /*length of 2nd molecule*/ /*Sequence of first molecule*/ Astring=(char *)space(sizeof(char)*(Alength+1)); /*Sequence of second molecule*/ Bstring=(char *)space(sizeof(char)*(Blength+1)); strncat(Astring,string,Alength); strncat(Bstring,string+Alength,Blength); /* compute AA dimer */ prAA=(struct plist *) space(sizeof(struct plist) * (4*Alength)); mfAA=(struct plist *) space(sizeof(struct plist) * (Alength+1)); AA=do_partfunc(Astring, Alength, 2, &prAA, &mfAA); /* compute BB dimer */ prBB=(struct plist *) space(sizeof(struct plist) * (4*Blength)); mfBB=(struct plist *) space(sizeof(struct plist) * (Blength+1)); BB=do_partfunc(Bstring, Blength, 2, &prBB, &mfBB); /*free_co_pf_arrays();*/ /* compute A monomer */ prA=(struct plist *) space(sizeof(struct plist) * (2*Alength)); mfA=(struct plist *) space(sizeof(struct plist) * (Alength+1)); do_partfunc(Astring, Alength, 1, &prA, &mfA); /* compute B monomer */ prB=(struct plist *) space(sizeof(struct plist) * (2*Blength)); mfB=(struct plist *) space(sizeof(struct plist) * (Blength+1)); do_partfunc(Bstring, Blength, 1, &prB, &mfB); 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); ajFmtPrintF(outf,"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, outf); free(ConcAandB);/*freeen*/ } /*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; (void)PS_dot_plot_list(string, aboutf, prAB, mfAB, comment); /*AA dot_plot*/ sprintf(comment,"\n%%Homodimer AA FreeEnergy= %.9f\n",AA.FcAB); /*write AA sequence*/ Newstring=(char*)space((2*Alength+1)*sizeof(char)); strcpy(Newstring,Astring); strcat(Newstring,Astring); (void)PS_dot_plot_list(Newstring, aaoutf, prAA, mfAA, comment); free(Newstring); /*BB dot_plot*/ sprintf(comment,"\n%%Homodimer BB FreeEnergy= %.9f\n",BB.FcAB); /*write BB sequence*/ Newstring=(char*)space((2*Blength+1)*sizeof(char)); strcpy(Newstring,Bstring); strcat(Newstring,Bstring); /*reset cut_point*/ cut_point=Blength+1; (void)PS_dot_plot_list(Newstring, bboutf, 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 A sequence*/ (void)PS_dot_plot_list(Astring, aoutf, prA, mfA, comment); /*B monomer dot plot*/ sprintf(comment,"\n%%Monomer B FreeEnergy= %.9f\n",AB.FB); /*write B sequence*/ (void)PS_dot_plot_list(Bstring, boutf, prB, mfB, comment); free(Astring); free(Bstring); free(prAB); free(prAA); free(prBB); free(prA); free(prB); free(mfAB); free(mfAA); free(mfBB); free(mfA); free(mfB); } /*end if(doT)*/ }/*end if(pf)*/ if (do_backtrack) { if (!doT) { if (pf) { (void) PS_dot_plot_list(string, dotfile, prAB, mfAB, "doof"); free(prAB); } free(mfAB); } } if (!doT) free_co_pf_arrays(); if (cstruc!=NULL) free(cstruc); free(string); free(structure); ajStrDel(&seqstring1); ajStrDel(&constring1); ajStrDel(&constring2); ajSeqDel(&seq1); ajSeqDel(&seq2); ajStrDel(&ensbases); ajStrDel(&eenergy); ajStrDel(&edangles); ajFileClose(&confile1); ajFileClose(&confile2); ajFileClose(¶mfile); ajFileClose(&outf); ajFileClose(&essfile); if (length<2000) free_co_arrays(); embExit(); return 0; }
int sel_nb(void) { char trans, **s; int next, i; double pegel = 0.0, schwelle = 0.0, zufall = 0.0; int found_stop=0; /* before we select a move, store current conformation in cache */ /* ... unless it just came from there */ if ( !is_from_cache ) put_in_cache(); else /* laplace stuff */ for (i=0; i<top; i++) { L += (GSV.currE - energies[i]); D++; } is_from_cache = 0; /* draw 2 different a random number */ schwelle = urn(); while ( zufall==0 ) zufall = urn(); /* advance internal clock */ if (totalflux>0) zeitInc = (log(1. / zufall) / totalflux); else { if (GSV.grow>0) zeitInc=GSV.grow; else zeitInc = GSV.time; } Zeit += zeitInc; /* laplace stuff */ sumK += L*zeitInc; sumKK += L*L*zeitInc; sumD += D*zeitInc; if (GSV.grow>0 && GSV.len < strlen(GAV.farbe_full)) grow_chain(); /* meanE /= (double)top; */ /* normalize boltzmann weights */ schwelle *=totalflux; /* and choose a neighbour structure next */ for (next = 0; next < top; next++) { pegel += bmf[next]; if (pegel > schwelle) break; } /* in case of rounding errors */ if (next==top) next=top-1; /* process termination contitiones */ /* is current structure identical to a stop structure ?*/ for (found_stop = 0, s = GAV.stopform; *s; s++) { if (strcmp(*s, GAV.currform) == 0) { found_stop = (s - GAV.stopform) + 1; break; } } if ( ((found_stop > 0) && (GTV.fpt == 1)) || (Zeit > GSV.time) ) { /* met condition to stop simulation */ /* laplace stuff */ double K, KK, N, sigma; K = sumK/Zeit; KK = sumKK/Zeit; N = sumD/Zeit; /* graph Laplacian is - Laplace-Beltrami operator */ sigma = -1.0*sqrt((KK-K*K)/N)/(K/N); /* this goes to stdout */ if ( !GTV.silent ) { printf("%s %6.2f %10.3f", costring(GAV.currform), GSV.currE, Zeit); /* laplace stuff*/ if (GTV.phi) printf(" %8.3f %8.3f %3g", zeitInc, L, D); if (GTV.verbose) printf(" %4d _ %d", top, lmin); if (found_stop) printf(" X%d\n", found_stop);/* found a stop structure */ else printf(" O\n"); /* time for simulation is exceeded */ /* laplace stuff */ if (GTV.phi) printf("Curvature fluctuation sigma = %7.5f\n", sigma); fflush(stdout); } /* this goes to log */ /* comment log steps of simulation as well !!! %6.2f round */ if ( found_stop ) { fprintf(logFP," X%02d %12.3f", found_stop, Zeit); /* laplace stuff */ if (GTV.phi) fprintf(logFP, " %3g %7.5f", GSV.phi, sigma); fprintf(logFP,"\n"); } else { fprintf(logFP," O %12.3f", Zeit); /* laplace stuff */ if (GTV.phi) fprintf(logFP, " %3g %7.5f", GSV.phi, sigma); fprintf(logFP," %d %s\n", lmin, costring(GAV.currform)); } GAV.subi[0] = xsubi[0]; GAV.subi[1] = xsubi[1]; GAV.subi[2] = xsubi[2]; fprintf(logFP, "(%5hu %5hu %5hu)", GAV.subi[0], GAV.subi[1], GAV.subi[2]); fflush(logFP); Zeit = 0.0; /* reset laplace stuff for next trajectory */ sumT = 0.0; sumK = 0.0; sumKK = 0.0; sumD = 0.0; L = 0.0; D = 0.0; /* highestE = OhighestE = -1000.0; */ reset_nbList(); costring(NULL); return(1); } else { /* continue simulation */ int flag = 0; if( (!GTV.silent) && (GSV.currE <= GSV.stopE+GSV.cut) ) { if (!GTV.lmin || (lmin==1 && strcmp(GAV.prevform, GAV.currform) != 0)) { char format[64]; flag = 1; sprintf(format, "%%-%ds %%6.2f %%10.3f", strlen(GAV.farbe_full)+1); printf(format, costring(GAV.currform), GSV.currE, Zeit); } /* laplace stuff */ if (GTV.phi) { printf(" %8.3f %8.3f %3g", zeitInc, L, D); L = D = 0.0; /* reset L and D for next structure */ } if ( flag && GTV.verbose ) { int ii, jj; if (next<0) trans='g'; /* growth */ else { ii = neighbor_list[2*next]; jj = neighbor_list[2*next+1]; if (abs(ii) < GSV.len) { if ((ii > 0) && (jj > 0)) trans = 'i'; else if ((ii < 0) && (jj < 0)) trans = 'd'; else if ((ii > 0) && (jj < 0)) trans = 's'; else trans = 'S'; } else { if ((ii > 0) && (jj > 0)) trans = 'I'; else trans = 'D'; } } printf(" %4d %c %d", top, trans, lmin); } if (flag) printf("\n"); } } /* store last lmin seen, so we can avoid printing the same lmin twice */ if (lmin==1) strcpy(GAV.prevform, GAV.currform); #if 0 if (lmin==1) { /* went back to previous lmin */ if (strcmp(GAV.prevform, GAV.currform) == 0) { if (OhighestE < highestE) { highestE = OhighestE; /* delete loop */ strcpy(highestS, OhighestS); } } else { strcpy(GAV.prevform, GAV.currform); OhighestE = 10000.; } } if ( strcmp(GAV.currform, GAV.startform)==0 ) { OhighestE = highestE = -1000.; highestS[0] = 0; } /* log highes energy */ if (GSV.currE > highestE) { OhighestE = highestE; highestE = GSV.currE; strcpy(OhighestS, highestS); strcpy(highestS, GAV.currform); } #endif if (next>=0) update_tree(neighbor_list[2*next], neighbor_list[2*next+1]); else { clean_up_rl(); ini_or_reset_rl(); } reset_nbList(); return(0); }
int main(int argc, char *argv[]) { char *string, *line; char *structure=NULL, *cstruc=NULL; char fname[53], ffname[60]; char *ParamFile=NULL; char *ns_bases=NULL, *c; char *Concfile; int i, length, l, sym, r; double min_en; double kT, sfact=1.07; int pf=0, istty; int noconv=0; int doT=0; /*compute dimere free energies etc.*/ int doC=0; /*toggle to compute concentrations*/ int doQ=0; /*toggle to compute prob of base being paired*/ int cofi=0; /*toggle concentrations stdin / file*/ struct plist *prAB; struct plist *prAA; /*pair probabilities of AA dimer*/ struct plist *prBB; struct plist *prA; struct plist *prB; struct plist *mfAB; struct plist *mfAA; /*pair mfobabilities of AA dimer*/ struct plist *mfBB; struct plist *mfA; struct plist *mfB; double *ConcAandB; do_backtrack = 1; string=NULL; Concfile=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], "-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 '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; case 'a': doT=1; pf=1; break; case 'c':/*concentrations from stdin*/ doC=1; doT=1; pf=1; break; case 'f':/*concentrations in file*/ if (i==argc-1) usage(); Concfile = argv[++i]; doC=1; cofi=1; doT=1; pf=1; break; case 'q': pf=1; doQ=1; break; default: 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!='\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 */ cut_point = -1; if (istty) { printf("\nInput sequence(s); @ to quit\n"); printf("Use '&' as spearator between 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, ">%51s", fname); printf("%s\n", line); free(line); if ((line = get_line(stdin))==NULL) break; } if ((line ==NULL) || (strcmp(line, "@") == 0)) break; string = tokenize(line); /* frees line */ length = (int) strlen(string); 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); } } structure = (char *) space((unsigned) length+1); if (fold_constrained) { cstruc = tokenize(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) { if (cut_point == -1) printf("length = %d\n", length); else printf("length1 = %d\nlength2 = %d\n", cut_point-1, length-cut_point+1); } /*compute mfe of AB dimer*/ min_en = cofold(string, structure); mfAB=(struct plist *) space(sizeof(struct plist) * (length+1)); mfAB=get_mfe_plist(mfAB); if (cut_point == -1) printf("%s\n%s", string, structure); /*no cofold*/ else { char *pstring, *pstruct; pstring = costring(string); pstruct = costring(structure); printf("%s\n%s", pstring, pstruct); free(pstring); free(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 (fname[0]!='\0') { strcpy(ffname, fname); strcat(ffname, "_ss.ps"); } else { strcpy(ffname, "rna.ps"); } if (length<2000) (void) PS_rna_plot(string, structure, ffname); else { fprintf(stderr,"INFO: structure too long, not doing xy_plot\n"); free_co_arrays(); } /*compute partition function*/ if (pf) { cofoldF AB, AA, BB; 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_co_pf_fold(length); if (cstruc!=NULL) strncpy(structure, cstruc, length+1); AB = co_pf_fold(string, structure); 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); prAB=(struct plist *) space(sizeof(struct plist) * (2*length)); prAB=get_plist(prAB, length,0.00001); /* 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; 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,string,Alength); strncat(Bstring,string+Alength,Blength); /* compute AA dimer */ prAA=(struct plist *) space(sizeof(struct plist) * (4*Alength)); mfAA=(struct plist *) space(sizeof(struct plist) * (Alength+1)); AA=do_partfunc(Astring, Alength, 2, &prAA, &mfAA); /* compute BB dimer */ prBB=(struct plist *) space(sizeof(struct plist) * (4*Blength)); mfBB=(struct plist *) space(sizeof(struct plist) * (Blength+1)); BB=do_partfunc(Bstring, Blength, 2, &prBB, &mfBB); /*free_co_pf_arrays();*/ /* compute A monomer */ prA=(struct plist *) space(sizeof(struct plist) * (2*Alength)); mfA=(struct plist *) space(sizeof(struct plist) * (Alength+1)); do_partfunc(Astring, Alength, 1, &prA, &mfA); /* compute B monomer */ prB=(struct plist *) space(sizeof(struct plist) * (2*Blength)); mfB=(struct plist *) space(sizeof(struct plist) * (Blength+1)); do_partfunc(Bstring, Blength, 1, &prB, &mfB); 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(string, 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,Astring); strcat(Newstring,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,Bstring); strcat(Newstring,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(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(Bstring, Newname, prB, mfB, comment); free(Astring); free(Bstring); free(prAB); free(prAA); free(prBB); free(prA); free(prB); free(mfAB); free(mfAA); free(mfBB); free(mfA); free(mfB); } /*end if(doT)*/ }/*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(string, ffname, prAB, mfAB, "doof"); free(prAB); } free(mfAB); } } if (!doT) free_co_pf_arrays(); if (cstruc!=NULL) free(cstruc); (void) fflush(stdout); free(string); free(structure); } while (1); return 0; }