A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
indexed_newick_reader.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_ATTRIBUTE_TREE_INDEXED_NEWICK_READER_H_
2 #define GENESIS_TREE_ATTRIBUTE_TREE_INDEXED_NEWICK_READER_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 
38 
39 #include <functional>
40 #include <map>
41 #include <string>
42 #include <vector>
43 
44 namespace genesis {
45 namespace tree {
46 
47 // =================================================================================================
48 // Indexed Attribute Tree Newick Reader Plugin
49 // =================================================================================================
50 
96 {
97 public:
98 
99  // -------------------------------------------------------------------------
100  // Typedefs and Enums
101  // -------------------------------------------------------------------------
102 
104 
110  enum class Source
111  {
115  kValue,
116 
120  kComment,
121 
125  kTag
126  };
127 
131  enum class Target
132  {
137  kNode,
138 
143  kEdge
144  };
145 
146  // -------------------------------------------------------------------------
147  // Constructor and Rule of Five
148  // -------------------------------------------------------------------------
149 
151  virtual ~IndexedAttributeTreeNewickReaderPlugin() = default;
152 
155 
158 
159  // -------------------------------------------------------------------------
160  // Settings
161  // -------------------------------------------------------------------------
162 
207  Source source,
208  size_t index,
209  Target target,
210  std::string const& target_key
211  );
212 
241  Source source,
242  size_t index,
243  Target target,
244  std::string const& target_key,
245  std::string const& default_value
246  );
247 
283  Source source,
284  Target target,
285  std::string const& target_key_prefix
286  );
287 
300 
304  void clear();
305 
306  // -------------------------------------------------------------------------
307  // Plugin Functions
308  // -------------------------------------------------------------------------
309 
310  void element_to_node( NewickBrokerElement const& element, TreeNode& node ) const;
311 
312  void element_to_edge( NewickBrokerElement const& element, TreeEdge& edge ) const;
313 
314  void register_with( NewickReader& reader ) const;
315 
316  // -------------------------------------------------------------------------
317  // Internal Functions
318  // -------------------------------------------------------------------------
319 
320 private:
321 
322  std::vector<std::string> const& get_attribute_source_(
323  NewickBrokerElement const& element,
324  Source source
325  ) const;
326 
327  void process_indexed_attributes_(
328  NewickBrokerElement const& element,
329  AttributeTreeMap& attributes,
330  Target target
331  ) const;
332 
333  void process_catch_all_attributes_(
334  NewickBrokerElement const& element,
335  AttributeTreeMap& attributes,
336  Target target
337  ) const;
338 
339  // -------------------------------------------------------------------------
340  // Data Members
341  // -------------------------------------------------------------------------
342 
343 private:
344 
345  struct AttributeDescriptor
346  {
347  Source source;
348  size_t index;
349  Target target;
350  std::string target_key;
351  std::string default_value;
352  bool use_default;
353  };
354 
355  std::vector<AttributeDescriptor> indexed_attributes_;
356  std::vector<AttributeDescriptor> catch_all_attributes_;
357 
358 };
359 
360 // =================================================================================================
361 // Attribute Tree Newick Reader
362 // =================================================================================================
363 
374  : public NewickReader
377 {
378 public:
379 
380  // -------------------------------------------------------------------------
381  // Constructor and Rule of Five
382  // -------------------------------------------------------------------------
383 
385  {
386  // We first register the default reader, then the placement reader, because the latter
387  // overwrites the data creation functions.
390  }
391 };
392 
393 } // namespace tree
394 } // namespace genesis
395 
396 #endif // include guard
Source
Select which kind of Newick data to take, i.e., either comments, values, or tags. ...
Read Newick trees with ordered attributes for the Nodes and Edges.
void clear()
Reset all settings to the default, i.e., delete all attribute settings.
self_type & add_catch_all(Source source, Target target, std::string const &target_key_prefix)
Store all Newick data of a given source in an AttributeTreeMap.
self_type & add_attribute(Source source, size_t index, Target target, std::string const &target_key)
Store the Newick data at a given index in an AttributeTreeMap.
Provide a set of plugin functions for NewickReader to read ordered attributes of the Nodes and Edges ...
Store data at the attributes map of an AttributeTreeEdge.
self_type & operator=(IndexedAttributeTreeNewickReaderPlugin const &)=default
void element_to_edge(NewickBrokerElement const &element, TreeEdge &edge) const
Store data at the attributes map of an AttributeTreeNode.
Provide a set of plugin functions for NewickReader to read a DefaultTree.
Target
Select where to store the data, i.e., at Nodes or Edges of the Tree.
Take data from Newick comments, i.e., [something].
std::map< std::string, std::string > AttributeTreeMap
Alias for the map type used by an AttributeTree.
Store the information for one element of a Newick tree.
Definition: element.hpp:60
void element_to_node(NewickBrokerElement const &element, TreeNode &node) const