NCBI C++ ToolKit
cuDistmat.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CU_DISTMAT__HPP
2 #define CU_DISTMAT__HPP
3 
4 /* $Id: cuDistmat.hpp 33815 2007-05-04 17:18:18Z kazimird $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Chris Lanczycki
30 *
31 * File Description: cdt_distmat.hpp
32 *
33 * Representation of a distance matrix for phylogenetic calculations.
34 * Note that the base class AMatrix is explicitly a matrix of doubles;
35 * templatize if becomes necessary.
36 *
37 */
38 
42 
45 BEGIN_SCOPE(cd_utils)
46 // pProgressFunction is called by ComputeMatrix to update the progress bar
47 typedef void (* pProgressFunction) (int Num, int Total);
48 
51  "",
52  "Percent Identity (Aligned Residues)",
53  "Kimura-Corrected % Identity (Aligned Residues)",
54  "Score of Aligned Residues",
55  "Score of Optimally-Extended Blocks",
56  "Blast Score (Footprint)",
57  "Blast Score (Full Sequence)",
58  "Percent Identity with variable Alignment"
59 };
69 };
71 
72 
73 // Subclass this class inorder to provide a specific distance matrix
74 // calculation algorithm.
75 
76 // Since this is a distance matrix, diagonal entries should be zero.
77 
79 
80  static const double TINY_DISTANCE;
81  static const double HUGE_DISTANCE;
82 
83 public:
84  static const bool USE_ALIGNED_DEFAULT;
85  static const int NO_EXTENSION;
86  static string GetDistMethodName(EDistMethod method);
87  static bool DistMethodUsesScoringMatrix(EDistMethod method);
88  static bool ExtensionsAllowed(EDistMethod method);
89  static bool RequireAlignedBlocks(EDistMethod method);
90 
91  typedef double TMatType; // type-def for values stored in matrix
92 
94  initialize();
95  }
96 
97 // DistanceMatrix(TCdd& cddref) : AMatrix() {
98  /*
99  DistanceMatrix(const CCd* cddref) : AMatrix() {
100  initialize();
101  SetCDD(cddref);
102  }*/
103 
104  DistanceMatrix(const int nrows) : AMatrix(nrows, nrows) {
105  initialize();
106  }
107 
108  bool UseAll() const { return !m_useAligned;}
109  bool UseAligned() const { return m_useAligned;}
110  void SetUseAligned(bool useAligned) { m_useAligned = useAligned;}
111 
112  double** GetMatrix() { return m_Array;}
113 
114  // GetMax/Min ignore the diagonal entries.
115  double GetMaxEntry();
116  double GetMinEntry();
117 
118  // force the matrix to be symmetric by averaging d_ij and d_ji
119  void EnforceSymmetry();
120 
121  // zero distances in off-diagonals can confuse tree algorithms later;
122  // replace with a tiny number
123  void ReplaceZeroWithTinyValue(const double tiny = TINY_DISTANCE);
124  void SetData(AlignmentCollection* aligns);
125 
126  // distance computation method methods
127  string GetDistMethodName() {return DISTANCE_METHOD_NAMES[m_dMethod];}
128  EDistMethod GetDistMethod() {return m_dMethod;}
129 
130  // scoring matrix methods
131  bool ResetMatrixType(EScoreMatrixType newType); // discards old matrix even if of the same type
132  string GetMatrixName();
133  EScoreMatrixType GetMatrixType();
134 
135  // methods to manage extensions
136  void SetNTermExt(int ext);
137  void SetCTermExt(int ext);
138  int GetNTermExt();
139  int GetCTermExt();
140 
141  // pass ComputeMatrix a pointer-to-function, so ComputeMatrix can call fn with meter updates
142  virtual bool ComputeMatrix(pProgressFunction pFunc) = 0;
143 
144  virtual ~DistanceMatrix();
145  static void readMat(ifstream& ifs, DistanceMatrix& dm, bool triangular);
146  static void writeMat(ofstream& ofs, const DistanceMatrix& dm, bool triangular);
147  void printMat(bool triangular=true);
148 
149 protected:
150  static const int OUTPUT_PRECISION;
151  static const int INITIAL_SCORE_BOUND;
152  typedef char* CharPtr;
153 
154  std::vector< std::string > m_ConvertedSequences;
155 
160 
163 
164  virtual void initialize();
165  void writeMat(ostream& os, bool triangular=true) const;
166 };
167 
168 END_SCOPE(cd_utils)
170 #endif
double ** m_Array
Definition: cuMatrix.hpp:47
bool UseAligned() const
Definition: cuDistmat.hpp:109
ScoreMatrix * m_scoreMatrix
Definition: cuDistmat.hpp:156
EDistMethod m_dMethod
Definition: cuDistmat.hpp:157
double TMatType
Definition: cuDistmat.hpp:91
bool UseAll() const
Definition: cuDistmat.hpp:108
static const int OUTPUT_PRECISION
Definition: cuDistmat.hpp:150
void SetUseAligned(bool useAligned)
Definition: cuDistmat.hpp:110
static const bool USE_ALIGNED_DEFAULT
Definition: cuDistmat.hpp:84
EDistMethod GetDistMethod()
Definition: cuDistmat.hpp:128
virtual bool ComputeMatrix(pProgressFunction pFunc)=0
AlignmentCollection * m_aligns
Definition: cuDistmat.hpp:159
string GetDistMethodName()
Definition: cuDistmat.hpp:127
std::vector< std::string > m_ConvertedSequences
Definition: cuDistmat.hpp:154
DistanceMatrix(const int nrows)
Definition: cuDistmat.hpp:104
static const int INITIAL_SCORE_BOUND
Definition: cuDistmat.hpp:151
static const double HUGE_DISTANCE
Definition: cuDistmat.hpp:81
static const int NO_EXTENSION
Definition: cuDistmat.hpp:85
static const double TINY_DISTANCE
Definition: cuDistmat.hpp:80
double ** GetMatrix()
Definition: cuDistmat.hpp:112
USING_SCOPE(objects)
const EDistMethod GLOBAL_DEFAULT_DIST_METHOD
Definition: cuDistmat.hpp:70
EDistMethod
Definition: cuDistmat.hpp:60
@ eScoreAligned
Definition: cuDistmat.hpp:64
@ eScoreAlignedOptimal
Definition: cuDistmat.hpp:65
@ eScoreBlastFoot
Definition: cuDistmat.hpp:66
@ ePercentIdentity
Definition: cuDistmat.hpp:62
@ ePercentIdentityRelaxed
Definition: cuDistmat.hpp:68
@ eScoreBlastFull
Definition: cuDistmat.hpp:67
@ eNoDistMethod
Definition: cuDistmat.hpp:61
@ ePercIdWithKimura
Definition: cuDistmat.hpp:63
void(* pProgressFunction)(int Num, int Total)
Definition: cuDistmat.hpp:47
const int NUMBER_OF_DISTANCE_METHODS
Definition: cuDistmat.hpp:49
const string DISTANCE_METHOD_NAMES[]
Definition: cuDistmat.hpp:50
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
#define NCBI_CDUTILS_EXPORT
Definition: ncbi_export.h:376
#define const
Definition: zconf.h:230
Modified on Thu Feb 22 17:12:12 2024 by modify_doxy.py rev. 669887