File: ProfileWithSub.cpp

package info (click to toggle)
clustalx 2.1%2Blgpl-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,332 kB
  • ctags: 3,424
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 11
file content (150 lines) | stat: -rw-r--r-- 3,857 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
 * Author: Mark Larkin
 * 
 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.  
 */
#ifdef HAVE_CONFIG_H
    #include "config.h"
#endif
#include "ProfileWithSub.h"

namespace clustalw
{

/**
 * 
 * @param prfLen 
 * @param firstS 
 * @param lastS 
 * @return 
 */
ProfileWithSub::ProfileWithSub(int prfLen, int firstS, int lastS)
 : ProfileBase(prfLen, firstS, lastS)
{
}

/**
 * 
 */
void ProfileWithSub::resetPrf1()
{
    profile.clear();
}


/**
 * 
 * @param seqArray 
 * @param gaps 
 * @param matrix[][] 
 * @param seqWeight 
 */
void ProfileWithSub::calcProfileWithSub(SeqArray* seqArray, vector<int>* gaps, 
                              int matrix[NUMRES][NUMRES], vector<int>* seqWeight)
{
    vector<vector<int> > weighting;
    int sum2, aa, seq, res;
    int _numSeq;
    int col, pos;
    int f;
    float scale;
    int _maxAA = userParameters->getMaxAA();
    int _gapPos1 = userParameters->getGapPos1();
    int _gapPos2 = userParameters->getGapPos2();
    
    weighting.resize(NUMRES + 2, vector<int>(prfLength + 2));
    
    _numSeq = lastSeq - firstSeq;

    sum2 = 0;
    for (seq = firstSeq; seq < lastSeq; seq++)
    {
        sum2 += (*seqWeight)[seq];
    }

    for (col = 0; col < prfLength; col++)
    {
        for (aa = 0; aa <= _maxAA; aa++)
        {
            weighting[aa][col] = 0;

            for (seq = firstSeq; seq < lastSeq; seq++)
                if (aa == (*seqArray)[seq][col])
                {
                    weighting[aa][col] += (*seqWeight)[seq];
                }
        }
        weighting[_gapPos1][col] = 0;

        for (seq = firstSeq; seq < lastSeq; seq++)
        {
            if (_gapPos1 == (*seqArray)[seq][col])
            {
                weighting[_gapPos1][col] += (*seqWeight)[seq];
            }
        }

        weighting[_gapPos2][col] = 0;

        for (seq = firstSeq; seq < lastSeq; seq++)
        {
            if (_gapPos2 == (*seqArray)[seq][col])
            {
                weighting[_gapPos2][col] += (*seqWeight)[seq];
            }
        }
    }

    for (pos = 0; pos < prfLength; pos++)
    {
        if ((*gaps)[pos] == _numSeq) // If all gaps
        {
            for (res = 0; res <= _maxAA; res++)
            {
                profile[pos + 1][res] = matrix[res][_gapPos1];
            }
            profile[pos + 1][_gapPos1] = matrix[_gapPos1][_gapPos1];
            profile[pos + 1][_gapPos2] = matrix[_gapPos2][_gapPos1];
        }
        else
        {
            scale = (float)(_numSeq - (*gaps)[pos]) / (float)_numSeq;
            for (res = 0; res <= _maxAA; res++)
            {
                f = 0;

                for (aa = 0; aa <= _maxAA; aa++)
                {
                    f += (weighting[aa][pos] * matrix[aa][res]);
                }

                f += (weighting[_gapPos1][pos] * matrix[_gapPos1][res]);
                f += (weighting[_gapPos2][pos] * matrix[_gapPos2][res]);
                profile[pos + 1][res] = (int)(((float)f / (float)sum2) * scale);
            }
            f = 0;

            for (aa = 0; aa <= _maxAA; aa++)
            {
                f += (weighting[aa][pos] * matrix[aa][_gapPos1]);
            }

            f += (weighting[_gapPos1][pos] * matrix[_gapPos1][_gapPos1]);
            f += (weighting[_gapPos2][pos] * matrix[_gapPos2][_gapPos1]);
            profile[pos + 1][_gapPos1] = (int)(((float)f / (float)sum2) * scale);
            f = 0;

            for (aa = 0; aa <= _maxAA; aa++)
            {
                f += (weighting[aa][pos] * matrix[aa][_gapPos2]);
            }

            f += (weighting[_gapPos1][pos] * matrix[_gapPos1][_gapPos2]);
            f += (weighting[_gapPos2][pos] * matrix[_gapPos2][_gapPos2]);
            profile[pos + 1][_gapPos2] = (int)(((float)f / (float)sum2) * scale);
        }
    }
}
                      

}