📄 savehmm_multialpha.c
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <time.h>#include "structs.h" /* data structures etc */#include "funcs.h" /* function header */#define POS 0//#define SAVE_DEBUGextern int verbose;void savemodule_multi(FILE*, struct hmm_multi_s*, struct module_multi_s*);savehmm_multialpha(FILE *outfile, struct hmm_multi_s *hmmp){ char s[1000]; char nr[32]; time_t t; int t1, t2; int i,j; struct module_multi_s *modulep; struct transition_s trans, *trans_ties; if(outfile == NULL) { printf("Could not write to outfile when saving hmm\n"); exit(0); } if(verbose == YES) { printf("saving hmm %s ... ", hmmp->name); fflush(stdout); } /* header */ if(fputs("***********************Header***************************\n", outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("********Header********\n");#endif /* name */ strcpy(s, "NAME: "); if(fputs(strcat(s , hmmp->name), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* time */ time(&t); strcpy(s, "TIME OF CREATION: "); if(fputs(strcat(s, ctime(&t)), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* nr of alphabets */ strcpy(s, "NR OF ALPHABETS: "); itoa(nr, hmmp->nr_alphabets); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* alphabet */ strcpy(s, "ALPHABET 1: "); if(fputs(strcat(s, hmmp->alphabet), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* alphabet length */ strcpy(s, "ALPHABET LENGTH 1: "); itoa(nr, hmmp->a_size); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif if(hmmp->nr_alphabets > 1) { /* alphabet */ strcpy(s, "ALPHABET 2: "); if(fputs(strcat(s, hmmp->alphabet_2), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* alphabet length */ strcpy(s, "ALPHABET LENGTH 2: "); itoa(nr, hmmp->a_size_2); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } if(hmmp->nr_alphabets > 2) { /* alphabet */ strcpy(s, "ALPHABET 3: "); if(fputs(strcat(s, hmmp->alphabet_3), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* alphabet length */ strcpy(s, "ALPHABET LENGTH 3: "); itoa(nr, hmmp->a_size_3); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } if(hmmp->nr_alphabets > 3) { /* alphabet */ strcpy(s, "ALPHABET 4: "); if(fputs(strcat(s, hmmp->alphabet_4), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* alphabet length */ strcpy(s, "ALPHABET LENGTH 4: "); itoa(nr, hmmp->a_size_4); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } /* nr of modules */ strcpy(s, "NR OF MODULES: "); itoa(nr, hmmp->nr_m); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* nr of vertices */ strcpy(s, "NR OF VERTICES: "); itoa(nr, hmmp->nr_v); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* nr of TRANSITIONS */ strcpy(s, "NR OF TRANSITIONS: "); itoa(nr, hmmp->nr_t); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* nr of DISTRIBUTION GROUPS */ strcpy(s, "NR OF DISTRIBUTION GROUPS: "); itoa(nr, hmmp->nr_d); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* nr of TRANS TIE GROUPS */ strcpy(s, "NR OF TRANSITION TIE GROUPS: "); itoa(nr, hmmp->nr_ttg); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* nr of PRIOR FILES */ strcpy(s, "NR OF EMISSION PRIORFILES 1: "); itoa(nr, hmmp->nr_ed); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* the PRIOR FILES */ strcpy(s, "EMISSION PRIORFILES_1:"); for(i = 0; i < hmmp->nr_ed; i++) { strcat(s, " "); strcat(s, (hmmp->emission_dirichlets + i)->name); } if(fputs(strcat(s, " \n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif if(hmmp->nr_alphabets > 1) { /* nr of PRIOR FILES */ strcpy(s, "NR OF EMISSION PRIORFILES 2: "); itoa(nr, hmmp->nr_ed_2); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* the PRIOR FILES */ strcpy(s, "EMISSION PRIORFILES_2:"); for(i = 0; i < hmmp->nr_ed_2; i++) { strcat(s, " "); strcat(s, (hmmp->emission_dirichlets_2 + i)->name); } if(fputs(strcat(s, " \n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } if(hmmp->nr_alphabets > 2) { /* nr of PRIOR FILES */ strcpy(s, "NR OF EMISSION PRIORFILES 3: "); itoa(nr, hmmp->nr_ed_3); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* the PRIOR FILES */ strcpy(s, "EMISSION PRIORFILES_3:"); for(i = 0; i < hmmp->nr_ed_3; i++) { strcat(s, " "); strcat(s, (hmmp->emission_dirichlets_3 + i)->name); } if(fputs(strcat(s, " \n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } if(hmmp->nr_alphabets > 3) { /* nr of PRIOR FILES */ strcpy(s, "NR OF EMISSION PRIORFILES 4: "); itoa(nr, hmmp->nr_ed_4); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* the PRIOR FILES */ strcpy(s, "EMISSION PRIORFILES_4:"); for(i = 0; i < hmmp->nr_ed_4; i++) { strcat(s, " "); strcat(s, (hmmp->emission_dirichlets_4 + i)->name); } if(fputs(strcat(s, " \n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } /* nr of PRIOR FILES */ strcpy(s, "NR OF TRANSITION PRIORFILES: "); if(fputs(strcat(s, "0\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* the PRIOR FILES */ strcpy(s, "TRANSITION PRIORFILES:"); for(i = 0; i < 0; i++) { strcat(s, " "); //strcat(s, (hmmp->emission_dirichlets)->name); } if(fputs(strcat(s, "\n"), outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* two empty rows */ if(fputs("\n\n", outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* modules */ if(fputs("***********************Modules*************************\n", outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* save the modules */ for(i = 0; i < hmmp->nr_m; i++) { //printf("inne\n"); modulep = *(hmmp->modules + i); savemodule_multi(outfile, hmmp, modulep); } /* empty row */ if(fputs("\n", outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* save distribution groups */ /****************Distribution groups***************************/ if(fputs("**********************Emission distribution groups*******************\n", outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("************************Emission distribution groups******************\n", s);#endif /* the groups */ j = 0; for(i = 0; i < hmmp->nr_d; i++) { strcpy(s, "Group "); itoa(nr, i+1); strcat(s, nr); strcat(s, ": "); while((t1 = *(hmmp->distrib_groups+j)) != END) { itoa(nr, t1); strcat(s, nr); strcat(s, " "); j++; } j++; strcat(s, "\n"); if(fputs(s, outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } /* empty row */ if(fputs("\n", outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* save transition tie groups */ /****************Transition tie groups***************************/ if(fputs("**********************Transition tie groups*******************\n", outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s); printf("hmmp->nr_ttg = %d\n", hmmp->nr_ttg);#endif /* the groups */ j = 0; for(i = 0; i < hmmp->nr_ttg; i++) { strcpy(s, "Tie "); itoa(nr, i+1); strcat(s, nr); strcat(s, ": "); while(((hmmp->trans_tie_groups)+j)->from_v != END) { t1 = ((hmmp->trans_tie_groups)+j)->from_v; itoa(nr, t1); strcat(s, nr); strcat(s, "->"); t1 = ((hmmp->trans_tie_groups)+j)->to_v; itoa(nr, t1); strcat(s, nr); strcat(s, " "); j++; } j++; strcat(s, "\n"); if(fputs(s, outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif } /* flush buffer */ fflush(outfile); if(verbose == YES) { printf("done\n"); }}void savemodule_multi(FILE *outfile,struct hmm_multi_s *hmmp, struct module_multi_s *modulep){ char s[500]; char nr[30]; int i, j, k ,l, m; int nr_t, nr_et, nr_e; int cur_v; char *alphp; //printf("name %s\n", modulep->name); /* name */ strcpy(s, "Module: "); if(fputs(strcat(s , modulep->name), outfile) == EOF) { perror(""); } #ifdef SAVE_DEBUG printf("\n%s", s);#endif /* type */ strcpy(s, "Type: "); switch(modulep->type) { case SINGLENODE: strcat(s, "Singlenode\n"); break; case CLUSTER: strcat(s, "Cluster\n"); break; case SINGLELOOP: strcat(s, "Singleloop\n"); break; case FORWARD_STD: strcat(s, "Forward_std\n"); break; case FORWARD_ALT: strcat(s, "Forward_alt\n"); break; case PROFILE7: strcat(s, "Profile7\n"); break; case PROFILE9: strcat(s, "Profile9\n"); break; default: printf("Error: unknown type %d, can't save hmm\n"); exit(-1); } if(fputs(s, outfile) == EOF) { perror(""); }#ifdef SAVE_DEBUG printf("%s", s);#endif /* nr of vertices */ strcpy(s, "NrVertices: "); itoa(nr, modulep->nr_v); if(fputs(strcat(strcat(s, nr), "\n"), outfile) == EOF) { perror("");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -