A library for working with phylogenetic and population genetic data.
v0.32.0
tree/mass_tree/tree.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_MASS_TREE_TREE_H_
2 #define GENESIS_TREE_MASS_TREE_TREE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include "genesis/tree/tree.hpp"
37 
38 #include <map>
39 
40 namespace genesis {
41 namespace tree {
42 
43 // =================================================================================================
44 // Typedefs
45 // =================================================================================================
46 
71 using MassTree = Tree;
72 
77 
82 
87 
88 // =================================================================================================
89 // Mass Tree Node Data
90 // =================================================================================================
91 
98 {
99  // -------------------------------------------------------------------
100  // Constructor and Rule of Five
101  // -------------------------------------------------------------------
102 
103 public:
104 
105  virtual ~MassTreeNodeData() override = default;
106 
107  // Move ctor and assignment.
108  MassTreeNodeData( MassTreeNodeData&& ) = delete;
110 
111 protected:
112 
113  MassTreeNodeData() = default;
114 
115  // Copy ctor and assignment.
116  MassTreeNodeData( MassTreeNodeData const& ) = default;
117  MassTreeNodeData& operator= ( MassTreeNodeData const& ) = default;
118 
119 public:
120 
121  static std::unique_ptr< MassTreeNodeData > create()
122  {
123  return std::unique_ptr< MassTreeNodeData >( new MassTreeNodeData() );
124  }
125 
126  virtual std::unique_ptr< BaseNodeData > recreate() const override
127  {
128  return std::unique_ptr< MassTreeNodeData >( new MassTreeNodeData() );
129  }
130 
131  virtual std::unique_ptr< BaseNodeData > clone() const override
132  {
133  return std::unique_ptr< MassTreeNodeData >( new MassTreeNodeData( *this ));
134  }
135 
136 };
137 
138 // =================================================================================================
139 // Mass Tree Edge Data
140 // =================================================================================================
141 
149 {
150  // -------------------------------------------------------------------
151  // Constructor and Rule of Five
152  // -------------------------------------------------------------------
153 
154 public:
155 
156  virtual ~MassTreeEdgeData() override = default;
157 
158  // Move ctor and assignment.
159  MassTreeEdgeData( MassTreeEdgeData&& ) = delete;
161 
162 protected:
163 
164  MassTreeEdgeData() = default;
165 
166  // Copy ctor and assignment.
167  MassTreeEdgeData( MassTreeEdgeData const& ) = default;
168  MassTreeEdgeData& operator= ( MassTreeEdgeData const& ) = default;
169 
170 public:
171 
172  static std::unique_ptr< MassTreeEdgeData > create()
173  {
174  return std::unique_ptr< MassTreeEdgeData >( new MassTreeEdgeData() );
175  }
176 
177  virtual std::unique_ptr< BaseEdgeData > recreate() const override
178  {
179  return std::unique_ptr< MassTreeEdgeData >( new MassTreeEdgeData() );
180  }
181 
182  virtual std::unique_ptr< BaseEdgeData > clone() const override
183  {
184  return std::unique_ptr< MassTreeEdgeData >( new MassTreeEdgeData( *this ));
185  }
186 
187  // -----------------------------------------------------
188  // Data Members
189  // -----------------------------------------------------
190 
199  std::map<double, double> masses;
200 
201 };
202 
203 // =================================================================================================
204 // Common Converter
205 // =================================================================================================
206 
214 {
215  return convert(
216  source,
217  [] ( tree::BaseNodeData const& node_data ) {
218  auto mass_node = tree::MassTreeNodeData::create();
219  auto const& orig_node = dynamic_cast< CommonNodeData const& >( node_data );
220  mass_node->name = orig_node.name;
221 
222  return mass_node;
223  },
224  [] ( tree::BaseEdgeData const& edge_data ) {
225  auto mass_edge = tree::MassTreeEdgeData::create();
226  auto const& orig_edge = dynamic_cast< CommonEdgeData const& >( edge_data );
227  mass_edge->branch_length = orig_edge.branch_length;
228 
229  return mass_edge;
230  }
231  );
232 }
233 
234 } // namespace tree
235 } // namespace genesis
236 
237 #endif // include guard
genesis::tree::MassTreeNodeData::recreate
virtual std::unique_ptr< BaseNodeData > recreate() const override
Polymorphically create a default-constructed instance of this class with the same derived type as it ...
Definition: tree/mass_tree/tree.hpp:126
genesis::tree::convert
Tree convert(Tree const &source, std::function< std::unique_ptr< BaseNodeData >(BaseNodeData const &node_data)> node_data_converter, std::function< std::unique_ptr< BaseEdgeData >(BaseEdgeData const &edge_data)> edge_data_converter)
Create a tree with the same topology as the source tree, while converting its data.
Definition: tree/function/operators.cpp:53
genesis::tree::MassTreeEdgeData::masses
std::map< double, double > masses
List of masses stored on this branch, sorted by their position on the branch.
Definition: tree/mass_tree/tree.hpp:199
genesis::tree::MassTreeNodeData::create
static std::unique_ptr< MassTreeNodeData > create()
Definition: tree/mass_tree/tree.hpp:121
genesis::tree::MassTreeEdgeData::recreate
virtual std::unique_ptr< BaseEdgeData > recreate() const override
Polymorphically create a default-constructed instance of this class with the same derived type as it ...
Definition: tree/mass_tree/tree.hpp:177
genesis::tree::MassTreeEdgeData
Data class for MassTreeEdges. Stores the branch length and a list of masses with their positions alon...
Definition: tree/mass_tree/tree.hpp:148
genesis::tree::MassTree
Tree MassTree
Alias for a Tree that stores masses on its TreeEdges.
Definition: placement/function/operators.hpp:54
tree.hpp
Header of Tree class.
genesis::tree::BaseEdgeData
Base class for storing data on Edges of a Tree.
Definition: edge_data.hpp:66
genesis::tree::MassTreeNodeData
Data class for MassTreeNodes. Stores taxon names.
Definition: tree/mass_tree/tree.hpp:97
genesis::tree::MassTreeEdgeData::operator=
MassTreeEdgeData & operator=(MassTreeEdgeData &&)=delete
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
genesis::tree::CommonEdgeData::branch_length
double branch_length
Branch length of the edge.
Definition: tree/common_tree/tree.hpp:193
genesis::tree::MassTreeNodeData::clone
virtual std::unique_ptr< BaseNodeData > clone() const override
Polymorphically copy an instance of this class. Use instead of copy constructor.
Definition: tree/mass_tree/tree.hpp:131
genesis::tree::CommonNodeData::name
std::string name
Name of the node.
Definition: tree/common_tree/tree.hpp:127
genesis::tree::TreeEdge
Definition: edge.hpp:60
genesis::tree::TreeNode
Definition: tree/tree/node.hpp:58
genesis::tree::MassTreeEdgeData::create
static std::unique_ptr< MassTreeEdgeData > create()
Definition: tree/mass_tree/tree.hpp:172
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::tree::BaseNodeData
Base class for storing data on Nodes of a Tree.
Definition: node_data.hpp:66
operators.hpp
Tree operator functions.
tree.hpp
genesis::tree::MassTreeEdgeData::clone
virtual std::unique_ptr< BaseEdgeData > clone() const override
Polymorphically copy an instance of this class. Use instead of copy constructor.
Definition: tree/mass_tree/tree.hpp:182
genesis::tree::MassTreeNodeData::~MassTreeNodeData
virtual ~MassTreeNodeData() override=default
genesis::tree::convert_common_tree_to_mass_tree
MassTree convert_common_tree_to_mass_tree(CommonTree const &source)
Helper function that takes a CommonTree (or any Tree with Node and Edge data derived from it) and tur...
Definition: tree/mass_tree/tree.hpp:213
genesis::tree::MassTreeNodeData::operator=
MassTreeNodeData & operator=(MassTreeNodeData &&)=delete
genesis::tree::MassTreeEdgeData::MassTreeEdgeData
MassTreeEdgeData()=default
genesis::tree::CommonEdgeData
Common class containing the commonly needed data for tree edges.
Definition: tree/common_tree/tree.hpp:144
genesis::tree::CommonNodeData
Common class containing the commonly needed data for tree nodes.
Definition: tree/common_tree/tree.hpp:79
genesis::tree::MassTreeEdgeData::~MassTreeEdgeData
virtual ~MassTreeEdgeData() override=default
genesis::tree::MassTreeNodeData::MassTreeNodeData
MassTreeNodeData()=default