PUBLIC duplexT *duplex_subopt(const char *s1, const char *s2, int delta, int w) { int i,j, n1, n2, thresh, E, n_subopt=0, n_max; char *struc; duplexT mfe; duplexT *subopt; n_max=16; subopt = (duplexT *) space(n_max*sizeof(duplexT)); delay_free=1; mfe = duplexfold(s1, s2); free(mfe.structure); thresh = (int) mfe.energy*100+0.1 + delta; n1 = strlen(s1); n2=strlen(s2); for (i=n1; i>0; i--) { for (j=1; j<=n2; j++) { int type; type = pair[S2[j]][S1[i]]; if (!type) continue; E = c[i][j]; if (i<n1) E += P->dangle3[type][SS1[i+1]]; if (j>1) E += P->dangle5[type][SS2[j-1]]; if (type>2) E += P->TerminalAU; if (E<=thresh) { struc = backtrack(i,j); #if 0 int l1; l1 = strchr(struc, '&')-struc; printf("%s %3d,%-3d : %3d,%-3d (%5.2f)\n", struc, i+2-l1, i+1, j-1, j+strlen(struc)-l1-3, E*0.01); #endif if (n_subopt+1>=n_max) { n_max *= 2; subopt = (duplexT *) xrealloc(subopt, n_max*sizeof(duplexT)); } subopt[n_subopt].i = MIN2(i+1,n1); subopt[n_subopt].j = MAX2(j-1,1); subopt[n_subopt].energy = E * 0.01; subopt[n_subopt++].structure = struc; } } } for (i=1; i<=n1; i++) free(c[i]); free(c); free(S1); free(S2); free(SS1); free(SS2); delay_free=0; if (subopt_sorted) qsort(subopt, n_subopt, sizeof(duplexT), compare); subopt[n_subopt].i =0; subopt[n_subopt].j =0; subopt[n_subopt].structure = NULL; return subopt; }
void ffiwrap_duplexfold (duplexT * x, char * linp, char * rinp) { *x = duplexfold (linp, rinp); return; }
int main(int argc, char *argv[]) { char *s1, *s2, *line; char fname[13]; char *ParamFile=NULL; char *ns_bases=NULL, *c; int i, l, sym, r; double deltaf; double kT, sfact=1.07; int pf=0, istty, delta=-1; int noconv=0; 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': fprintf(stderr, "partition function folding not yet implemented\n"); usage(); 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], "%lf", &deltaf); if (r!=1) usage(); delta = (int) (0.1+deltaf*100); break; case 's': subopt_sorted=1; break; case 'd': dangles=0; if (argv[i][2]!='\0') { r=sscanf(argv[i]+2, "%d", &dangles); if (r!=1) usage(); } break; case 'P': if (i==argc-1) usage(); ParamFile = argv[++i]; break; default: usage(); } } if (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)); do { /* main loop: continue until end of file */ duplexT mfe, *subopt; if (istty) { printf("\nInput two sequences (one line each); @ to quit\n"); printf("%s\n", scale); } fname[0]='\0'; if ((line = get_line(stdin))==NULL) break; /* skip empty lines, comment lines, name lines */ while (line && ((*line=='*')||(*line=='\0')||(*line=='>'))) { printf("%s\n", line); free(line); if ((line = get_line(stdin))==NULL) break; } if ((line ==NULL) || (strcmp(line, "@") == 0)) break; s1 = (char *) space(strlen(line)+1); (void) sscanf(line,"%s",s1); free(line); if ((line = get_line(stdin))==NULL) break; /* skip comment lines and get filenames */ while ((*line=='*')||(*line=='\0')||(*line=='>')) { printf("%s\n", line); free(line); if ((line = get_line(stdin))==NULL) break; } if ((line ==NULL) || (strcmp(line, "@") == 0)) break; s2 = (char *) space(strlen(line)+1); (void) sscanf(line,"%s",s2); free(line); for (l = 0; l < strlen(s1); l++) { s1[l] = toupper(s1[l]); if (!noconv && s1[l] == 'T') s1[l] = 'U'; } for (l = 0; l < strlen(s2); l++) { s2[l] = toupper(s2[l]); if (!noconv && s2[l] == 'T') s2[l] = 'U'; } if (istty) printf("lengths = %d,%d\n", strlen(s1), strlen(s2)); /* initialize_fold(length); */ update_fold_params(); if (delta>=0) { duplexT *sub; subopt = duplex_subopt(s1, s2, delta, 5); for (sub=subopt; sub->i >0; sub++) { print_struc(sub); free(sub->structure); } free(subopt); } else { mfe = duplexfold(s1, s2); print_struc(&mfe); free(mfe.structure); } (void) fflush(stdout); (void) fflush(stdout); free(s1); free(s2); } while (1); return 0; }
PRIVATE void print_interaction(interact *Int, char *s1, char *s2, pu_contrib *p_c, pu_contrib *p_c2, int w, int incr3, int incr5) { char *i_long,*i_short; int i,len, l_l, l_s, len1, end5, end3, i_min, j_min, l1, add_a, add_b,nix_up; double p_c_S; double G_min,Gi_min,Gul, G_sum, Gus, diff; duplexT mfe; char *struc; G_min = Int->Gikjl; Gi_min = Int->Gikjl_wo; len1 = Int->length; len=strlen(s1)+strlen(s2); /* use duplexfold() to fold the interaction site */ l_l = (Int->i-Int->k+1); i_long = (char*)space(sizeof(char)*(l_l+1)); l_s = (Int->l-Int->j+1); i_short = (char*)space(sizeof(char)*(l_s+1)); strncpy(i_long,&s1[Int->k-1],l_l); i_long[l_l] = '\0'; strncpy(i_short,&s2[Int->j-1],l_s); i_short[l_s] = '\0'; mfe = duplexfold(i_long,i_short); i_min = mfe.i; j_min = mfe.j ; l1 = strchr(mfe.structure, '&')-mfe.structure; /* printf("%s %3d,%-3d : %3d,%-3d (%5.2f)\n", mfe.structure, i_min+1-l1, i_min, j_min, j_min+strlen(mfe.structure)-l1-2, mfe.energy ); */ /* structure by duplexfold is shorter than structure by RNAup:*/ add_a = add_b = 0; /* length difference in longer / shorter sequence*/ nix_up = 0; if(((i_min+1-l1) - i_min) != ( Int->k - Int->i)) { add_a = Int->i - Int->k + 2; } if(((j_min+strlen(mfe.structure)-l1-2) - j_min) != (Int->l - Int->j)) { add_b = Int->l - Int->j +2; } /* printf("add_a %d add_b %d\n",add_a,add_b); */ if( add_a || add_b ) { nix_up = 1; if(add_a && add_b == 0) add_b = Int->l - Int->j + 2; if(add_a == 0 && add_b) add_a = Int->i - Int->k + 2; struc = (char*)space(sizeof(char)*(add_a+add_b+3)); for(i=0;i<(add_a+add_b-1);i++) { if(i != l_l) struc[i] = '.'; if(i == l_l) struc[i] = '&'; } struc[i] = '\0'; } else { l1=strlen(mfe.structure); struc = (char*)space(sizeof(char)*(l1+1)); strcpy(struc,mfe.structure); } end5 = MAX(1,Int->k-incr5); end3 = MIN(MIN(l_l-1+incr3,w+incr3+incr5),len1); p_c_S = p_c->H[end5][end3]+p_c->I[end5][end3]+p_c->M[end5][end3]+p_c->E[end5][end3]; Gul = -RT*log(p_c_S); if (p_c2 == NULL) { G_sum = Gi_min + Gul; /* printf("dG = dGint + dGu_l\n"); */ printf("%s %3d,%-3d : %3d,%-3d (%.2f = %.2f + %.2f)\n", struc, Int->k, Int->i, Int->j, Int->l, G_min, Gi_min, Gul); printf("%s&%s\n",i_long,i_short); } else { p_c_S = p_c2->H[Int->j][(Int->l)-(Int->j)]+ p_c2->I[Int->j][(Int->l)-(Int->j)]+ p_c2->M[Int->j][(Int->l)-(Int->j)]+ p_c2->E[Int->j][(Int->l)-(Int->j)]; Gus = -RT*log(p_c_S); G_sum = Gi_min + Gul +Gus; /* printf("dG = dGint + dGu_l + dGu_s\n"); */ printf("%s %3d,%-3d : %3d,%-3d (%.2f = %.2f + %.2f + %.2f)\n", struc, Int->k, Int->i, Int->j, Int->l, G_min, Gi_min, Gul, Gus); printf("%s&%s\n",i_long,i_short); } if (!EQUAL(G_min,G_sum)) { printf("ERROR\n"); diff = fabs((G_min)-(G_sum)); printf("diff %.18f\n",diff); } if(nix_up) fprintf(stderr,"RNAduplex structure doesn't match any structure of RNAup structure ensemble\n"); free(i_long); free(i_short); free(mfe.structure); free(struc); }