NCBI C++ ToolKit
cuAlignedDM.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #include <ncbi_pch.hpp>
3 
5 BEGIN_SCOPE(cd_utils)
6 
7 const double AlignedDM::FRACTIONAL_EXTRA_OFFSET = 0.005;
8 
10 :DistanceMatrix(), m_ppAlignedResidues(0), m_maligns(0)
11 {
12 }
13 
15 {
16  m_maligns = malign;
18 }
19 
21 {
22  if (m_ppAlignedResidues) {
23  for (int i=0; i<m_NumRows; i++) {
24  delete [] m_ppAlignedResidues[i];
25  }
26  delete [] m_ppAlignedResidues;
27  }
28 }
29 
30 // Pack the m_ppAlignedResidues array as follows:
31 // [0...nAligned-1][nAligned...nAligned+m_nTermExt-1][nAligned+m_nTermExt....nAligned+m_nTermExt+m_cTermExt-1]
32 // If either m_nTermExt or m_cTermExt < 0, drop the corresponding appended range and
33 // make the corresponding parts of the [0...nAligned-1] range 0 == no residue.
35 
36  int nrows = 0;
37  int resArrayDim = 0;
38  int nAligned = 0;
39  int firstAligned, lastAligned;
40 
41  bool result = true;
42 
43  if (m_aligns) {
44  nrows = m_aligns->GetNumRows();
45  } else {
46  return false;
47  }
48 
49  // if space is already allocated, clean up and get fresh copy
50  if (m_ppAlignedResidues) {
51  for (int i=0; i<m_NumRows; i++) {
52  delete [] m_ppAlignedResidues[i];
53  }
54  delete [] m_ppAlignedResidues;
56  }
57  m_ConvertedSequences.clear();
58  m_ppAlignedResidues = new CharPtr[nrows];
59  if (m_ppAlignedResidues == NULL) {
60  return false;
61  }
62 
63  // Make m_ppAlignedResidues large enough to hold any positive extensions
64  nAligned = m_aligns->GetAlignmentLength();
65  resArrayDim = nAligned + Max(0, m_nTermExt) + Max(0, m_cTermExt);
66  for (int i=0; i<nrows; i++) {
67  m_ppAlignedResidues[i] = new char[resArrayDim];
68  if (m_ppAlignedResidues[i] == NULL) {
69  result = false;
70  }
71  }
72 
73  // Get all sequences and mapping from rowIndex -> seqIndex
74  //m_ConvertedSequences.clear();
77 // m_cd->SetAlignedResidues(); //m_ppAlignedResidues, m_ConvertedSequences);
78 
79  if (m_nTermExt == 0 && m_cTermExt == 0) {
80  return true;
81  }
82 
83  // N-terminal extension... if negative, eliminate that many residues from front of array
84  if (m_nTermExt < 0) {
85  for (int i = 0; i<nrows; ++i) {
86  for (int j = 0; j<-m_nTermExt; ++j) {
87  m_ppAlignedResidues[i][j] = 0;
88  }
89  }
90  // if positive, add after the list of aligned residues
91  } else {
92  for (int i = 0; i<nrows; ++i) {
93  firstAligned = m_maligns->GetLowerBound(i);
94  for (int j = m_nTermExt; j > 0 ; --j) {
95  m_ppAlignedResidues[i][m_nTermExt - j + nAligned] = (firstAligned - j < 0) ? 0 : m_ConvertedSequences[i][firstAligned - j];
96  }
97  }
98  }
99 
100  // C-terminal extension... if negative, eliminate that many residues from back of aligned residues section
101  if (m_cTermExt < 0) {
102  for (int i = 0; i<nrows; ++i) {
103  for (int j = 0; j<-m_cTermExt; ++j) {
104  m_ppAlignedResidues[i][nAligned - 1 - j] = 0;
105  }
106  }
107  // if positive, add after end of n-term extensions
108  } else {
109  int nTermOffset = Max(0, m_nTermExt);
110  int seqLen;
111  for (int i = 0; i<nrows; ++i) {
112  lastAligned = m_maligns->GetUpperBound(i);
113  seqLen = m_ConvertedSequences[i].size();
114  for (int j = 0; j < m_cTermExt; ++j) {
115  m_ppAlignedResidues[i][j + nAligned + nTermOffset] =
116  (lastAligned + 1 + j >= seqLen) ? 0 : m_ConvertedSequences[i][lastAligned + 1 + j];
117  }
118  }
119  }
120 
121  return result;
122 }
123 
125 
126  int nrows;
127  int rowVal;
128  int maxVal = -INITIAL_SCORE_BOUND;
129 // if (m_cd != null) {
130  if (m_maligns) {
131  nrows = m_maligns->GetNumRows();
132  // if space is already allocated then safe to assume array has been filled in
133  if (!m_ppAlignedResidues) {
134  m_ppAlignedResidues = new CharPtr[nrows];
135  for (int i=0; i<nrows; i++) {
137  }
138 // SetConvertedSequencesForCD(m_cd, m_ConvertedSequences);
140 // m_cd->SetAlignedResidues(m_ppAlignedResidues, m_ConvertedSequences);
141  }
142  for (int i=0; i<nrows; ++i) {
143  rowVal = GetMaxScore(m_ppAlignedResidues[i]);
144  if (rowVal > maxVal) {
145  maxVal = rowVal;
146  }
147  }
148  }
149  return maxVal;
150 }
151 
152 // Calculate score for an exact match to a set of residues.
154 
155  char Res1;
156  int score=0;
157  int alignLen;
158 
159 // if (m_cd == null || m_scoreMatrix == NULL || m_scoreMatrix->GetType() == eInvalidMatrixType) {
161  return -INITIAL_SCORE_BOUND;
162  }
163 
164  alignLen = m_maligns->GetAlignmentLength();
165  // for each column of the alignment
166  for (int i=0; i<alignLen; i++) {
167  Res1 = residues[i];
168  if (Res1 > 0) {
169  score += m_scoreMatrix->GetScore(Res1, Res1);
170  }
171  }
172  return score;
173 }
174 
175 
177 
178  int minVal = INITIAL_SCORE_BOUND;
180  minVal = m_maligns->GetAlignmentLength() * m_scoreMatrix->GetScore('*', 'A');
181  }
182  return minVal;
183 }
184 
185 END_SCOPE(cd_utils)
int Max(int Val1, int Val2)
Definition: cuMatrix.hpp:149
int GetMaxScoreForAligned()
static const double FRACTIONAL_EXTRA_OFFSET
Definition: cuAlignedDM.hpp:54
CharPtr * m_ppAlignedResidues
Definition: cuAlignedDM.hpp:56
int GetMaxScore(CharPtr residues)
MultipleAlignment * m_maligns
Definition: cuAlignedDM.hpp:57
bool GetResidueListsWithShifts()
Definition: cuAlignedDM.cpp:34
void setData(MultipleAlignment *malign)
Definition: cuAlignedDM.cpp:14
int SetMinScore()
virtual ~AlignedDM()
Definition: cuAlignedDM.cpp:20
void GetAllSequences(vector< string > &sequences)
int GetAlignmentLength(int row=0) const
void GetAlignedResiduesForAll(char **&ppAlignedResidues, bool forceRecompute)
int GetLowerBound(int row) const
int GetUpperBound(int row) const
ScoreMatrix * m_scoreMatrix
Definition: cuDistmat.hpp:156
AlignmentCollection * m_aligns
Definition: cuDistmat.hpp:159
std::vector< std::string > m_ConvertedSequences
Definition: cuDistmat.hpp:154
static const int INITIAL_SCORE_BOUND
Definition: cuDistmat.hpp:151
void SetData(AlignmentCollection *aligns)
Definition: cuDistmat.cpp:105
EScoreMatrixType GetType() const
int GetScore(char i, char j)
@ eInvalidMatrixType
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
int i
else result
Definition: token2.c:20
Modified on Sat Jul 13 13:36:16 2024 by modify_doxy.py rev. 669887