Change Eclipse configuration
[jabaws.git] / website / archive / binaries / mac / src / clustalw / src / multipleAlign / LowScoreSegProfile.cpp
1 /**
2  * Author: Mark Larkin
3  * 
4  * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.  
5  */
6 #ifdef HAVE_CONFIG_H
7     #include "config.h"
8 #endif
9 #include "LowScoreSegProfile.h"
10
11 namespace clustalw
12 {
13
14 LowScoreSegProfile::LowScoreSegProfile(int prfLen, int firstS, int lastS)
15     : prfLength(prfLen),
16       firstSeq(firstS),
17       lastSeq(lastS)
18 {
19     profile.resize(prfLength + 2, vector<int>(LENCOL + 2));
20 }
21
22 void LowScoreSegProfile::calcLowScoreSegProfile(const SeqArray* seqArray, 
23                                 int matrix[NUMRES][NUMRES], vector<int>* seqWeight)
24 {
25     vector<vector<int> > weighting; 
26     int d, i, res; 
27     int r, pos;
28     int f;
29     int _gapPos1 = userParameters->getGapPos1();
30     int _gapPos2 = userParameters->getGapPos2();
31     int _maxAA = userParameters->getMaxAA();
32
33     weighting.resize(NUMRES + 2, vector<int>(prfLength + 2));
34     
35     for (r = 0; r < prfLength; r++)
36     {
37         for (d = 0; d <= _maxAA; d++)
38         {
39             weighting[d][r] = 0;
40             for (i = firstSeq; i < lastSeq; i++)
41             {
42                 if (r + 1 < (int)(*seqArray)[i + 1].size() - 1)
43                 {
44                     if (d == (*seqArray)[i + 1][r + 1])
45                     { 
46                         weighting[d][r] += (*seqWeight)[i];
47                     }
48                 }
49             }
50         }
51         
52         weighting[_gapPos1][r] = 0;
53         
54         for (i = firstSeq; i < lastSeq; i++)
55         {
56             if (r + 1 < (int)(*seqArray)[i + 1].size() - 1)
57             {
58                 if (_gapPos1 == (*seqArray)[i + 1][r + 1])
59                 { 
60                     weighting[_gapPos1][r] += (*seqWeight)[i];
61                 }
62             }
63         }
64         
65         weighting[_gapPos2][r] = 0;
66         
67         for (i = firstSeq; i < lastSeq; i++)
68         {
69             if (r + 1 < (int)(*seqArray)[i + 1].size() - 1)
70             {
71                 if (_gapPos2 == (*seqArray)[i + 1][r + 1])
72                 { 
73                     weighting[_gapPos2][r] += (*seqWeight)[i];
74                 }
75             }
76         }
77     }
78
79     for (pos = 0; pos < prfLength; pos++)
80     {
81         for (res = 0; res <= _maxAA; res++)
82         {
83             f = 0;
84             
85             for (d = 0; d <= _maxAA; d++)
86             {
87                 f += (weighting[d][pos] * matrix[d][res]);
88             }
89             
90             f += (weighting[_gapPos1][pos] * matrix[_gapPos1][res]);
91             f += (weighting[_gapPos2][pos] * matrix[_gapPos2][res]);
92             profile[pos + 1][res] = f;
93         }
94         f = 0;
95         
96         for (d = 0; d <= _maxAA; d++)
97         {
98             f += (weighting[d][pos] * matrix[d][_gapPos1]);
99         }   
100         
101         f += (weighting[_gapPos1][pos] * matrix[_gapPos1][_gapPos1]);
102         f += (weighting[_gapPos2][pos] * matrix[_gapPos2][_gapPos1]);
103         profile[pos + 1][_gapPos1] = f;
104         f = 0;
105            
106         for (d = 0; d <= _maxAA; d++)
107         {
108             f += (weighting[d][pos] * matrix[d][_gapPos2]);
109         }   
110         f += (weighting[_gapPos1][pos] * matrix[_gapPos1][_gapPos2]);
111         f += (weighting[_gapPos2][pos] * matrix[_gapPos2][_gapPos2]);
112         profile[pos + 1][_gapPos2] = f;
113     }
114 }                                
115
116 }