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

Go to the SVN repository for this file.

1 #ifndef CU_TREEALG__HPP
2 #define CU_TREEALG__HPP
3 
4 /* $Id: cuSeqTreeAlg.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:
32 * Virtual base class for representing sequence-tree calculation algorithms.
33 * Implementations of specific algorithms should be subclasses that define,
34 * minimally, the ComputeTree method.
35 *
36 */
37 
40 
43 BEGIN_SCOPE(cd_utils)
44 
47  "",
48  "Single Linkage Clustering",
49  "Neighbor Joining"
50  //"Fast Minimum Evolution"
51 };
52 
55  eSLC=1,
56  eNJ=2
57  //eME=3
58 }; // add name to array above and increment # algorithms
60 
62 string GetTreeAlgorithmName(ETreeMethod algorithm);
63 
64 
65 const double RESET_WITH_TINY_DISTANCE = 0.0001; // used to reset zero-distance leafs in MPRooting
66 
68 void MidpointRootSeqTree(const SeqTree& oldTree, SeqTree& newTree);
69 //SeqTree MidpointRootSeqTree(const SeqTree& oldTree);
71 bool GetMaxPath(const SeqTree& atree, double& dMax, SeqTree::iterator& end1, SeqTree::iterator& end2);
73 bool GetMaxPath(const SeqTree::iterator& cursor, double& dMax, double& dBranch1, SeqTree::iterator& end1, double& dBranch2, SeqTree::iterator& end2);
74 
75 
77 
78 public:
79 
80  enum Rootedness {
81  eUnrooted=0,
82  eRooted=1,
83  eMidpointRooted=2
84  };
85 
86 private:
87 
88  static const string NO_NAME;
89  static const Rootedness DEF_ROOTED;
90 
91 public:
92 
95  typedef vector< TSeqIt > TTreeIt;
96 /*
97  TreeAlgorithm(string name=NO_NAME) : m_tree(NULL), m_tmethod(eNone) {
98  m_rootedness = DEF_ROOTED;
99  }
100 */
101  TreeAlgorithm(Rootedness rooted = DEF_ROOTED, ETreeMethod tmethod = eNoTreeMethod)
102  : m_tree(NULL), m_rootedness(rooted), m_tmethod(tmethod) {
103  }
104 
105 
106  const SeqTree* GetTree() const {
107  return m_tree;
108  }
109 /*
110  void SetName(string name) {
111  m_name = name;
112  }
113  const string GetName() const {
114  return m_name;
115  }
116  */
117 
118  string GetName() {
119  return TREE_ALGORITHM_NAMES[m_tmethod];
120  }
122  return m_tmethod;
123  }
124 
125  void SetRootedness(Rootedness rooted) {
126  m_rootedness = rooted;
127  }
129  return m_rootedness;
130  }
131  bool isRooted() {
132  bool r = (m_rootedness == eUnrooted) ? false : true;
133  return r;
134  }
135 
136  void SetMidpointRooting(bool rooting) {
137  if (rooting) {
138  m_rootedness = eMidpointRooted;
139  } else if (m_rootedness == eMidpointRooted) {
140  m_rootedness = DEF_ROOTED;
141  }
142  }
144  return (m_rootedness == eMidpointRooted);
145  }
146 
147 
148  virtual ~TreeAlgorithm(){}
149  virtual long GetNumLoopsForTreeCalc() = 0;
150  virtual void ComputeTree(SeqTree* tree, pProgressFunction pFunc) = 0;
151  virtual string toString(){return kEmptyStr;}
152 
153  //virtual void SetCDD(CCd* cdd){};
154  virtual void SetDistMat(DistanceMatrix* dm){};
155 
156  //void fillSeqNames(SeqTree* treeData, CCd* pCd);
157 
158  const DistanceMatrix* GetDistMat() const {
159  return m_dm;
160  }
161 
162 protected:
163 
165 
166  DistanceMatrix* m_dm; // Distance matrix used to compute the tree
167  //CCd* m_cdd; // Optionally defined CD for which this tree is generated.
168 
169 // string m_name;
172 
173  void midpointRootIfNeeded();
174 };
175 
176 END_SCOPE(cd_utils)
178 
179 #endif /* CU_TREEALG__HPP */
const SeqTree * GetTree() const
vector< TSeqIt > TTreeIt
static const Rootedness DEF_ROOTED
ETreeMethod GetTreeMethod()
SeqTree * m_tree
bool useMidpointRooting()
virtual ~TreeAlgorithm()
virtual void ComputeTree(SeqTree *tree, pProgressFunction pFunc)=0
void SetRootedness(Rootedness rooted)
DistanceMatrix * m_dm
SeqTree::iterator TSeqIt
ETreeMethod m_tmethod
virtual void SetDistMat(DistanceMatrix *dm)
void SetMidpointRooting(bool rooting)
Rootedness m_rootedness
string GetName()
virtual string toString()
TreeAlgorithm(Rootedness rooted=DEF_ROOTED, ETreeMethod tmethod=eNoTreeMethod)
virtual long GetNumLoopsForTreeCalc()=0
const DistanceMatrix * GetDistMat() const
SeqTree::sibling_iterator TChildIt
Rootedness GetRootedness()
static const string NO_NAME
void(* pProgressFunction)(int Num, int Total)
Definition: cuDistmat.hpp:47
USING_SCOPE(objects)
const ETreeMethod GLOBAL_DEFAULT_ALGORITHM
string GetTreeAlgorithmName(ETreeMethod algorithm)
Definition: cuSeqTreeNj.cpp:47
const int NUMBER_OF_TREE_ALGORITHMS
bool GetMaxPath(const SeqTree &atree, double &dMax, SeqTree::iterator &end1, SeqTree::iterator &end2)
void MidpointRootSeqTree(const SeqTree &oldTree, SeqTree &newTree)
ETreeMethod
@ eNJ
@ eNoTreeMethod
@ eSLC
const string TREE_ALGORITHM_NAMES[]
const double RESET_WITH_TINY_DISTANCE
meTree * newTree()
Definition: graph.cpp:102
#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
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_CDUTILS_EXPORT
Definition: ncbi_export.h:376
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
#define const
Definition: zconf.h:230
Modified on Fri Mar 01 10:08:09 2024 by modify_doxy.py rev. 669887