|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_TAXONOMY_FUNCTIONS_TAXONOMY_H_
2 #define GENESIS_TAXONOMY_FUNCTIONS_TAXONOMY_H_
40 #include <unordered_map>
78 template<
class UnaryPredicate >
87 template<
class UnaryPredicate >
96 template<
class UnaryPredicate >
99 for(
auto const& c : tax ) {
104 if( rec !=
nullptr ) {
114 template<
class UnaryPredicate >
117 std::queue< Taxon const* > taxa_queue;
118 for(
auto& t : tax ) {
119 taxa_queue.push( &t );
122 while( not taxa_queue.empty() ) {
123 auto const& cur = *taxa_queue.front();
130 for(
auto const& t : cur ) {
131 taxa_queue.push( &t );
140 template<
class SearchStrategy,
class UnaryPredicate >
144 auto const& ctax =
static_cast< Taxonomy const&
>( tax );
161 Taxon
const*
find_taxon_by_id( Taxonomy
const& tax, std::string
const&
id );
171 template<
class SearchStrategy >
175 return t.
name() == name;
182 template<
class SearchStrategy >
186 auto const& ctax =
static_cast< Taxonomy const&
>( tax );
193 template<
class SearchStrategy >
204 template<
class SearchStrategy >
208 auto const& ctax =
static_cast< Taxonomy const&
>( tax );
209 return const_cast< Taxon*
>( find_taxon_by_id<SearchStrategy>( ctax,
id, strat ));
301 std::string
const& rank,
302 bool case_sensitive =
false
322 bool case_sensitive =
false
346 void sort_by_name( Taxonomy& tax,
bool recursive =
true,
bool case_sensitive =
false );
370 std::ostream&
operator << ( std::ostream& out, Taxonomy
const& tax );
386 bool validate( Taxonomy
const& taxonomy,
bool stop_at_first_error =
false );
391 #endif // include guard
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.
bool has_unique_ids(Taxonomy const &tax)
Return true iff all IDs of the Taxa in the Taxonomy are unique.
size_t taxon_level(Taxon const &taxon)
Return the level of depth of a given Taxon.
Tag used for find_taxon().
Taxon const * find_taxon_by_id(Taxonomy const &tax, std::string const &id)
Alias for find_taxon_by_id(..., DepthFirstSearch{}).
Store a Taxon, i.e., an element in a Taxonomy, with its name, rank, ID and sub-taxa.
Taxon const * find_taxon_by_name(Taxonomy const &tax, std::string const &name)
Alias for find_taxon_by_name(..., DepthFirstSearch{}).
bool validate(Taxonomy const &taxonomy, bool stop_at_first_error)
Validate the internal data structures of a Taxonomy and its child Taxa Taxa.
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.
void sort_by_name(Taxonomy &tax, bool recursive, bool case_sensitive)
Sort the Taxa of a Taxonomy by their name.
std::string const & name() const
Return the name of this taxon.
Taxon const * find_taxon(Taxonomy const &tax, UnaryPredicate p)
Alias for find_taxon(..., DepthFirstSearch{})
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
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.
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_at_level(Taxonomy const &tax, size_t level)
Count the number of Taxa at a certain level of depth in the Taxonomy.
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.
Tag used for find_taxon().
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.
std::string const & id() const
Set the ID of this taxon.