File: LowScoreSegProfile.cpp

package info (click to toggle)
clustalx 2.1%2Blgpl-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,324 kB
  • sloc: cpp: 40,050; sh: 163; xml: 102; makefile: 16
file content (116 lines) | stat: -rw-r--r-- 3,254 bytes parent folder | download | duplicates (11)
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
/**
 * Author: Mark Larkin
 * 
 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.  
 */
#ifdef HAVE_CONFIG_H
    #include "config.h"
#endif
#include "LowScoreSegProfile.h"

namespace clustalw
{

LowScoreSegProfile::LowScoreSegProfile(int prfLen, int firstS, int lastS)
    : prfLength(prfLen),
      firstSeq(firstS),
      lastSeq(lastS)
{
    profile.resize(prfLength + 2, vector<int>(LENCOL + 2));
}

void LowScoreSegProfile::calcLowScoreSegProfile(const SeqArray* seqArray, 
                                int matrix[NUMRES][NUMRES], vector<int>* seqWeight)
{
    vector<vector<int> > weighting; 
    int d, i, res; 
    int r, pos;
    int f;
    int _gapPos1 = userParameters->getGapPos1();
    int _gapPos2 = userParameters->getGapPos2();
    int _maxAA = userParameters->getMaxAA();

    weighting.resize(NUMRES + 2, vector<int>(prfLength + 2));
    
    for (r = 0; r < prfLength; r++)
    {
        for (d = 0; d <= _maxAA; d++)
        {
            weighting[d][r] = 0;
            for (i = firstSeq; i < lastSeq; i++)
            {
                if (r + 1 < (int)(*seqArray)[i + 1].size() - 1)
                {
                    if (d == (*seqArray)[i + 1][r + 1])
                    { 
                        weighting[d][r] += (*seqWeight)[i];
                    }
                }
            }
        }
        
        weighting[_gapPos1][r] = 0;
        
        for (i = firstSeq; i < lastSeq; i++)
        {
            if (r + 1 < (int)(*seqArray)[i + 1].size() - 1)
            {
                if (_gapPos1 == (*seqArray)[i + 1][r + 1])
                { 
                    weighting[_gapPos1][r] += (*seqWeight)[i];
                }
            }
        }
        
        weighting[_gapPos2][r] = 0;
        
        for (i = firstSeq; i < lastSeq; i++)
        {
            if (r + 1 < (int)(*seqArray)[i + 1].size() - 1)
            {
                if (_gapPos2 == (*seqArray)[i + 1][r + 1])
                { 
                    weighting[_gapPos2][r] += (*seqWeight)[i];
                }
            }
        }
    }

    for (pos = 0; pos < prfLength; pos++)
    {
        for (res = 0; res <= _maxAA; res++)
        {
            f = 0;
            
            for (d = 0; d <= _maxAA; d++)
            {
                f += (weighting[d][pos] * matrix[d][res]);
            }
            
            f += (weighting[_gapPos1][pos] * matrix[_gapPos1][res]);
            f += (weighting[_gapPos2][pos] * matrix[_gapPos2][res]);
            profile[pos + 1][res] = f;
        }
        f = 0;
        
        for (d = 0; d <= _maxAA; d++)
        {
            f += (weighting[d][pos] * matrix[d][_gapPos1]);
        }   
        
        f += (weighting[_gapPos1][pos] * matrix[_gapPos1][_gapPos1]);
        f += (weighting[_gapPos2][pos] * matrix[_gapPos2][_gapPos1]);
        profile[pos + 1][_gapPos1] = f;
        f = 0;
           
        for (d = 0; d <= _maxAA; d++)
        {
            f += (weighting[d][pos] * matrix[d][_gapPos2]);
        }   
        f += (weighting[_gapPos1][pos] * matrix[_gapPos1][_gapPos2]);
        f += (weighting[_gapPos2][pos] * matrix[_gapPos2][_gapPos2]);
        profile[pos + 1][_gapPos2] = f;
    }
}                                

}