|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_PLACEMENT_FORMATS_NEWICK_READER_H_
2 #define GENESIS_PLACEMENT_FORMATS_NEWICK_READER_H_
84 auto const& en_vec = ( get_edge_num_from_comments_ ? element.
comments : element.
tags );
87 if( en_vec.size() == 1 ) {
88 edge_data.reset_edge_num( std::stoull( en_vec[0] ));
95 auto name = element.
name;
99 name =
"node '" + name +
"'";
117 if( en_vec.size() > 1 ) {
118 if( get_edge_num_from_comments_ ) {
119 throw std::invalid_argument(
120 "Edge at " + name +
" contains more than one comment value such as "
121 "'[xyz]'. Expecting only one for the placement edge_num of this edge."
124 throw std::invalid_argument(
125 "Edge at " + name +
" contains more than one tag value such as "
126 "'{xyz}'. Expecting only one for the placement edge_num of this edge."
138 std::set<PlacementEdgeData::EdgeNumType> edge_nums;
139 for(
auto const& edge : tree.
edges() ) {
144 if( edge_num > -1 && edge_nums.count( edge_num ) > 0 ) {
145 throw std::invalid_argument(
146 "Jplace document contains a Newick tree where the edge_num '"
148 "and hence cannot be used to uniquely identify edges of the tree. "
149 "This indicates a severe issue with the program that created the jplace file."
152 edge_nums.insert( edge_num );
157 throw std::invalid_argument(
"Jplace document contains an empty Newick tree." );
167 throw std::invalid_argument(
168 "Jplace document contains too many edges without an edge_num. We can cope with a few "
169 "of them missing. But as none of them can receive any placements, it does not make "
170 "sense if too many are missing. This hence indicates a severe issue with the program "
171 "that created the jplace file. Possibly, the provided jplace version (1-3) does not "
172 "match the format used to specify the edge_num values in the tree."
183 if( edge_nums.count( -1 ) > 0 ) {
184 LOG_WARN <<
"Jplace document contains a Newick tree where not all edges have a proper "
185 <<
"edge_num assigned to them. This might be because the document uses "
186 <<
"an old jplace standard (version 1), where the edge at the root does not "
187 <<
"have an edge_num. We can still work with this tree, but it might also "
188 <<
"indicate a more severe issue with the data.";
190 for(
auto& edge : tree.
edges() ) {
192 if( edge_data.edge_num() == -1 ) {
199 assert( edge_nums.size() > 0 );
200 auto const next_avail = *(edge_nums.rbegin()) + 1;
201 assert( edge_nums.count( next_avail ) == 0 );
202 edge_data.reset_edge_num( next_avail );
203 edge_nums.insert( next_avail );
209 LOG_WARN <<
"Jplace document has a Newick tree where the edge_num tags are non standard. "
210 <<
"They are expected by the jplace standard to be assigned in ascending order "
211 <<
"via post-order traversal of the tree. We can still work with this tree, "
212 <<
"but it might indicate an issue with the data.";
257 get_edge_num_from_comments_ = value;
268 return get_edge_num_from_comments_;
277 bool get_edge_num_from_comments_ =
false;
303 CommonTreeNewickReaderPlugin::register_with( *
this );
311 #endif // include guard
create_node_data_function create_node_data_plugin
std::string name
Name of the node.
std::vector< std::string > comments
Arbitrary strings that can be attached to a node, e.g. in Newick format via "[]".
std::vector< finish_reading_function > finish_reading_plugins
bool has_correct_edge_nums(PlacementTree const &tree)
Verify that the tree has correctly set edge nums.
Provide a set of plugin functions for NewickReader to read a CommonTree.
create_edge_data_function create_edge_data_plugin
static std::unique_ptr< PlacementEdgeData > create()
PlacementTreeNewickReaderPlugin()=default
std::string to_string(GenomeLocus const &locus)
void finish_reading(tree::Tree &tree) const
#define LOG_WARN
Log a warning. See genesis::utils::LoggingLevel.
std::vector< element_to_edge_function > element_to_edge_plugins
void element_to_edge(tree::NewickBrokerElement const &element, tree::TreeEdge &edge) const
Data class for PlacementTreeEdges. Stores the branch length of the edge, and the edge_num,...
Class for representing phylogenetic trees.
Provides easy and fast logging functionality.
void reset_edge_num(EdgeNumType val)
Force to set the edge_num to a certain value.
bool empty() const
Return whether the Tree is empty (i.e., has no nodes, edges and links).
PlacementTreeNewickReaderPlugin & operator=(PlacementTreeNewickReaderPlugin const &)=default
std::vector< std::string > tags
Arbitrary strings that can be attached to a node, e.g. in Newick format via "{}".
virtual ~PlacementTreeNewickReaderPlugin()=default
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
bool enable_tags() const
Return whether currently Newick tags are enabled.
utils::Range< IteratorEdges > edges()
void register_with(tree::NewickReader &reader) const
PlacementTreeNewickReader()
Store the information for one element of a Newick tree.
PlacementTreeNewickReaderPlugin & get_edge_num_from_comments(bool value)
Set whether to use tags or comments of the Newick tree for the edge nums.
bool get_edge_num_from_comments() const
Get whether to use tags or comments of the Newick tree for the edge nums.
size_t edge_count() const
Return the number of TreeEdges of the Tree.
static std::unique_ptr< PlacementNodeData > create()