Wrapper for Clustal Omega.
[jabaws.git] / binaries / src / clustalo / src / hhalign / hhalignment.h
1 /* -*- mode: c; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
3 /*********************************************************************
4  * Clustal Omega - Multiple sequence alignment
5  *
6  * Copyright (C) 2010 University College Dublin
7  *
8  * Clustal-Omega is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This file is part of Clustal-Omega.
14  *
15  ********************************************************************/
16
17 /*
18  * RCS $Id: hhalignment.h 154 2010-11-09 18:29:05Z fabian $
19  */
20
21 // hhalignment.h
22
23 class Alignment
24 {
25 public:
26   int L;              // number of match states of alignment
27   int N_in;           // total number of sequences in alignment
28   int N_filtered;     /* number of sequences after sequence identity 
29                          filtering */
30   int N_ss;           // number of >ss_ or >sa sequences
31
32   int kss_dssp;       /* index of sequence with secondary structure 
33                          by dssp      -1:no >ss_dssp line found */
34   int ksa_dssp;       /* index of sequence with solvent accessibility 
35                          by dssp    -1:no >sa_dssp line found */
36   int kss_pred;       /* index of sequence with predicted secondary 
37                          structure    -1:no >ss_pred line found */
38   int kss_conf;       /* index of sequence with confidence values of 
39                          prediction  -1:no >ss_conf line found */
40   int kfirst;         // index of first real sequence
41
42   char* longname;     /* Full name of first sequence of original alignment 
43                          (NAME field) */
44   char name[NAMELEN]; // HMM name = first word in longname in lower case
45   char fam[NAMELEN];  // family ID (derived from name) (FAM field)
46   char file[NAMELEN]; /* Rootname (w/o path, with extension) of alignment 
47                          file that is used to construct the HMM */
48
49   int n_display;      /* number of sequences to be displayed 
50                          (INCLUDING >ss_pred, >ss_conf, >ss_dssp sequences) */
51   char** sname;       // names of display sequences (first seq=0, first char=0)
52   char** seq;         // residues of display sequences (first char=1)
53   int* l;             // l[i] = position of i'th match state in alignment 
54
55   char* keep;         /* keep[k]=1 if sequence is included in amino acid 
56                          frequencies; 0 otherwise (first=0) */
57
58   double *pdExWeight; /* external sequence weight as given by tree FIXME (FS) */
59
60   Alignment(int maxseq=MAXSEQ, int maxres=/*MAXRES*/par.maxResLen);
61   ~Alignment();
62
63   // Read alignment into X (uncompressed) in ASCII characters
64   void Read(FILE* inf, char infile[NAMELEN], char* line=NULL);
65 #ifdef CLUSTALO
66   void Transfer(char **ppcProf, int iCnt);
67   void ClobberGlobal();
68 #endif
69
70   /* Convert ASCII to numbers between 0 and 20, throw out all insert states, 
71      record their number in I[k][i] and store sequences to be displayed 
72      in sname[k] and seq[k] */
73   void Compress(const char infile[NAMELEN]);
74
75   // Apply sequence identity filter
76   inline int FilterForDisplay(int max_seqid, int coverage=0, int qid=0, float qsc=0, int N=0);
77   inline int Filter(int max_seqid, int coverage=0, int qid=0, float qsc=0, int N=0);
78   int Filter2(char keep[], int coverage, int qid, float qsc, int seqid1, int seqid2, int Ndiff);
79
80   bool FilterNeff(); /* MR1 */
81   float filter_by_qsc(float qsc, char* dummy); /* MR1 */
82
83   // Filter alignment for min score per column with core query profile, defined by min_coverage_core and min_seqid_core
84   int HomologyFilter(int coverage_core, float qsc_core, float coresc);
85
86   // Calculate AA frequencies q.p[i][a] and transition probabilities q.tr[i][a] from alignment
87   void FrequenciesAndTransitions(HMM& q, char* in=NULL);
88
89   // Calculate freqs q.f[i][a] and transitions q.tr[i][a] (a=MM,MI,MD) with pos-specific subalignments
90   void Amino_acid_frequencies_and_transitions_from_M_state(HMM& q, char* in);
91
92   // Calculate transitions q.tr[i][a] (a=DM,DD) with pos-specific subalignments
93   void Transitions_from_D_state(HMM& q, char* in);
94
95   // Calculate transitions q.tr[i][a] (a=DM,DD) with pos-specific subalignments
96   void Transitions_from_I_state(HMM& q, char* in);
97   
98   // Write alignment without insert states to alignment file
99   void WriteWithoutInsertsToFile(char* alnfile);
100
101   // Write alignment to alignment file
102   void WriteToFile(char* alnfile, const char format[]=NULL);
103
104   // Read a3m slave alignment of hit from ta3mfile and merge into (query) master alignment
105   void MergeMasterSlave(Hit& hit, char ta3mfile[]);
106
107   // Read a3m alignment of hit from ta3mfile and merge-combine with query alignment
108   void Merge(Hit& hit, char ta3mfile[]);
109
110   // Add a sequence to Qali
111   void AddSequence(char Xk[], int Ik[]=NULL);
112
113   // Determine matrix of position-specific weights w[k][i] for multiple alignment
114   void GetPositionSpecificWeights(float* w[]);
115
116   char readCommentLine;   // Set to 1, if a comment line with '#' is read /* MR1 */
117
118 private:
119   char** X;               // X[k][i] contains column i of sequence k in alignment (first seq=0, first char=1) (0-3: ARND ..., 20:X, 21:GAP)
120   short unsigned int** I; // I[k][i] contains the number of inserts AFTER match state i (first=0)
121   char* display;          // display[k]=1 if sequence will be displayed in output alignments; 0 otherwise (first=0)
122   float* wg;              // w[k] = global weight of sequence k
123   int* nseqs;             // number of sequences in subalignment i (only for DEBUGGING)
124   int* nres;              // number of residues in sequence k
125   int* first;             // first residue in sequence k
126   int* last;              // last  residue in sequence k
127   int* ksort;             // index for sorting sequences: X[ksort[k]]
128   int FilterWithCoreHMM(char in[], float coresc, HMM& qcore);
129 };