A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2017 Lucas Czech
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() = 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() = 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 // Default Converter
205 // =================================================================================================
206 
214 {
215  return convert(
216  source,
217  [] ( tree::BaseNodeData const& node_data ) {
218  (void) node_data;
220  },
221  [] ( tree::BaseEdgeData const& edge_data ) {
222  auto mass_edge = tree::MassTreeEdgeData::create();
223  auto const& orig_edge = dynamic_cast< DefaultEdgeData const& >( edge_data );
224  mass_edge->branch_length = orig_edge.branch_length;
225 
226  return mass_edge;
227  }
228  );
229 }
230 
231 } // namespace tree
232 } // namespace genesis
233 
234 #endif // include guard
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.
MassTreeEdgeData & operator=(MassTreeEdgeData &&)=delete
Base class for storing data on Nodes of a Tree.
Definition: node_data.hpp:66
Tree operator functions.
Data class for MassTreeEdges. Stores the branch length and a list of masses with their positions alon...
virtual ~MassTreeNodeData()=default
Data class for MassTreeNodes. Stores nothing.
virtual std::unique_ptr< BaseNodeData > clone() const override
Polymorphically copy an instance of this class. Use instead of copy constructor.
virtual std::unique_ptr< BaseEdgeData > recreate() const override
Polymorphically create a default-constructed instance of this class with the same derived type as it ...
Default class containing the commonly needed data for tree edges.
MassTree convert_default_tree_to_mass_tree(DefaultTree const &source)
Helper function that takes a DefaultTree (or any Tree with Node and Edge data derived from it) and tu...
std::map< double, double > masses
List of masses stored on this branch, sorted by their position on the branch.
Tree MassTree
Alias for a Tree that stores masses on its TreeEdges.
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
static std::unique_ptr< MassTreeNodeData > create()
virtual std::unique_ptr< BaseNodeData > recreate() const override
Polymorphically create a default-constructed instance of this class with the same derived type as it ...
MassTreeNodeData & operator=(MassTreeNodeData &&)=delete
double branch_length
Branch length of the edge.
virtual std::unique_ptr< BaseEdgeData > clone() const override
Polymorphically copy an instance of this class. Use instead of copy constructor.
Header of Tree class.
virtual ~MassTreeEdgeData()=default
Base class for storing data on Edges of a Tree.
Definition: edge_data.hpp:66
static std::unique_ptr< MassTreeEdgeData > create()