PUBLIC float *Make_bp_profile(int length){ return Make_bp_profile_bppm(pr, length); }
int main(int argc, char *argv[]) { float *T[MAXSEQ]; int i,j, istty, n=0; int type, length, taxa_list=0; float dist; FILE *somewhere=NULL; char *structure; char *line=NULL, fname[FILENAME_MAX_LENGTH], *list_title=NULL; plist *pr_pl, *mfe_pl; pr_pl = mfe_pl = NULL; command_line(argc, argv); if((outfile[0]=='\0')&&(task=='m')&&(edit_backtrack)) strcpy(outfile,"backtrack.file"); if (outfile[0]!='\0') somewhere = fopen(outfile,"w"); if (somewhere==NULL) somewhere = stdout; istty = (isatty(fileno(stdout))&&isatty(fileno(stdin))); while (1) { if ((istty)&&(n==0)) { printf("\nInput sequence; @ to quit\n"); printf("%s\n", ruler); } type = 0; do { /* get sequence to fold */ if (line!=NULL) free(line); *fname='\0'; if ((line=get_line(stdin))==NULL) {type = 999; break;} if (line[0]=='@') type = 999; if (line[0]=='*') { if (taxa_list==0) { if (task=='m') taxa_list=1; printf("%s\n", line); type = 0; } else { list_title = strdup(line); type = 888; } } if (line[0]=='>') { if (sscanf(line,">%" XSTR(FILENAME_ID_LENGTH) "s", fname)!=0) strcat(fname, "_dp.ps"); if (taxa_list) printf("%d : %s\n", n+1, line+1); else printf("%s\n",line); type = 0; } if (isalpha(line[0])) { char *cp; cp =strchr(line,' '); if (cp) *cp='\0'; type = 1; } } while(type==0); if( (task == 'm')&&(type>800) ) { if (taxa_list) printf("* END of taxa list\n"); printf("> p %d (pdist)\n",n); for (i=1; i<n; i++) { for (j=0; j<i; j++) { printf("%g ",profile_edit_distance(T[i], T[j])); if(edit_backtrack) fprintf(somewhere,"> %d %d\n",i+1,j+1); print_aligned_lines(somewhere); } printf("\n"); } if (type==888) { /* do another distance matrix */ n = 0; printf("%s\n", list_title); free(list_title); } } if(type>800) { for (i=0; i<n; i++) free_profile(T[i]); if (type == 888) continue; if (outfile[0]!='\0') (void) fclose(somewhere); if (line!= NULL) free(line); return 0; /* finito */ } length = (int) strlen(line); for (i=0; i<length; i++) { line[i]=toupper(line[i]); if (!noconv && line[i] == 'T') line[i] = 'U'; } /* init_pf_fold(length); <- obsolete */ structure = (char *) space((length+1)*sizeof(char)); (void) pf_fold(line,structure); if (*fname=='\0') sprintf(fname, "%d_dp.ps", n+1); /* PS_dot_plot(line, fname); <- NOT THREADSAFE and obsolete function! */ /* get pairlist of probability matrix */ assign_plist_from_pr(&pr_pl, pr, length, 1e-5); /* no previous mfe call thus no mfe structure information known */ mfe_pl = (plist *)space(sizeof(plist)); mfe_pl[0].i = mfe_pl[0].j = 0; /* call threadsafe dot plot printing function */ PS_dot_plot_list(line, fname, pr_pl, mfe_pl, ""); T[n] = Make_bp_profile_bppm(pr, length); if((istty)&&(task=='m')) printf("%s\n",structure); free(structure); free(mfe_pl); free(pr_pl); free_pf_arrays(); n++; switch (task) { case 'p' : if (n==2) { dist = profile_edit_distance(T[0],T[1]); printf("%g\n",dist); print_aligned_lines(somewhere); free_profile(T[0]); free_profile(T[1]); n=0; } break; case 'f' : if (n>1) { dist = profile_edit_distance(T[1], T[0]); printf("%g\n",dist); print_aligned_lines(somewhere); free_profile(T[1]); n=1; } break; case 'c' : if (n>1) { dist = profile_edit_distance(T[1], T[0]); printf("%g\n",dist); print_aligned_lines(somewhere); free_profile(T[0]); T[0] = T[1]; n=1; } break; case 'm' : break; default : nrerror("This can't happen."); } /* END switch task */ (void) fflush(stdout); } /* END while */ if (line !=NULL) free(line); return 0; }
void main() { char *seq1="CGCAGGGAUACCCGCG", *seq2="GCGCCCAUAGGGACGC", *struct1,* struct2,* xstruc; float e1, e2, tree_dist, string_dist, profile_dist, kT; Tree *T1, *T2; swString *S1, *S2; float *pf1, *pf2; FLT_OR_DBL *bppm; /* fold at 30C instead of the default 37C */ temperature = 30.; /* must be set *before* initializing */ /* allocate memory for structure and fold */ struct1 = (char* ) space(sizeof(char)*(strlen(seq1)+1)); e1 = fold(seq1, struct1); struct2 = (char* ) space(sizeof(char)*(strlen(seq2)+1)); e2 = fold(seq2, struct2); free_arrays(); /* free arrays used in fold() */ /* produce tree and string representations for comparison */ xstruc = expand_Full(struct1); T1 = make_tree(xstruc); S1 = Make_swString(xstruc); free(xstruc); xstruc = expand_Full(struct2); T2 = make_tree(xstruc); S2 = Make_swString(xstruc); free(xstruc); /* calculate tree edit distance and aligned structures with gaps */ edit_backtrack = 1; tree_dist = tree_edit_distance(T1, T2); free_tree(T1); free_tree(T2); unexpand_aligned_F(aligned_line); printf("%s\n%s %3.2f\n", aligned_line[0], aligned_line[1], tree_dist); /* same thing using string edit (alignment) distance */ string_dist = string_edit_distance(S1, S2); free(S1); free(S2); printf("%s mfe=%5.2f\n%s mfe=%5.2f dist=%3.2f\n", aligned_line[0], e1, aligned_line[1], e2, string_dist); /* for longer sequences one should also set a scaling factor for partition function folding, e.g: */ kT = (temperature+273.15)*1.98717/1000.; /* kT in kcal/mol */ pf_scale = exp(-e1/kT/strlen(seq1)); /* calculate partition function and base pair probabilities */ e1 = pf_fold(seq1, struct1); /* get the base pair probability matrix for the previous run of pf_fold() */ bppm = export_bppm(); pf1 = Make_bp_profile_bppm(bppm, strlen(seq1)); e2 = pf_fold(seq2, struct2); /* get the base pair probability matrix for the previous run of pf_fold() */ bppm = export_bppm(); pf2 = Make_bp_profile_bppm(bppm, strlen(seq2)); free_pf_arrays(); /* free space allocated for pf_fold() */ profile_dist = profile_edit_distance(pf1, pf2); printf("%s free energy=%5.2f\n%s free energy=%5.2f dist=%3.2f\n", aligned_line[0], e1, aligned_line[1], e2, profile_dist); free_profile(pf1); free_profile(pf2); }