A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
taxonomy/functions/taxonomy.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TAXONOMY_FUNCTIONS_TAXONOMY_H_
2 #define GENESIS_TAXONOMY_FUNCTIONS_TAXONOMY_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 <functional>
35 #include <iosfwd>
36 #include <string>
37 #include <unordered_map>
38 #include <vector>
39 
40 namespace genesis {
41 namespace taxonomy {
42 
43 // =================================================================================================
44 // Forwad Declarations
45 // =================================================================================================
46 
47 class Taxon;
48 class Taxonomy;
49 
50 // =================================================================================================
51 // Accessors
52 // =================================================================================================
53 
54 Taxon const* find_taxon_by_name( Taxonomy const& tax, std::string const& name );
55 Taxon* find_taxon_by_name( Taxonomy& tax, std::string const& name );
56 
57 size_t taxon_level( Taxon const& taxon );
58 size_t total_taxa_count( Taxonomy const& tax );
59 
60 size_t taxa_count_lowest_levels( Taxonomy const& tax );
61 size_t taxa_count_at_level( Taxonomy const& tax, size_t level );
62 std::vector< size_t > taxa_count_levels( Taxonomy const& tax );
63 
65  Taxonomy const& tax,
66  std::string const& rank,
67  bool case_sensitive = false
68 );
69 std::unordered_map< std::string, size_t> taxa_count_ranks(
70  Taxonomy const& tax,
71  bool case_sensitive = false
72 );
73 
74 // =================================================================================================
75 // Modifiers
76 // =================================================================================================
77 
78 void sort_by_name( Taxonomy& tax, bool recursive = true, bool case_sensitive = false );
79 
80 void remove_taxa_at_level( Taxonomy& tax, size_t level );
81 
82 // =================================================================================================
83 // Print and Output
84 // =================================================================================================
85 
86 std::ostream& operator << ( std::ostream& out, Taxonomy const& tax );
87 
88 bool validate( Taxonomy const& taxonomy, bool stop_at_first_error = false );
89 
90 } // namespace taxonomy
91 } // namespace genesis
92 
93 #endif // include guard
size_t taxon_level(Taxon const &taxon)
Return the level of depth of a given Taxon.
bool validate(Taxonomy const &taxonomy, bool stop_at_first_error)
Validate the internal data structures of a Taxonomy and its child Taxa Taxa.
std::vector< size_t > taxa_count_levels(Taxonomy const &tax)
Count the number of Taxa at each level of depth in the Taxonomy.
size_t taxa_count_lowest_levels(Taxonomy const &tax)
Return the number of lowest level Taxa (i.e., taxa without sub-taxa) in the Taxonomy.
Taxon const * find_taxon_by_name(Taxonomy const &tax, std::string const &name)
Find a Taxon with a given name by recursively searching the Taxonomy.
std::ostream & operator<<(std::ostream &out, Taxonomy const &tax)
Print the contents of a Taxonomy, i.e., all nested taxa, up to a limit of 10.
void remove_taxa_at_level(Taxonomy &tax, size_t level)
Remove all Taxa at a given level of depth in the Taxonomy hierarchy, and all their children...
std::unordered_map< std::string, size_t > taxa_count_ranks(Taxonomy const &tax, bool case_sensitive)
Count the number of Taxa in a Taxonomy per rank.
void sort_by_name(Taxonomy &tax, bool recursive, bool case_sensitive)
Sort the Taxa of a Taxonomy by their name.
size_t total_taxa_count(Taxonomy const &tax)
Return the total number of taxa contained in the Taxomony, i.e., the number of (non-unique) names of ...
size_t taxa_count_with_rank(Taxonomy const &tax, std::string const &rank, bool case_sensitive)
Count the number of Taxa in a Taxonomy that have a certain rank assigned to them. ...
size_t taxa_count_at_level(Taxonomy const &tax, size_t level)
Count the number of Taxa at a certain level of depth in the Taxonomy.