PRIVATE cofoldF do_partfunc(char *string, int length, int Switch, struct plist **tpr, struct plist **mfpl) { /*compute mfe and partition function of dimere or monomer*/ char *Newstring; char *tempstruc; double min_en; double sfact=1.07; double kT; cofoldF X; kT = (temperature+273.15)*1.98717/1000.; switch (Switch) { case 1: /*monomer*/ cut_point=-1; tempstruc = (char *) space((unsigned)length+1); min_en = fold(string, tempstruc); pf_scale = exp(-(sfact*min_en)/kT/(length)); *mfpl=get_mfe_plist(*mfpl); free_arrays(); /*En=pf_fold(string, tempstruc);*/ init_co_pf_fold(length); X=co_pf_fold(string, tempstruc); *tpr=get_plist(*tpr, length,0.00001); free_co_pf_arrays(); free(tempstruc); break; case 2: /*dimer*/ Newstring=(char *)space(sizeof(char)*(length*2+1)); strcat(Newstring,string); strcat(Newstring,string); cut_point=length+1; tempstruc = (char *) space((unsigned)length*2+1); min_en = cofold(Newstring, tempstruc); pf_scale =exp(-(sfact*min_en)/kT/(2*length)); *mfpl=get_mfe_plist(*mfpl); free_co_arrays(); init_co_pf_fold(2*length); X=co_pf_fold(Newstring, tempstruc); *tpr=get_plist(*tpr, 2*length,0.00001); free_co_pf_arrays(); free(Newstring); free(tempstruc); break; default: printf("Error in get_partfunc\n, computing neither mono- nor dimere!\n"); exit (42); } return X; }
/* PUBLIC */ Plist copy_plist_of_terms(Plist terms) { if (terms == NULL) return NULL; else { Plist tail = copy_plist_of_terms(terms->next); Plist head = get_plist(); head->v = copy_term(terms->v); head->next = tail; return head; } } /* copy_plist_of_terms */
static void linear_insert(Mindex mdx, Term t) { Plist p = get_plist(); p->v = t; p->next = NULL; if (mdx->linear_last != NULL) mdx->linear_last->next = p; else mdx->linear_first = p; mdx->linear_last = p; } /* linear_insert */
static Discrim discrim_bind_end(Term t, Discrim d, Plist *path_p) { Discrim d1; Plist dp; int symbol, sym; /* add current node to the front of the path list. */ dp = get_plist(); dp->v = d; dp->next = *path_p; *path_p = dp; if (VARIABLE(t)) { d1 = d->u.kids; symbol = VARNUM(t); while (d1 && DVAR(d1) && d1->symbol < symbol) d1 = d1->next; if (d1 == NULL || !DVAR(d1) || d1->symbol != symbol) return NULL; else /* found node */ return d1; } else { /* constant || complex */ d1 = d->u.kids; sym = SYMNUM(t); /* arities fixed: handle both NAME and COMPLEX */ while (d1 && DVAR(d1)) /* skip variables */ d1 = d1->next; while (d1 && d1->symbol < sym) d1 = d1->next; if (d1 == NULL || d1->symbol != sym) return NULL; else { int i; for (i = 0; d1 && i < ARITY(t); i++) d1 = discrim_bind_end(ARG(t,i), d1, path_p); return d1; } } } /* discrim_bind_end */
static void discrim_bind_insert(Term t, Discrim root, void *object) { Discrim d; Plist gp1, gp2; d = discrim_bind_insert_rec(t, root); gp1 = get_plist(); gp1->v = object; gp1->next = NULL; /* Install at end of list. */ if (d->u.data == NULL) d->u.data = gp1; else { for (gp2 = d->u.data; gp2->next != NULL; gp2 = gp2->next); gp2->next = gp1; } } /* discrim_bind_insert */
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; }
/* * The event loop for display. It displays data on screen and handles hotkey * presses. * * Parameter : * duration - returns after 'duration' * * The function also returns if user presses 'q', 'Ctrl+C' or 'r'. * * Return value: * 0 - main() exits * 1 - main() calls it again */ int lt_display_loop(int duration) { uint64_t start; int remaining; struct timeval timeout; fd_set read_fd; int need_refresh = TRUE; pid_t *plist = NULL; id_t *tlist = NULL; int list_len = 0; int list_index = 0; int retval = 1; int next_snap; int gpipe; start = lt_millisecond(); gpipe = lt_gpipe_readfd(); if (!show_help) { print_hint(NULL); print_sysglobal(); } get_plist(&plist, &tlist, &list_len, &list_index); for (;;) { if (need_refresh && !show_help) { if (list_len != 0) { if (!thread_mode) { print_taskbar_process(plist, list_len, list_index); print_process(plist[list_index]); } else { print_taskbar_thread(plist, tlist, list_len, list_index); print_thread(plist[list_index], tlist[list_index]); } } else { print_empty_process_bar(); } } need_refresh = TRUE; /* Usually we need refresh. */ remaining = duration - (int)(lt_millisecond() - start); if (remaining <= 0) { break; } /* Embedded dtrace snap action here. */ next_snap = lt_dtrace_work(0); if (next_snap == 0) { /* * Just did a snap, check time for the next one. */ next_snap = lt_dtrace_work(0); } if (next_snap > 0 && remaining > next_snap) { remaining = next_snap; } timeout.tv_sec = remaining / 1000; timeout.tv_usec = (remaining % 1000) * 1000; FD_ZERO(&read_fd); FD_SET(0, &read_fd); FD_SET(gpipe, &read_fd); /* Wait for keyboard input, or signal from gpipe */ if (select(gpipe + 1, &read_fd, NULL, NULL, &timeout) > 0) { int k = 0; if (FD_ISSET(gpipe, &read_fd)) { /* Data from pipe has priority */ char ch; (void) read(gpipe, &ch, 1); k = ch; /* Need this for big-endianness */ } else { k = getch(); } /* * Check if we need to update the hint line whenever we * get a chance. * NOTE: current implementation depends on * g_config.lt_cfg_snap_interval, but it's OK because it * doesn't have to be precise. */ print_hint(NULL); /* * If help is on display right now, and a key press * happens, we need to clear the help and continue. */ if (show_help) { (void) werase(stdscr); (void) refresh(); print_title(); print_sysglobal(); show_help = FALSE; /* Drop this key and continue */ continue; } switch (k) { case 'Q': case 'q': retval = 0; goto quit; case 'R': case 'r': lt_display_deinit(); lt_display_init(); goto quit; case 'H': case 'h': show_help = TRUE; (void) werase(stdscr); (void) refresh(); print_help(); break; case ',': case '<': case KEY_LEFT: --list_index; if (list_index < 0) { list_index = 0; } break; case '.': case '>': case KEY_RIGHT: ++list_index; if (list_index >= list_len) { list_index = list_len - 1; } break; case 'a': case 'A': sort_type = LT_SORT_AVG; print_sysglobal(); break; case 'p': case 'P': sort_type = LT_SORT_TOTAL; print_sysglobal(); break; case 'm': case 'M': sort_type = LT_SORT_MAX; print_sysglobal(); break; case 'c': case 'C': sort_type = LT_SORT_COUNT; print_sysglobal(); break; case 't': case 'T': if (plist != NULL) { selected_pid = plist[list_index]; } selected_tid = INVALID_TID; thread_mode = !thread_mode; get_plist(&plist, &tlist, &list_len, &list_index); break; case '1': case '!': current_list_type = LT_LIST_CAUSE; print_sysglobal(); break; case '2': case '@': if (g_config.lt_cfg_low_overhead_mode) { lt_display_error("Switching mode is " "not available for '-f low'."); } else { current_list_type = LT_LIST_SPECIALS; print_sysglobal(); } break; case '3': case '#': if (g_config.lt_cfg_trace_syncobj) { current_list_type = LT_LIST_SOBJ; print_sysglobal(); } else if (g_config.lt_cfg_low_overhead_mode) { lt_display_error("Switching mode is " "not available for '-f low'."); } else { lt_display_error("Tracing " "synchronization objects is " "disabled."); } break; default: /* Wake up for nothing; no refresh is needed */ need_refresh = FALSE; break; } } else { need_refresh = FALSE; } } quit: if (plist != NULL) { selected_pid = plist[list_index]; } if (tlist != NULL) { selected_tid = tlist[list_index]; } lt_stat_proc_list_free(plist, tlist); return (retval); }
int main(int argc, char *argv[]) { int i; char *file_name; if (argc < 2) { print_usage(argv[0]); exit(1); } while ((i = getopt (argc, argv, "Dludbv")) != EOF) { switch (i){ case 'l': optflag |= LIST; break; case 'd': optflag |= DIAG; break; case 'v': optflag |= VIEW; break; case 'b': optflag |= BIN; break; case 'u': optflag |= VIEWUDP; break; case 'D': optflag |= VERBOSE; break; default: print_usage(argv[0]); exit(0); } } /* * snoop ファイルを open 必須 */ if(argc == 3) file_name = argv[2]; else file_name = argv[1]; if( sn_open(file_name) < 0){ perror("sn_open()"); exit(0); } /* * packet 数(count)を得る 必須 */ if (sn_count() < 0){ perror("sn_count()"); exit(0); } /* * packet のリスト(plist_head)を得る 必須 */ if ( get_plist() < 0){ perror("get_plist()"); exit(0); } /* * packet を読む 必須 */ if ( read_packet() < 0){ perror("read_packet()"); exit(0); } /* * connection list * と udp port pair list を見る オプション */ if(optflag & LIST){ if ( read_conn_list() <0 ) { perror("read_conn_list()"); exit(0); } if ( read_pair_list() <0 ) { perror("read_pair_list()"); exit(0); } } /* * 各 connection の packet の流れを表示 オプション * 追加オプションによって、packet の ack を確認等を行う */ if(optflag & (VIEW|DIAG)){ if ( view_conn() < 0 ) { perror("view_conn()"); exit(0); } } /* * 各 UDP port pair の packet の流れを表示 オプション * 追加オプションはまだ未実装 */ if(optflag & (VIEWUDP)){ if ( view_pair(optflag) < 0 ) { perror("view_pair()"); exit(0); } } /* * 各 connection の 各方向毎の TCP の data 部をファイルとして保存。 * file 名 は <src IP>.<src port>-<dest IP>.<dest port> */ if(optflag & BIN){ if ( mkbin() <0 ) { perror("mkbin()"); exit(0); } } 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; }