1 #ifndef ALGO_PHY_TREE___BIO_TREE__HPP
2 #define ALGO_PHY_TREE___BIO_TREE__HPP
126 return GetFeatureValue(
id);
192 bool HasFeature(
const string& feature_name)
const;
230 template<
class TBioNode>
310 btr->SetParentTree(*subnode);
337 return value.features[fid];
341 const string& feature_value)
345 btr->
AddFeature(
this, feature_name, feature_value);
382 const string& feature_value);
389 const string& feature_name,
390 const string& feature_value);
451 if (tree_node.GetValue().GetId() ==
m_Uid) {
474 tree_node.SetParentTree(
m_Tree);
537 template<
class TBioNode>
542 template<
class TBioNode>
544 : m_FeatureDict(btr.m_FeatureDict),
545 m_NodeIdCounter(btr.m_NodeIdCounter),
550 template<
class TBioNode>
560 template<
class TBioNode>
566 if (tree_node == 0) {
574 template<
class TBioNode>
577 const string& feature_value)
580 bool id_found = m_FeatureDict.HasFeature(feature_id);
582 node->
GetValue().features.SetFeature(feature_id, feature_value);
588 template<
class TBioNode>
590 const string& feature_name,
591 const string& feature_value)
595 = m_FeatureDict.GetId(feature_name);
598 feature_id = m_FeatureDict.Register(feature_name);
600 AddFeature(node, feature_id, feature_value);
603 template<
class TBioNode>
610 template<
class TBioNode>
615 m_TreeNode.reset(node);
618 template<
class TBioNode>
627 ret = parent_node->
AddNode(node_value);
634 template<
class TBioNode>
640 ret = parent_node->
AddNode(node_value);
647 template<
class TBioNode>
650 m_FeatureDict.Clear();
Basic data contained in every bio-tree node.
Features storage for the bio tree node.
Find node by UID functor.
Basic tree structure for biological applications.
definition of a Culling tree
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.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
TNodeList::iterator TNodeList_I
CBioTreeFeaturePair(TBioTreeFeatureId fid, const string &fvalue)
void SetParentTree(CBioNode &node, CBioTree *tr)
Recursively set parent tree for the node.
TTreeType * DetachNode(TTreeType *subnode)
Remove the subtree from the tree without destroying it.
const TBioTreeNode * GetNode() const
void AddNode(TTreeType *subnode)
Node is added as a subnode the this node.
virtual TBioTreeNodeId GetNodeId(const TBioTreeNode &)
Get new unique node id (for cases when node id depends on the node's content.
const string & GetFeature(const string &feature_name) const
Get dynamic feature by name.
CBioTree(const CBioTree< TBioNode > &btr)
void SetNodeId(TBioTreeNode *node)
Assign new unique node id to the node.
map< string, TBioTreeFeatureId > TFeatureNameIdx
Feature reverse index (feature name -> id)
TFeatureDict m_Dict
id -> feature name map
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...
CTreeNode< TBioNode > TParent
void Clear()
Clear the bio tree.
void SetParentTree(CBioNode &node)
Recursively set this tree as parent tree for the node.
CTreeNode & operator=(const TTreeType &tree)
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
unsigned int TBioTreeNodeId
Tree node id. Every node has its unique id in the tree.
TBioTree * GetParentTree()
Return pointer on the hosting tree (can be NULL)
void PrintNode(CNcbiOstream &os, const CBioTreeDynamic &tree, const CBioTreeDynamic::TBioTreeNode &node, const IBioTreeDynamicLabelFormatter *label_fmt=nullptr)
Newick but without the terminal ';'.
void WriteNewickTree(CNcbiOstream &os, const CBioTreeDynamic &tree, const IBioTreeDynamicLabelFormatter *label_fmt=nullptr)
Newick format output.
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...
CBioNode & operator=(const CBioNode &tree)
Recursive assignment.
const TBioTreeNode * FindNode(TBioTreeNodeId node_id) const
Finds node by id.
CBioTreeFeatureDictionary & GetFeatureDict()
Return feature dictionary.
unsigned int TBioTreeFeatureId
Feature Id.
CFindUidFunc(TBioTreeNodeId uid)
TFeatureNameIdx m_Name2Id
id -> feature name map
CBioTreeFeatureDictionary m_FeatureDict
unique_ptr< TBioTreeNode > m_TreeNode
Top level node.
const CBioTreeFeatureDictionary & GetFeatureDict() const
Return feature dictionary.
virtual string GetLabelForNode(const CBioTreeDynamic::TBioTreeNode &node) const =0
TBioTreeNode * AddNode(const TBioNodeType &node_value, TBioTreeNodeId parent_id)
Add node to the tree (node location is defined by the parent id.
TNodeFeatures TNodeFeaturesType
TFeatureList m_FeatureList
TBioTreeFeatureId GetId(const string &feature_name) const
If feature is already registered returns its id by name.
virtual TBioTreeNodeId GetNodeId()
Get new unique node id.
const TFeatureList & GetFeatureList() const
Return reference on the internal container.
TBioTreeNode * GetTreeNodeNonConst()
CBioNode(const TBioNode &value=TBioNode())
Construct tree node with specified value.
const string & operator[](TBioTreeFeatureId id) const
Get feature value by id (operator semantics)
BioTreeBaseNode(TBioTreeNodeId uid_value=0)
bool operator<(const CBioTreeFeaturePair &rhs) const
virtual ~IBioTreeDynamicLabelFormatter()
CBioTreeFeaturePair(void)
CBioTree< TBioNode > TBioTree
void SetParentTree(TBioTree *pt)
Associate node with the hosting class (non-recursive)
void AddNode(TTreeType *subnode)
Add new subnode.
map< TBioTreeFeatureId, string > TFeatureDict
Feature dictionary (feature id -> feature name map)
CBioNode TBioTreeNode
Biotree node (forms the tree hierarchy)
TTreeType * DetachNode(typename TParent::TNodeList_I it)
Node is detached from the tree (Parent becomes 0)
unsigned int m_IdCounter
Feature id counter.
void SetId(TBioTreeNodeId id)
TNodeFeatures features
list of node features
TBioTreeNode * m_Node
Search result.
ETreeTraverseCode operator()(TBioTreeNode &tree_node, int delta)
CBioTree< BioTreeBaseNode< CBioTreeEmptyNodeData, CBioTreeFeatureList > > CBioTreeDynamic
Bio tree without static elements.
const TBioTreeNode * GetTreeNode() const
TBioTreeNodeId m_Uid
Node uid to search for.
TBioTreeNodeId m_NodeIdCounter
const TBioNode & GetValue(void) const
Return node's value.
TNodeData data
additional node info
CBioNode * AddNode(const TBioNode &val=TBioNode())
Add a subnode to this node based on value.
const TFeatureDict & GetFeatureDict() const
Get reference on the internal map.
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)
ETreeTraverseCode operator()(TBioTreeNode &tree_node, int delta)
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).
vector< CBioTreeFeaturePair > TFeatureList
CAssignTreeFunc(CBioTree *tree)
TBioTreeNodeId GetId() const
const TBioTree * GetParentTree() const
Return pointer on the hosting tree (can be NULL)
void SetTreeNode(TBioTreeNode *node)
Assign new top level tree node.
const string & operator[](const string &feature_name) const
CBioNode(const CBioNode &bn)
Construct tree node based on source tree node (recursive copy)
TBioTreeNodeId uid
Unique node Id.
TBioTree * m_ParentTree
Pointer on the hosting class.
void SetFeature(const string &feature_name, const string &feature_value)
const TTreeType * GetParent(void) const
Get node's parent.
CNcbiOstream & operator<<(CNcbiOstream &os, const CBioTreeDynamic &tree)
Newick format output.
CBioTreeFeaturePair(TBioTreeFeatureId fid)
CBioTree< TBioNode > & operator=(const CBioTree< TBioNode > &btr)
TTreeType * DetachNode(TTreeType *subnode)
@ eTreeTraverseStop
Stop traversal (return form algorithm)
@ eTreeTraverse
Keep traversal.
#define NCBI_XALGOPHYTREE_EXPORT
const GenericPointer< typename T::ValueType > T2 value
Int4 delta(size_t dimension_, const Int4 *score_)
Basic node data structure used by BioTreeBaseNode.
Tree node feature pair (id to string)
Functor to reset tree pointer in all nodes.