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

Go to the SVN repository for this file.

1 /* $Id: cuDmAlignedOptimalScore.cpp 38459 2008-07-07 18:34:41Z lanczyck $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 */
27 #include <ncbi_pch.hpp>
29 
31 BEGIN_SCOPE(cd_utils)
32 
33 // DM_AlignedScore class
34 
35 // The pairwise score between two rows in an alignment is the sum over the
36 // scores of each pair of aligned residues:
37 //
38 // d[i][j] = max_Score_for_row - sum(k)( scoring_matrix(i_k, j_k))
39 //
40 // where x_k is the kth aligned residue of row x. The offset is to make
41 // high scores map to short distances. Although note that each row will
42 // in general have a different score for an exact match, making d=0 ambiguous.
43 
45 
47 {
48 }
49 
51  AlignedDM(), m_blockExtender(0)
52 {
54 }
55 
57 {
59  m_useAligned = true;
60  m_nTermExt = nTermExt;
61  m_cTermExt = cTermExt;
63  if (m_nTermExt != 0 || m_cTermExt != 0) {
64  m_useAligned = false;
65  }
66 }
67 
69 {
70  m_blockExtender = be;
71 }
72 
74 {
75  if (!m_maligns || !m_blockExtender)
76  return false;
77  m_ConvertedSequences.clear();
82  int nrows = m_maligns->GetNumRows();
84 
85  //m_maligns->GetAllSequences( m_ConvertedSequences);
86  int count = 0;
87  int total = (int)((double)nrows * (((double)nrows-1)/2));
88 
89  // pre-fetch map
90  /*
91  int** ppScores;
92  ppScores = new int*[256];
93  for (int j=0; j<256; j++) {
94  ppScores[j] = new int[256];
95  }
96  for (int j=0; j<256; j++) {
97  for (int k=0; k<256; k++) {
98  ppScores[j][k] = m_scoreMatrix->GetScore(char(j), char(k));
99  }
100  }*/
101 
102 
103  // for each row in the alignment
104  for (int j=0; j<nrows; j++)
105  {
106  m_Array[j][j] = 0.0;
107  // for each other row in the alignment
108  for (int k=j+1; k<nrows; k++)
109  {
111  //m_Array[j][k] = scoreOneRowPair(j, k, ppScores);
112  m_Array[k][j] = m_Array[j][k];
113  // tell callback function about progress
114  }
115  count += nrows - (j+1);
116  pFunc(count, total);
117  }
118  assert(count == total);
120 
121  // free space allocated for scores
122  /*
123  for (int j=0; j<256; j++) {
124  delete []ppScores[j];
125  }
126  delete []ppScores;
127  */
128  return true;
129 }
130 
131 //d= max(log(s))- log(s)
133 {
134  /*
135  ReplaceZeroWithTinyValue();
136  for (int i=1; i<GetNumRows(); ++i)
137  {
138  for (int j=0; j<i; ++j)
139  {
140  m_Array[i][j] = log(m_Array[i][j]);
141  m_Array[j][i] = m_Array[i][j];
142  }
143  }*/
144  double max = GetMaxEntry();
145  if (FRACTIONAL_EXTRA_OFFSET > 0) {
147  }
148  for (int i=1; i<GetNumRows(); ++i)
149  {
150  for (int j=0; j<i; ++j)
151  {
152  m_Array[i][j] = (max - m_Array[i][j]);
153  m_Array[j][i] = m_Array[i][j];
154  }
155  }
156 }
157 
158 END_SCOPE(cd_utils)
double ** m_Array
Definition: cuMatrix.hpp:47
int GetNumRows() const
Definition: cuMatrix.hpp:84
static const double FRACTIONAL_EXTRA_OFFSET
Definition: cuAlignedDM.hpp:54
MultipleAlignment * m_maligns
Definition: cuAlignedDM.hpp:57
bool setMatrixForExtensionScores(double **matrix, int matrixSize)
void setScoringMatrix(ScoreMatrix *sm)
void setCTermExt(int ext)
bool extendOnePair(int primaryRow, int secondaryRow)
void setNTermExt(int ext)
void setAlignments(MultipleAlignment *ma)
void setBlockExtender(BlockExtender *be)
static const EDistMethod DIST_METHOD
DMAlignedOptimalScore(EScoreMatrixType type=GLOBAL_DEFAULT_SCORE_MATRIX)
virtual bool ComputeMatrix(pProgressFunction pFunc)
void initDMAlignedScore(EScoreMatrixType type, int nTermExt, int cTermExt)
ScoreMatrix * m_scoreMatrix
Definition: cuDistmat.hpp:156
EDistMethod m_dMethod
Definition: cuDistmat.hpp:157
std::vector< std::string > m_ConvertedSequences
Definition: cuDistmat.hpp:154
double GetMaxEntry()
Definition: cuDistmat.cpp:112
EDistMethod
Definition: cuDistmat.hpp:60
@ eScoreAlignedOptimal
Definition: cuDistmat.hpp:65
void(* pProgressFunction)(int Num, int Total)
Definition: cuDistmat.hpp:47
EScoreMatrixType
#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
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
int i
T max(T x_, T y_)
#define assert(x)
Definition: srv_diag.hpp:58
Definition: type.c:6
Modified on Sun Apr 14 05:28:25 2024 by modify_doxy.py rev. 669887