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

Go to the SVN repository for this file.

1 #ifndef ALGO_PHY_TREE___BIO_TREE__HPP
2 #define ALGO_PHY_TREE___BIO_TREE__HPP
3 
4 /* $Id: bio_tree.hpp 92082 2020-12-21 15:19:57Z grichenk $
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  * Authors: Anatoliy Kuznetsov
30  *
31  * File Description: Things for representing and manipulating bio trees
32  *
33  */
34 
35 /// @file bio_tree.hpp
36 /// Things for representing and manipulating bio trees.
37 /// CBioTree is the central class here.
38 
39 #include <corelib/ncbistd.hpp>
40 
41 #include <map>
42 #include <string>
43 #include <memory>
44 #include <vector>
45 #include <list>
46 
47 #include <corelib/ncbi_tree.hpp>
48 
50 
51 /** @addtogroup Tree
52  *
53  * @{
54  */
55 
56 
57 /// Feature Id. All bio tree dynamic features are encoded by feature ids.
58 /// Ids are shared among the tree nodes. Feature id to feature name map is
59 /// supported by the tree.
60 typedef unsigned int TBioTreeFeatureId;
61 
62 /// Tree node id. Every node has its unique id in the tree.
63 typedef unsigned int TBioTreeNodeId;
64 
65 
66 
67 
68 /// Tree node feature pair (id to string)
70 {
72  string value;
73 
74  CBioTreeFeaturePair(TBioTreeFeatureId fid, const string& fvalue)
75  : id(fid),
76  value(fvalue)
77  {}
78 
80  : id(fid)
81  {}
82 
84  : id(0)
85  {}
86 
87  bool operator<(const CBioTreeFeaturePair& rhs) const { return (id<rhs.id); }
88 };
89 
90 
91 /// Features storage for the bio tree node
92 ///
93 /// Every node in the bio tree may have a list of attached features.
94 /// Features are string attributes which may vary from node to node in the
95 /// tree.
96 ///
97 /// Implementation note: This class may evolve into a specialized templates
98 /// parameterizing different feature storage options (like vector, map, list)
99 /// depending on what tree is used.
101 {
102 public:
103  typedef vector<CBioTreeFeaturePair> TFeatureList;
104 
107  CBioTreeFeatureList& operator=(const CBioTreeFeatureList& flist);
108 
109  /// Set feature value, feature if exists replaced, if not added.
110  void SetFeature(TBioTreeFeatureId id, const string& value);
111 
112  /// Get feature value by id
113  /// @return Feature value or empty string if feature does not exists
114  const string& GetFeatureValue(TBioTreeFeatureId id) const;
115 
116  /// Place feature value in 'result', if available.
117  /// @return true if feature 'id' is present in the list, false otherwise
118  bool GetFeatureValue(TBioTreeFeatureId id, string& result) const;
119 
120  /// Remove feature from the list
121  void RemoveFeature(TBioTreeFeatureId id);
122 
123  /// Get feature value by id (operator semantics)
124  const string& operator[](TBioTreeFeatureId id) const
125  {
126  return GetFeatureValue(id);
127  }
128 
129  /// Return reference on the internal container
130  const TFeatureList& GetFeatureList() const { return m_FeatureList; }
131 protected:
133 };
134 
135 /// Basic node data structure used by BioTreeBaseNode.
136 /// Strucure carries absolutely no info.
138 {
139 };
140 
141 
142 /// Basic data contained in every bio-tree node
143 ///
144 /// Template parameter NodeData allows to extend list of
145 /// compile-time (non-dynamic attributes in the tree)
146 /// NodeFeatures - extends node with dynamic list of node attributes
147 ///
148 ///
149 template<class TNodeData = CBioTreeEmptyNodeData,
150  class TNodeFeatures = CBioTreeFeatureList>
152 {
153 public:
154  typedef TNodeData TNodeDataType;
155  typedef TNodeFeatures TNodeFeaturesType;
156 public:
157 
159  : uid(uid_value)
160  {}
161 
162  TBioTreeNodeId GetId() const { return uid; }
163 
164  void SetId(TBioTreeNodeId id) { uid = id; }
165 public:
166  TBioTreeNodeId uid; ///< Unique node Id
167  TNodeData data; ///< additional node info
168  TNodeFeatures features; ///< list of node features
169 };
170 
171 
172 /// Feature dictionary.
173 /// Used for mapping between feature ids and feature names.
174 ///
176 {
177 public:
178  /// Feature dictionary (feature id -> feature name map)
180 
181  /// Feature reverse index (feature name -> id)
183 
184 public:
187 
189  operator=(const CBioTreeFeatureDictionary& btr);
190 
191  /// Check if feature is listed in the dictionary
192  bool HasFeature(const string& feature_name) const;
193 
194  /// Check if feature is listed in the dictionary
195  bool HasFeature(TBioTreeFeatureId id) const;
196 
197  /// Register new feature, return its id.
198  /// If feature is already registered just returns the id.
199  /// Feature ids are auto incremented variable managed by the class.
200  TBioTreeFeatureId Register(const string& feature_name);
201 
202  /// Register new feature.
203  /// Throws an exception if a feature with this id or this name already exists
204  void Register(TBioTreeFeatureId id, const string& feature_name);
205 
206  void Unregister(TBioTreeFeatureId id);
207 
208  /// If feature is already registered returns its id by name.
209  /// If feature does not exist returns -1.
210  TBioTreeFeatureId GetId(const string& feature_name) const;
211 
212  /// Return the featue name given the id, or "" if not found
213  string GetName(TBioTreeFeatureId id) const;
214 
215  /// Clear the dictionary
216  void Clear();
217 
218  /// Get reference on the internal map
219  const TFeatureDict& GetFeatureDict() const { return m_Dict; }
220 
221 protected:
222  TFeatureDict m_Dict; ///< id -> feature name map
223  TFeatureNameIdx m_Name2Id; ///< id -> feature name map
224 
225  unsigned int m_IdCounter; ///< Feature id counter
226 };
227 
228 
229 /// Basic tree structure for biological applications
230 template<class TBioNode>
231 class CBioTree
232 {
233 public:
235 
236  // Hide the base class from SWIG
237  #ifdef NCBI_SWIG
238  class CBioNode
239  #else
240  class CBioNode : public CTreeNode<TBioNode>
241  #endif
242  {
243  public:
246 
247  /// Construct tree node with specified value
248  CBioNode(const TBioNode& value = TBioNode())
249  : TParent(value), m_ParentTree(0)
250  {}
251 
252  /// Construct tree node based on source tree node (recursive copy)
253  CBioNode(const CBioNode& bn)
254  : TParent(bn), m_ParentTree(0)
255  {
256  TBioTree* pt = (TBioTree*)bn.GetParentTree();
257  SetParentTree(pt);
258  }
259 
260  /// Recursive assignment
262  {
264  TBioTree* pt = (TBioTree*)tree.GetParentTree();
265  SetParentTree(pt);
266  }
267 
268  /// Associate node with the hosting class (non-recursive)
269  void SetParentTree(TBioTree* pt) { m_ParentTree = pt; }
270 
271  /// Return pointer on the hosting tree (can be NULL)
272  const TBioTree* GetParentTree() const { return m_ParentTree; }
273 
274  /// Return pointer on the hosting tree (can be NULL)
276 
278  {
279  typename TParent::TTreeType* ptn = TParent::DetachNode(subnode);
280  if (ptn) {
281  TTreeType* n = (TTreeType*) ptn;
282  TBioTree* btr = GetParentTree();
283  if (btr) {
284  btr->SetParentTree(*n, 0);
285  }
286  return n;
287  }
288  return 0;
289  }
290 
291  /// Node is detached from the tree (Parent becomes 0)
293  {
294  typename TParent::TTreeType* ptn = TParent::DetachNode(it);
295  if (ptn) {
296  TTreeType* n = (TTreeType*) ptn;
297  TBioTree* btr = GetParentTree();
298  if (btr) {
299  btr->SetParentTree(*n, 0);
300  }
301  return n;
302  }
303  return 0;
304  }
305 
306  /// Node is added as a subnode the this node
307  void AddNode(TTreeType* subnode)
308  {
309  if (TBioTree* btr = GetParentTree()) {
310  btr->SetParentTree(*subnode);
311  }
312  TParent::AddNode(subnode);
313  }
314 
315  /// Add a subnode to this node based on value
316  CBioNode* AddNode(const TBioNode& val = TBioNode())
317  {
318  CBioNode* subnode = new CBioNode(val);
319  AddNode(subnode);
320  return subnode;
321  }
322 
323 
324  /// Get dynamic feature by name
325  const string& GetFeature(const string& feature_name) const
326  {
327  const TBioTree* btr = GetParentTree();
328  _ASSERT(btr);
329  const CBioTreeFeatureDictionary& dict = btr->GetFeatureDict();
330 
331  TBioTreeFeatureId fid = dict.GetId(feature_name);
332 
333  if (fid == (TBioTreeFeatureId)-1)
334  return kEmptyStr;
335 
336  const TBioNode& value = TParent::GetValue();
337  return value.features[fid];
338  }
339 
340  void SetFeature(const string& feature_name,
341  const string& feature_value)
342  {
343  TBioTree* btr = GetParentTree();
344  _ASSERT(btr);
345  btr->AddFeature(this, feature_name, feature_value);
346  }
347 
348  const string& operator[](const string& feature_name) const
349  {
350  return GetFeature(feature_name);
351  }
352 
353  protected:
354  TBioTree* m_ParentTree; ///< Pointer on the hosting class
355  };
356 
357  /// Biotree node (forms the tree hierarchy)
358  typedef CBioNode TBioTreeNode;
359  typedef TBioNode TBioNodeType;
360 
361 public:
362 
364  virtual ~CBioTree() {}
365 
367 
369 
370 
371  /// Finds node by id.
372  /// @return
373  /// Node pointer or NULL if requested node id is unknown
374  const TBioTreeNode* FindNode(TBioTreeNodeId node_id) const;
375 
376 
377  /// Add feature to the tree node
378  /// Function controls that the feature is registered in the
379  /// feature dictionary of this tree.
381  TBioTreeFeatureId feature_id,
382  const string& feature_value);
383 
384  /// Add feature to the tree node
385  /// Function controls that the feature is registered in the
386  /// feature dictionary of this tree. If feature is not found
387  /// it is added to the dictionary
389  const string& feature_name,
390  const string& feature_value);
391 
392  /// Get new unique node id
393  virtual TBioTreeNodeId GetNodeId() { return m_NodeIdCounter++; }
394 
395  /// Get new unique node id
396  /// (for cases when node id depends on the node's content
397  virtual TBioTreeNodeId GetNodeId(const TBioTreeNode& /*node*/)
398  { return m_NodeIdCounter++; }
399 
400  /// Assign new unique node id to the node
401  void SetNodeId(TBioTreeNode* node);
402 
403  /// Assign new top level tree node
405 
406  const TBioTreeNode* GetTreeNode() const { return m_TreeNode.get(); }
407 
409 
410  void DetachTreeNode() { m_TreeNode.release(); }
411 
412  /// Add node to the tree (node location is defined by the parent id
413  TBioTreeNode* AddNode(const TBioNodeType& node_value,
414  TBioTreeNodeId parent_id);
415 
416  /// Add a node to the tree when you have already looked up
417  /// the parent node (faster)
418  TBioTreeNode* AddNode(const TBioNodeType& node_value,
419  TBioTreeNode* parent_node);
420 
421  /// Recursively set this tree as parent tree for the node
422  void SetParentTree(CBioNode& node) { SetParentTree(node, this); }
423 
424  /// Recursively set parent tree for the node
425  void SetParentTree(CBioNode& node, CBioTree* tr)
426  { TreeDepthFirstTraverse(node, CAssignTreeFunc(tr)); }
427 
428  /// Clear the bio tree
429  void Clear();
430 
431  /// Return feature dictionary
433 
434  /// Return feature dictionary
436  { return m_FeatureDict; }
437 
438 protected:
439 
440  /// Find node by UID functor
441  ///
442  /// @internal
444  {
445  public:
447 
449  {
450  if (delta == 0 || delta == 1) {
451  if (tree_node.GetValue().GetId() == m_Uid) {
452  m_Node = &tree_node;
453  return eTreeTraverseStop;
454  }
455  }
456  return eTreeTraverse;
457  }
458 
459  const TBioTreeNode* GetNode() const { return m_Node; }
460  private:
461  TBioTreeNodeId m_Uid; ///< Node uid to search for
462  TBioTreeNode* m_Node; ///< Search result
463  };
464 
465  /// Functor to reset tree pointer in all nodes
466  ///
467  /// @internal
469  {
472  {
473  if (delta == 0 || delta == 1)
474  tree_node.SetParentTree(m_Tree);
475  return eTreeTraverse;
476  }
477  private:
479  };
480 
481 protected:
484  unique_ptr<TBioTreeNode> m_TreeNode; ///< Top level node
485 };
486 
487 
488 /// Bio tree without static elements. Everything is stored as features.
489 ///
490 /// @internal
491 typedef
494 
495 /// Interface to obtain custom labels for nodes
497 {
498 public:
499  virtual string GetLabelForNode(const CBioTreeDynamic::TBioTreeNode &node) const = 0;
501 };
502 
503 
504 /// Newick format output
507 
508 /// Newick format output
509 ///
510 /// tree_name gets put in the file.
513  const IBioTreeDynamicLabelFormatter* label_fmt = nullptr);
514 
515 /// Nexus format output (Newick with some stuff around it).
516 ///
517 /// tree_name gets put in the file.
520  const string& tree_name = "the_tree", const IBioTreeDynamicLabelFormatter* label_fmt = nullptr);
521 
522 /// Newick but without the terminal ';'
524 void PrintNode(CNcbiOstream& os, const CBioTreeDynamic& tree,
525  const CBioTreeDynamic::TBioTreeNode& node, const IBioTreeDynamicLabelFormatter* label_fmt = nullptr);
526 
527 
528 /* @} */
529 
530 
531 /////////////////////////////////////////////////////////////////////////////
532 //
533 // CBioTree<TBioNode>
534 //
535 
536 
537 template<class TBioNode>
539 : m_NodeIdCounter(0)
540 {}
541 
542 template<class TBioNode>
544 : m_FeatureDict(btr.m_FeatureDict),
545  m_NodeIdCounter(btr.m_NodeIdCounter),
546  m_TreeNode(new TBioTreeNode(*(btr.m_TreeNode)))
547 {
548 }
549 
550 template<class TBioNode>
553 {
554  m_FeatureDict = btr.m_FeatureDict;
555  m_NodeIdCounter = btr.m_NodeIdCounter;
556  m_TreeNode.reset(new TBioTreeNode(*(btr.m_TreeNode)));
557  return *this;
558 }
559 
560 template<class TBioNode>
561 const typename CBioTree<TBioNode>::TBioTreeNode*
563 {
564  TBioTreeNode* tree_node =
565  const_cast<TBioTreeNode*>(m_TreeNode.get());
566  if (tree_node == 0) {
567  return 0;
568  }
569  CFindUidFunc func =
570  TreeDepthFirstTraverse(*tree_node, CFindUidFunc(node_id));
571  return func.GetNode();
572 }
573 
574 template<class TBioNode>
576  TBioTreeFeatureId feature_id,
577  const string& feature_value)
578 {
579  // Check if this id is in the dictionary
580  bool id_found = m_FeatureDict.HasFeature(feature_id);
581  if (id_found) {
582  node->GetValue().features.SetFeature(feature_id, feature_value);
583  } else {
584  // TODO:throw an exception here
585  }
586 }
587 
588 template<class TBioNode>
590  const string& feature_name,
591  const string& feature_value)
592 {
593  // Check if this id is in the dictionary
594  TBioTreeFeatureId feature_id
595  = m_FeatureDict.GetId(feature_name);
596  if (feature_id == (TBioTreeFeatureId)-1) {
597  // Register the new feature type
598  feature_id = m_FeatureDict.Register(feature_name);
599  }
600  AddFeature(node, feature_id, feature_value);
601 }
602 
603 template<class TBioNode>
605 {
606  TBioTreeNodeId uid = GetNodeId(*node);
607  node->GetValue().uid = uid;
608 }
609 
610 template<class TBioNode>
612 {
613  _ASSERT(node->GetParent() == 0);
615  m_TreeNode.reset(node);
616 }
617 
618 template<class TBioNode>
621  TBioTreeNodeId parent_id)
622 {
623  TBioTreeNode* ret = 0;
624  const TBioTreeNode* pnode = FindNode(parent_id);
625  if (pnode) {
626  TBioTreeNode* parent_node = const_cast<TBioTreeNode*>(pnode);
627  ret = parent_node->AddNode(node_value);
628  // done by AddNode:
629  //TreeDepthFirstTraverse(*ret, CAssignTreeFunc(this));
630  }
631  return ret;
632 }
633 
634 template<class TBioNode>
637  TBioTreeNode* parent_node)
638 {
639  TBioTreeNode* ret = 0;
640  ret = parent_node->AddNode(node_value);
641  //done by AddNode:
642  //TreeDepthFirstTraverse(*ret, CAssignTreeFunc(this));
643 
644  return ret;
645 }
646 
647 template<class TBioNode>
649 {
650  m_FeatureDict.Clear();
651  m_NodeIdCounter = 0;
652  m_TreeNode.reset(0);
653 }
654 
655 /// Bio tree without static elements. Everything is stored as features.
656 ///
657 /// @internal
658 typedef
661 
662 
663 END_NCBI_SCOPE // ALGO_PHY_TREE___BIO_TREE__HPP
664 
665 #endif
Basic data contained in every bio-tree node.
Definition: bio_tree.hpp:152
Feature dictionary.
Definition: bio_tree.hpp:176
Features storage for the bio tree node.
Definition: bio_tree.hpp:101
Find node by UID functor.
Definition: bio_tree.hpp:444
Basic tree structure for biological applications.
Definition: bio_tree.hpp:232
definition of a Culling tree
Definition: ncbi_tree.hpp:100
Interface to obtain custom labels for nodes.
Definition: bio_tree.hpp:497
Include a standard set of the NCBI C++ Toolkit most basic headers.
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
TNodeList::iterator TNodeList_I
Definition: ncbi_tree.hpp:109
CBioTreeFeaturePair(TBioTreeFeatureId fid, const string &fvalue)
Definition: bio_tree.hpp:74
void SetParentTree(CBioNode &node, CBioTree *tr)
Recursively set parent tree for the node.
Definition: bio_tree.hpp:425
TTreeType * DetachNode(TTreeType *subnode)
Remove the subtree from the tree without destroying it.
Definition: ncbi_tree.hpp:720
const TBioTreeNode * GetNode() const
Definition: bio_tree.hpp:459
void AddNode(TTreeType *subnode)
Node is added as a subnode the this node.
Definition: bio_tree.hpp:307
virtual TBioTreeNodeId GetNodeId(const TBioTreeNode &)
Get new unique node id (for cases when node id depends on the node's content.
Definition: bio_tree.hpp:397
const string & GetFeature(const string &feature_name) const
Get dynamic feature by name.
Definition: bio_tree.hpp:325
CBioTree(const CBioTree< TBioNode > &btr)
Definition: bio_tree.hpp:543
virtual ~CBioTree()
Definition: bio_tree.hpp:364
void SetNodeId(TBioTreeNode *node)
Assign new unique node id to the node.
Definition: bio_tree.hpp:604
map< string, TBioTreeFeatureId > TFeatureNameIdx
Feature reverse index (feature name -> id)
Definition: bio_tree.hpp:182
TFeatureDict m_Dict
id -> feature name map
Definition: bio_tree.hpp:222
void AddFeature(TBioTreeNode *node, const string &feature_name, const string &feature_value)
Add feature to the tree node Function controls that the feature is registered in the feature dictiona...
Definition: bio_tree.hpp:589
CTreeNode< TBioNode > TParent
Definition: bio_tree.hpp:244
void Clear()
Clear the bio tree.
Definition: bio_tree.hpp:648
void SetParentTree(CBioNode &node)
Recursively set this tree as parent tree for the node.
Definition: bio_tree.hpp:422
CTreeNode & operator=(const TTreeType &tree)
Definition: ncbi_tree.hpp:678
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
Definition: ncbi_tree.hpp:504
TNodeData TNodeDataType
Definition: bio_tree.hpp:154
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
Definition: ncbi_tree.hpp:51
unsigned int TBioTreeNodeId
Tree node id. Every node has its unique id in the tree.
Definition: bio_tree.hpp:63
TBioTree * GetParentTree()
Return pointer on the hosting tree (can be NULL)
Definition: bio_tree.hpp:275
void PrintNode(CNcbiOstream &os, const CBioTreeDynamic &tree, const CBioTreeDynamic::TBioTreeNode &node, const IBioTreeDynamicLabelFormatter *label_fmt=nullptr)
Newick but without the terminal ';'.
Definition: bio_tree.cpp:230
void WriteNewickTree(CNcbiOstream &os, const CBioTreeDynamic &tree, const IBioTreeDynamicLabelFormatter *label_fmt=nullptr)
Newick format output.
Definition: bio_tree.cpp:280
void AddFeature(TBioTreeNode *node, TBioTreeFeatureId feature_id, const string &feature_value)
Add feature to the tree node Function controls that the feature is registered in the feature dictiona...
Definition: bio_tree.hpp:575
CBioNode & operator=(const CBioNode &tree)
Recursive assignment.
Definition: bio_tree.hpp:261
const TBioTreeNode * FindNode(TBioTreeNodeId node_id) const
Finds node by id.
Definition: bio_tree.hpp:562
CBioTreeFeatureDictionary & GetFeatureDict()
Return feature dictionary.
Definition: bio_tree.hpp:432
unsigned int TBioTreeFeatureId
Feature Id.
Definition: bio_tree.hpp:60
CFindUidFunc(TBioTreeNodeId uid)
Definition: bio_tree.hpp:446
TFeatureNameIdx m_Name2Id
id -> feature name map
Definition: bio_tree.hpp:223
CBioTreeFeatureDictionary m_FeatureDict
Definition: bio_tree.hpp:482
unique_ptr< TBioTreeNode > m_TreeNode
Top level node.
Definition: bio_tree.hpp:484
const CBioTreeFeatureDictionary & GetFeatureDict() const
Return feature dictionary.
Definition: bio_tree.hpp:435
virtual string GetLabelForNode(const CBioTreeDynamic::TBioTreeNode &node) const =0
TBioNode TBioNodeType
Definition: bio_tree.hpp:359
TBioTreeNode * AddNode(const TBioNodeType &node_value, TBioTreeNodeId parent_id)
Add node to the tree (node location is defined by the parent id.
Definition: bio_tree.hpp:620
TNodeFeatures TNodeFeaturesType
Definition: bio_tree.hpp:155
TFeatureList m_FeatureList
Definition: bio_tree.hpp:132
TBioTreeFeatureId GetId(const string &feature_name) const
If feature is already registered returns its id by name.
Definition: bio_tree.cpp:209
virtual TBioTreeNodeId GetNodeId()
Get new unique node id.
Definition: bio_tree.hpp:393
const TFeatureList & GetFeatureList() const
Return reference on the internal container.
Definition: bio_tree.hpp:130
TBioTreeNode * GetTreeNodeNonConst()
Definition: bio_tree.hpp:408
CBioNode(const TBioNode &value=TBioNode())
Construct tree node with specified value.
Definition: bio_tree.hpp:248
const string & operator[](TBioTreeFeatureId id) const
Get feature value by id (operator semantics)
Definition: bio_tree.hpp:124
void DetachTreeNode()
Definition: bio_tree.hpp:410
BioTreeBaseNode(TBioTreeNodeId uid_value=0)
Definition: bio_tree.hpp:158
bool operator<(const CBioTreeFeaturePair &rhs) const
Definition: bio_tree.hpp:87
virtual ~IBioTreeDynamicLabelFormatter()
Definition: bio_tree.hpp:500
CBioTreeFeaturePair(void)
Definition: bio_tree.hpp:83
CBioTree< TBioNode > TBioTree
Definition: bio_tree.hpp:234
void SetParentTree(TBioTree *pt)
Associate node with the hosting class (non-recursive)
Definition: bio_tree.hpp:269
void AddNode(TTreeType *subnode)
Add new subnode.
Definition: ncbi_tree.hpp:743
map< TBioTreeFeatureId, string > TFeatureDict
Feature dictionary (feature id -> feature name map)
Definition: bio_tree.hpp:179
CBioNode TBioTreeNode
Biotree node (forms the tree hierarchy)
Definition: bio_tree.hpp:358
TTreeType * DetachNode(typename TParent::TNodeList_I it)
Node is detached from the tree (Parent becomes 0)
Definition: bio_tree.hpp:292
unsigned int m_IdCounter
Feature id counter.
Definition: bio_tree.hpp:225
void SetId(TBioTreeNodeId id)
Definition: bio_tree.hpp:164
TNodeFeatures features
list of node features
Definition: bio_tree.hpp:168
TBioTreeNode * m_Node
Search result.
Definition: bio_tree.hpp:462
ETreeTraverseCode operator()(TBioTreeNode &tree_node, int delta)
Definition: bio_tree.hpp:448
CBioNode TTreeType
Definition: bio_tree.hpp:245
CBioTree< BioTreeBaseNode< CBioTreeEmptyNodeData, CBioTreeFeatureList > > CBioTreeDynamic
Bio tree without static elements.
Definition: bio_tree.hpp:493
const TBioTreeNode * GetTreeNode() const
Definition: bio_tree.hpp:406
TBioTreeNodeId m_Uid
Node uid to search for.
Definition: bio_tree.hpp:461
TBioTreeNodeId m_NodeIdCounter
Definition: bio_tree.hpp:483
const TBioNode & GetValue(void) const
Return node's value.
Definition: ncbi_tree.hpp:184
TNodeData data
additional node info
Definition: bio_tree.hpp:167
CBioNode * AddNode(const TBioNode &val=TBioNode())
Add a subnode to this node based on value.
Definition: bio_tree.hpp:316
const TFeatureDict & GetFeatureDict() const
Get reference on the internal map.
Definition: bio_tree.hpp:219
TBioTreeNode * AddNode(const TBioNodeType &node_value, TBioTreeNode *parent_node)
Add a node to the tree when you have already looked up the parent node (faster)
Definition: bio_tree.hpp:636
ETreeTraverseCode operator()(TBioTreeNode &tree_node, int delta)
Definition: bio_tree.hpp:471
void WriteNexusTree(CNcbiOstream &os, const CBioTreeDynamic &tree, const string &tree_name="the_tree", const IBioTreeDynamicLabelFormatter *label_fmt=nullptr)
Nexus format output (Newick with some stuff around it).
Definition: bio_tree.cpp:287
vector< CBioTreeFeaturePair > TFeatureList
Definition: bio_tree.hpp:103
CAssignTreeFunc(CBioTree *tree)
Definition: bio_tree.hpp:470
TBioTreeNodeId GetId() const
Definition: bio_tree.hpp:162
const TBioTree * GetParentTree() const
Return pointer on the hosting tree (can be NULL)
Definition: bio_tree.hpp:272
void SetTreeNode(TBioTreeNode *node)
Assign new top level tree node.
Definition: bio_tree.hpp:611
const string & operator[](const string &feature_name) const
Definition: bio_tree.hpp:348
CBioNode(const CBioNode &bn)
Construct tree node based on source tree node (recursive copy)
Definition: bio_tree.hpp:253
TBioTreeNodeId uid
Unique node Id.
Definition: bio_tree.hpp:166
TBioTree * m_ParentTree
Pointer on the hosting class.
Definition: bio_tree.hpp:354
void SetFeature(const string &feature_name, const string &feature_value)
Definition: bio_tree.hpp:340
const TTreeType * GetParent(void) const
Get node's parent.
Definition: ncbi_tree.hpp:139
CNcbiOstream & operator<<(CNcbiOstream &os, const CBioTreeDynamic &tree)
Newick format output.
Definition: bio_tree.cpp:273
CBioTreeFeaturePair(TBioTreeFeatureId fid)
Definition: bio_tree.hpp:79
TBioTreeFeatureId id
Definition: bio_tree.hpp:71
CBioTree< TBioNode > & operator=(const CBioTree< TBioNode > &btr)
Definition: bio_tree.hpp:552
TTreeType * DetachNode(TTreeType *subnode)
Definition: bio_tree.hpp:277
@ eTreeTraverseStop
Stop traversal (return form algorithm)
Definition: ncbi_tree.hpp:53
@ eTreeTraverse
Keep traversal.
Definition: ncbi_tree.hpp:52
#define NCBI_XALGOPHYTREE_EXPORT
Definition: ncbi_export.h:1009
yy_size_t n
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Int4 delta(size_t dimension_, const Int4 *score_)
Basic node data structure used by BioTreeBaseNode.
Definition: bio_tree.hpp:138
Tree node feature pair (id to string)
Definition: bio_tree.hpp:70
Functor to reset tree pointer in all nodes.
Definition: bio_tree.hpp:469
#define _ASSERT
else result
Definition: token2.c:20
Modified on Fri Sep 20 14:58:05 2024 by modify_doxy.py rev. 669887