/* -*- mode: c; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /********************************************************************* * Clustal Omega - Multiple sequence alignment * * Copyright (C) 2010 University College Dublin * * Clustal-Omega is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This file is part of Clustal-Omega. * ********************************************************************/ /* * RCS $Id: hhhalfalignment-C.h 227 2011-03-28 17:03:09Z fabian $ */ // 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.h" // 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.h" // constants, class #include "hhutil-C.h" // 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] } ///////////////////////////////////////////////////////////////////////////////////// // Destructor HalfAlignment::~HalfAlignment() { Unset(); delete[] h; h = NULL; delete[] s; s = NULL; delete[] l; l = NULL; delete[] m; m = NULL; } ///////////////////////////////////////////////////////////////////////////////////// /** * @brief 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) { printf(" i chr m l\n"); for(i=0;i<=L+1;i++) printf("%3i %1c %3i %3i\n",i,seq[0][m[0][i]],m[0][i],l[0][i]); printf("\n"); } } /*** end HalfAlignment::Set() ***/ ///////////////////////////////////////////////////////////////////////////////////// /** * @brief 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++; } ///////////////////////////////////////////////////////////////////////////////////// /** * @brief 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'); } ///////////////////////////////////////////////////////////////////////////////////// /** * @brief Write the a2m/a3m alignment into alnfile */ void HalfAlignment::Print(char* alnfile) { int k; //counts sequences int omitted=0; // counts number of sequences with no residues in match states FILE *outf; 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]); } 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); fclose(outf); } /** EOF hhhalfalignment-C.h **/