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

Go to the SVN repository for this file.

1 /* $Id: cuSeqTreeFactory.cpp 46200 2010-06-18 14:23:18Z 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 * Author: Chris Lanczycki
27 *
28 * File Description:
29 * Factory class to create TreeAlgorithm and DistanceMatrix instances.
30 * Specific subclass determined by parameters supplied by client.
31 * Enums referenced here defined in the two base classes.
32 *
33 */
34 
35 #include <ncbi_pch.hpp>
37 
38 // Distance matrix headers for concrete classes
43 // Tree algorithm method headers
46 
48 BEGIN_SCOPE(cd_utils)
49 
50 void static dummyMeter(int Num, int Total)
51 {
52 }
53 
55 {
56  CNcbiOstrstream oss;
57  oss << "TreeOptions state:\n";
58  oss << "clusteringMethod = " << clusteringMethod << endl;
59  oss << "distMethod = " << distMethod << endl;
60  oss << "matrix = " << matrix << endl;
61  oss << "nTermExt = " << nTermExt << endl;
62  oss << "cTermExt = " << cTermExt << endl;
63  oss << "tree scope = " << scope << endl;
64  oss << "color scope = " << coloringScope << endl;
65  return CNcbiOstrstreamToString(oss);
66 }
67 
69 {
70  SeqTree* treeData = 0;
71  TreeFactory treeFactory;
72  DistanceMatrix* distMat = treeFactory.GetMatrix(treeOptions.distMethod, alignData, treeOptions.matrix,
73  treeOptions.nTermExt, treeOptions.cTermExt);
74 
75  if (distMat)
76  {
77  DMAlignedOptimalScore * dmAos ;
78  BlockExtender* blockExtender = 0;
79  try {
80  dmAos = dynamic_cast<DMAlignedOptimalScore *> (distMat);
81  }catch (...){
82  dmAos = 0;
83  }
84  if (dmAos)
85  {
86  blockExtender = new BlockExtender();
87  dmAos->setBlockExtender(blockExtender);
88  }
89  distMat->ComputeMatrix(dummyMeter);
90  if (blockExtender)
91  delete blockExtender;
92  TreeAlgorithm* treeAlg = treeFactory.GetAlgorithm(treeOptions.clusteringMethod);
93 
94  if (treeAlg)
95  {
96  treeAlg->SetDistMat(distMat);
97  treeData = new SeqTree();
98  treeAlg->ComputeTree(treeData, dummyMeter);
99  treeData->fixRowNumber(*alignData);
100  }
101  }
102  return treeData;
103 }
104 
106 
107  if (!m_algorithm) {
108  switch (method) {
109  case eNJ:
111  break;
112  case eSLC:
114  break;
115  /*
116  case eME:
117  m_algorithm = new ME_TreeAlgorithm();
118  break;*/
119  case eNoTreeMethod:
120  default:
121  break;
122  }
123  }
125  return m_algorithm;
126 }
127 
129  const int nTermExt, const int cTermExt) {
130  MultipleAlignment* pma;
131  try{
132  pma = dynamic_cast<MultipleAlignment*>(alignData);
133  }
134  catch (...){
135  pma =0;
136  }
137  if (!m_matrix) {
138  switch (method) {
139  case ePercentIdentity:
140  if (pma)
141  {
142  m_matrix = new DM_Identities(scoreMatrix);
143  ((DM_Identities*)m_matrix)->SetKimura(false);
144  ((AlignedDM*)m_matrix)->setData(pma);
145  }
146  break;
147  case ePercIdWithKimura:
148  if(pma)
149  {
150  m_matrix = new DM_Identities(scoreMatrix);
151  ((DM_Identities*)m_matrix)->SetKimura(true);
152  ((AlignedDM*)m_matrix)->setData(pma);
153  }
154  break;
155  case eScoreAligned:
156  if(pma)
157  {
158  m_matrix = new DM_AlignedScore(scoreMatrix);
159  ((AlignedDM*)m_matrix)->setData(pma);
160  }
161  break;
163  if(pma)
164  {
165  m_matrix = new DMAlignedOptimalScore(scoreMatrix);
166  ((AlignedDM*)m_matrix)->setData(pma);
167  m_matrix->SetNTermExt(nTermExt);
168  m_matrix->SetCTermExt(cTermExt);
169  }
170  break;
172  m_matrix = new FlexiDm(scoreMatrix);
173  m_matrix->SetData(alignData);
174  break;
175  /*
176  case eScoreBlastFoot:
177  m_matrix = new DM_BlastScore(scoreMatrix, nTermExt, cTermExt);
178  ((DM_BlastScore*)m_matrix)->SetUseFullSequence(false);
179  m_matrix->SetData(alignData);
180  break;
181  case eScoreBlastFull:
182  m_matrix = new DM_BlastScore(scoreMatrix);
183  ((DM_BlastScore*)m_matrix)->SetUseFullSequence(true);
184  m_matrix->SetData(alignData);
185  break;*/
186  case eNoDistMethod:
187  default:
188  break;
189  }
190  }
191 
192  return m_matrix;
193 }
194 
195 END_SCOPE(cd_utils)
#define static
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
void setBlockExtender(BlockExtender *be)
void SetNTermExt(int ext)
Definition: cuDistmat.cpp:154
virtual bool ComputeMatrix(pProgressFunction pFunc)=0
void SetCTermExt(int ext)
Definition: cuDistmat.cpp:161
void SetData(AlignmentCollection *aligns)
Definition: cuDistmat.cpp:105
void fixRowNumber(AlignmentCollection &aligns)
Definition: cuSeqtree.cpp:584
virtual void ComputeTree(SeqTree *tree, pProgressFunction pFunc)=0
virtual void SetDistMat(DistanceMatrix *dm)
void SetMidpointRooting(bool rooting)
static SeqTree * makeTree(AlignmentCollection *alignData, const TreeOptions &treeOptions)
virtual TreeAlgorithm * GetAlgorithm(const ETreeMethod method, bool mpRoot=true)
TreeAlgorithm * m_algorithm
virtual DistanceMatrix * GetMatrix(const EDistMethod method, AlignmentCollection *alignData, const EScoreMatrixType matrix=GLOBAL_DEFAULT_SCORE_MATRIX, const int nTermExt=DistanceMatrix::NO_EXTENSION, const int cTermExt=DistanceMatrix::NO_EXTENSION)
DistanceMatrix * m_matrix
const DistanceMatrix * GetMatrix() const
EDistMethod
Definition: cuDistmat.hpp:60
@ eScoreAligned
Definition: cuDistmat.hpp:64
@ eScoreAlignedOptimal
Definition: cuDistmat.hpp:65
@ ePercentIdentity
Definition: cuDistmat.hpp:62
@ ePercentIdentityRelaxed
Definition: cuDistmat.hpp:68
@ eNoDistMethod
Definition: cuDistmat.hpp:61
@ ePercIdWithKimura
Definition: cuDistmat.hpp:63
EScoreMatrixType
ETreeMethod
@ eNJ
@ eNoTreeMethod
@ eSLC
static void dummyMeter(int Num, int Total)
#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
CAlgorithm_type::EColoring_scope coloringScope
ETreeMethod clusteringMethod
EDistMethod distMethod
EScoreMatrixType matrix
CAlgorithm_type::ETree_scope scope
Modified on Wed Feb 28 07:11:33 2024 by modify_doxy.py rev. 669887