// hhfullalignment.C #ifndef MAIN #define MAIN #include // cin, cout, cerr #include // ofstream, ifstream #include // printf #include // exit #include // strcmp, strstr #include // sqrt, pow #include // INT_MIN #include // FLT_MIN #include // clock #include // islower, isdigit etc using std::ios; using std::ifstream; using std::ofstream; using std::cout; using std::cerr; using std::endl; #include "util.C" // imax, fmax, iround, iceil, ifloor, strint, strscn, strcut, substr, uprstr, uprchr, Basename etc. #include "list.h" // list data structure #include "hash.h" // hash data structure #include "hhdecl.C" // constants, class #include "hhutil.C" // imax, fmax, iround, iceil, ifloor, strint, strscn, strcut, substr, uprstr, uprchr, Basename etc. #include "hhhmm.h" // class HMM #include "hhalignment.h" // class Alignment #include "hhhit.h" #endif ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// // Methods of class HalfAlignment ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// // Constructor HalfAlignment::HalfAlignment(int maxseqdis) { n=0; sname=seq=NULL; nss_dssp = nss_pred = nss_conf = nsa_dssp = ncons= -1; h = new(int[maxseqdis]); //h[k] = next position of sequence k to be written s = new(char*[maxseqdis]); //s[k][h] = character in column h, sequence k of output alignment l = new(int*[maxseqdis]); //counts non-gap residues: l[k][i] = index of last residue AT OR BEFORE match state i in seq k m = new(int*[maxseqdis]); //counts positions: m[k][i] = position of match state i in string seq[k] if (!h || !s || !l || !m) MemoryError("space for formatting HMM-HMM alignment"); } ///////////////////////////////////////////////////////////////////////////////////// // Destructor HalfAlignment::~HalfAlignment() { Unset(); delete[] h; delete[] s; delete[] l; delete[] m; } ///////////////////////////////////////////////////////////////////////////////////// // Free memory in HalfAlignment arrays s[][], l[][], and m[][] void HalfAlignment::Unset() { // Free memory for alignment characters and residue counts for (int k=0; k=5) { fprintf(stderr," i chr m l\n"); for(i=0;i<=L+1;i++) fprintf(stderr,"%3i %1c %3i %3i\n",i,seq[0][m[0][i]],m[0][i],l[0][i]); printf("\n"); } } ///////////////////////////////////////////////////////////////////////////////////// // Fill in insert states following match state i (without inserting '.' to fill up) void HalfAlignment::AddInserts(int i) { for (int k=0; k'9')) s[k][h[k]++]=InsertChr(c); pos++; } ///////////////////////////////////////////////////////////////////////////////////// // Remove all characters c from template sequences void HalfAlignment::RemoveChars(char c) { int k,h,hh; for (k=0; k=1; step--) { state = hit.states[step]; i = hit.i[step]; switch(state) { case MM: //MM pair state (both query and template in Match state) AddColumn(i); AddInserts(i); break; case DG: //D- state case MI: //MI state AddColumnAsInsert(i); AddInserts(i); break; case GD: //-D state case IM: //IM state AddChar('-'); break; } if (par.outformat<=2) FillUpGaps(); } if(0) { //par.loc==0) { //////////////////////////////////////////// STILL NEEDED?? // If in global mode: Add part of alignment after last MM state for (i=hit.i[1]+1; i<=L; i++) { AddColumnAsInsert(i); AddInserts(i); if (par.outformat==2) FillUpGaps(); } } // Add endgaps for (j=hit.j[1]+1; j<=hit.L; j++) { AddChar('-'); } // Add end-of-string character AddChar('\0'); } ///////////////////////////////////////////////////////////////////////////////////// // Write the a2m/a3m alignment into alnfile ///////////////////////////////////////////////////////////////////////////////////// void HalfAlignment::Print(char* alnfile, char* commentname, const char format[]) { int k; //counts sequences int omitted=0; // counts number of sequences with no residues in match states FILE *outf; char* tmp_name = new(char[NAMELEN]); if (strcmp(alnfile,"stdout")) { if (par.append) outf=fopen(alnfile,"a"); else outf=fopen(alnfile,"w"); if (!outf) OpenFileError(alnfile); } else outf = stdout; if (v>=3) cout<<"Writing alignment to "<%s\n",sname[k]); fprintf(outf,"%s\n",s[k]); } for (k=0; k%s\n",sname[k]); fprintf(outf,"%s\n",s[k]); } else { omitted++; if (v>=3) printf("%-14.14s contains no residue in match state. Omitting sequence\n",sname[k]); } } } if (v>=2 && omitted) printf("Omitted %i sequences in %s which contained no residue in match state\n",omitted,alnfile); } else { for (k=0; k=65 && *ptr<=90)) fprintf(outf,"%c",*ptr); fprintf(outf,"\n"); } } fclose(outf); delete[] tmp_name; }