|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_TREE_FUNCTION_OPERATORS_H_
2 #define GENESIS_TREE_FUNCTION_OPERATORS_H_
65 template<
class NodeDataType,
class EdgeDataType >
69 for(
auto const& node : tree.
nodes() ) {
70 if( ! node.has_data() ) {
77 assert( node.data_ptr() );
78 auto const& ref = *node.data_ptr();
79 if(
typeid( ref ) !=
typeid( NodeDataType )) {
85 for(
auto const& edge : tree.
edges() ) {
86 if( ! edge.has_data() ) {
93 assert( edge.data_ptr() );
94 auto const& ref = *edge.data_ptr();
95 if(
typeid( ref ) !=
typeid( EdgeDataType )) {
111 template<
class NodeDataType,
class EdgeDataType >
115 for(
auto const& node : tree.
nodes() ) {
116 if( ! node.has_data() ) {
123 assert( node.data_ptr() );
124 if(
dynamic_cast< NodeDataType const*
>( node.data_ptr() ) ==
nullptr ) {
130 for(
auto const& edge : tree.
edges() ) {
131 if( ! edge.has_data() ) {
138 assert( edge.data_ptr() );
139 if(
dynamic_cast< EdgeDataType const*
>( edge.data_ptr() ) ==
nullptr ) {
165 std::function< std::unique_ptr<BaseNodeData>( BaseNodeData
const& node_data )> node_data_converter,
166 std::function< std::unique_ptr<BaseEdgeData>( BaseEdgeData
const& edge_data )> edge_data_converter
192 std::function<
bool ( TreeNode
const&, TreeNode
const&) > node_comparator,
193 std::function<
bool ( TreeEdge
const&, TreeEdge
const&) > edge_comparator
203 std::vector<Tree>
const& trees,
204 std::function<
bool ( TreeNode
const&, TreeNode
const&) > node_comparator,
205 std::function<
bool ( TreeEdge
const&, TreeEdge
const&) > edge_comparator
223 bool identical_topology( Tree
const& lhs, Tree
const& rhs,
bool identical_indices =
true );
230 bool identical_topology( std::vector<Tree>
const& trees,
bool identical_indices =
true );
239 bool belongs_to( Tree
const& tree, TreeNode
const& node );
244 bool belongs_to( TreeNode
const& node, Tree
const& tree );
249 bool belongs_to( Tree
const& tree, TreeEdge
const& edge );
254 bool belongs_to( TreeEdge
const& edge, Tree
const& tree );
259 bool belongs_to( Tree
const& tree, TreeLink
const& link );
264 bool belongs_to( TreeLink
const& link, Tree
const& tree );
269 bool belongs_to( Tree
const& tree, Subtree
const& subt );
274 bool belongs_to( Subtree
const& subt, Tree
const& tree );
284 TreeEdge
const*
edge_between( TreeNode
const& lhs, TreeNode
const& rhs );
291 std::string
print_info( TreeEdge
const& edge );
292 std::string
print_info( TreeLink
const& link );
293 std::string
print_info( TreeNode
const& node );
295 std::string
print_gist( Tree
const& tree,
long items = 10 );
312 #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.
std::string print_gist(Tree const &tree, long items)
std::string print_info(Tree const &tree)
bool tree_data_is(Tree const &tree, bool allow_null=false)
Check whether the data of the nodes and edges of the Tree are exactly of the specified data types.
bool belongs_to(Tree const &tree, TreeNode const &node)
Return whether the TreeNode belongs to the Tree, i.e., whether it is owned by the Tree.
bool identical_topology(Tree const &lhs, Tree const &rhs, bool identical_indices)
Return whether both trees have an identical topology.
bool equal(Tree const &lhs, Tree const &rhs, std::function< bool(TreeNode const &, TreeNode const &) > node_comparator, std::function< bool(TreeEdge const &, TreeEdge const &) > edge_comparator)
Compare two trees for equality given binary comparator functionals for their nodes and edges.
bool tree_data_is_derived_from(Tree const &tree, bool allow_null=false)
Check whether the data of the nodes and edges of the Tree are derived from the specified data types.
TreeEdge * edge_between(TreeNode &lhs, TreeNode &rhs)
Return the TreeEdge between two TreeNode&s, if they are neighbours, or nullptr otherwise.
Class for representing phylogenetic trees.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
utils::Range< IteratorNodes > nodes()
utils::Range< IteratorEdges > edges()
bool validate_topology(Tree const &tree)
Validate that all internal pointers of the Tree elements (TreeLinks, TreeNodes, TreeEdges) to each ot...