62 bool keep_singleton_inner_nodes,
63 bool keep_inner_node_names,
68 for(
auto const& taxon : taxonomy ) {
69 auto const level = parent_level + 1;
71 if( max_level > -1 &&
taxon_level( taxon ) >= static_cast<size_t>( max_level )) {
78 }
else if( ! keep_singleton_inner_nodes && taxon.size() == 1 ) {
84 taxon, keep_singleton_inner_nodes, keep_inner_node_names, max_level,
91 std::string
const tax_name = (
92 ( ! keep_inner_node_names && taxon.size() > 0 )
98 taxon, keep_singleton_inner_nodes, keep_inner_node_names, max_level,
107 bool keep_singleton_inner_nodes,
108 bool keep_inner_node_names,
118 if( taxonomy.
size() > 1 ) {
126 taxonomy, keep_singleton_inner_nodes, keep_inner_node_names, max_level, 1, broker
142 return nr.broker_to_tree( broker );
147 std::unordered_map<std::string, Taxopath>
const& extra_taxa,
148 bool keep_singleton_inner_nodes,
149 bool keep_inner_node_names,
151 bool add_extra_taxa_parents
155 auto copy = taxonomy;
156 for(
auto const& tp : extra_taxa ) {
158 if( add_extra_taxa_parents ) {
167 assert( ! add_extra_taxa_parents );
169 throw std::runtime_error(
"Taxopath " +
path +
" not found in Taxonomy." );
174 tax->add_child( tp.first );
177 return taxonomy_to_tree( copy, keep_singleton_inner_nodes, keep_inner_node_names, max_level );
181 std::unordered_map<std::string, Taxopath>
const& taxon_map,
182 bool keep_singleton_inner_nodes,
183 bool keep_inner_node_names,
189 tmp, taxon_map, keep_singleton_inner_nodes, keep_inner_node_names, max_level,
true Helper class to generate a taxonomic path string from a Taxopath object or a Taxon.
size_t size() const
Return the number of immediate child Taxa.
std::string to_string(Taxopath const &taxopath) const
Return a string representation of a Taxopath.
Read default Newick trees, i.e., trees with names and branch lengths.
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.
tree::Tree taxonomy_to_tree(Taxonomy const &taxonomy, bool keep_singleton_inner_nodes, bool keep_inner_node_names, int max_level)
Turn a Taxonomy into a (possibly multifurcating) Tree.
Stores a Newick tree in an intermediate format that can be further processed into a Tree...
utils::Range< IteratorPath< true > > path(ElementType const &start, ElementType const &finish)
static void add_subtaxonomy_(Taxonomy const &taxonomy, bool keep_singleton_inner_nodes, bool keep_inner_node_names, int max_level, int parent_level, tree::NewickBroker &broker)
Recursive local helper function to add taxa to the tree broker.
Class for representing phylogenetic trees.
void assign_ranks() const
Iterate over the tree and assign ranks (= number of immediate children) to all nodes.
Taxon & add_from_taxopath(Taxonomy &taxonomy, Taxopath const &taxopath, bool expect_parents)
Add a Taxon to a Taxonomy, using the taxonomic elements of a Taxopath.
void push_bottom(NewickBrokerElement const &node)
Taxon const * find_taxon_by_taxopath(Taxonomy const &tax, Taxopath const &taxopath)
Find a Taxon in a Taxonomy, given its Taxopath.
Store the information for one element of a Newick tree.
size_t taxon_level(Taxon const &taxon)
Return the level of depth of a given Taxon.