bpp-phyl3  3.0.0
ExtendedNewick.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_IO_EXTENDEDNEWICK_H
6 #define BPP_PHYL_IO_EXTENDEDNEWICK_H
7 
8 
9 #include "../Tree/PhyloDAG.h"
10 #include "IoDAG.h"
11 
12 namespace bpp
13 {
37  public AbstractIPhyloDAG,
38  public AbstractOPhyloDAG,
41 {
42 protected:
44  bool writeId_;
45  bool verbose_;
46 
47 public:
57  ExtendedNewick(bool allowComments = false, bool writeId = false, bool verbose = false) :
58  allowComments_(allowComments),
59  writeId_(writeId),
60  verbose_(verbose)
61  {}
62 
63  virtual ~ExtendedNewick() {}
64 
65 public:
71  const std::string getFormatName() const override;
72  const std::string getFormatDescription() const override;
73  /* @} */
74 
82 
83  std::unique_ptr<PhyloDAG> readPhyloDAG(std::istream& in) const override;
84 
85 private:
86  std::shared_ptr<PhyloNode> parenthesisToNode(
87  PhyloDAG& dag,
88  std::shared_ptr<PhyloNode> father,
89  const std::string& description,
90  unsigned int& nodeCounter,
91  unsigned int& branchCounter,
92  map<str::string, shared_ptr<PhyloNode> >& mapEvent,
93  bool withId,
94  bool verbose) const;
95 
96 public:
97  std::unique_ptr<PhyloDAG> parenthesisToPhyloDAG(
98  const std::string& description,
99  bool withId,
100  bool verbose = false) const;
101 
110 public:
112 
113  void writePhyloDAG(const PhyloDAG& dag, std::ostream& out) const override
114  {
115  write_(dag, out);
116  }
126 
127  void readPhyloDAGs(
128  std::istream& in,
129  std::vector<std::unique_ptr<PhyloDAG>>& dags) const override;
130 
134 
135  void writePhyloDAGs(const std::vector<const PhyloDAG*>& dags, std::ostream& out) const override
136  {
137  write_(dags, out);
138  }
141 protected:
142  void write_(const PhyloDAG& tree, std::ostream& out) const;
143 
144  void write_(const std::vector<const PhyloDAG*>& dags, std::ostream& out) const;
145 
146  Element getElement(const std::string& elt) const override;
147 
158  std::string nodeToParenthesis(const PhyloDAG& dag, std::shared_ptr<PhyloNode> node, bool writeId = false) const;
159 
169  std::string dagToParenthesis(const PhyloDAG& dag, bool writeId = false) const;
170 
177  std::string dagToParenthesis(const PhyloDAG& dag) const;
178 };
179 } // end of namespace bpp.
180 #endif // BPP_PHYL_IO_EXTENDEDNEWICK_H
Partial implementation of the IMultiDAG interface.
Definition: IoDAG.h:252
virtual void readPhyloDAGs(std::istream &in, std::vector< std::unique_ptr< PhyloDAG >> &dags) const override=0
Read dags from a stream.
Partial implementation of the IDAG interface.
Definition: IoDAG.h:122
std::unique_ptr< PhyloDAG > readPhyloDAG(std::istream &in) const override=0
Read a DAG from a stream.
Partial implementation of the ODAG interface.
Definition: IoDAG.h:273
virtual void writePhyloDAGs(const std::vector< const PhyloDAG * > &dags, std::ostream &out) const =0
Write dags to a stream.
Partial implementation of the ODAG interface.
Definition: IoDAG.h:151
virtual void writePhyloDAG(const PhyloDAG &dag, std::ostream &out) const =0
Write a PhyloDAG to a stream.
The so-called 'ExtendedNewick' parenthetic format for phylogenetic networks, where hybridization node...
void write_(const PhyloDAG &tree, std::ostream &out) const
const std::string getFormatDescription() const override
ExtendedNewick(bool allowComments=false, bool writeId=false, bool verbose=false)
Build a new ExtendedNewick reader/writer.
Element getElement(const std::string &elt) const override
std::string dagToParenthesis(const PhyloDAG &dag, bool writeId=false) const
Get the parenthesis description of a tree.
std::unique_ptr< PhyloDAG > readPhyloDAG(std::istream &in) const override=0
virtual void readPhyloDAGs(std::istream &in, std::vector< std::unique_ptr< PhyloDAG >> &dags) const override=0
void writePhyloDAGs(const std::vector< const PhyloDAG * > &dags, std::ostream &out) const override
Write dags to a stream.
std::shared_ptr< PhyloNode > parenthesisToNode(PhyloDAG &dag, std::shared_ptr< PhyloNode > father, const std::string &description, unsigned int &nodeCounter, unsigned int &branchCounter, map< str::string, shared_ptr< PhyloNode > > &mapEvent, bool withId, bool verbose) const
std::unique_ptr< PhyloDAG > parenthesisToPhyloDAG(const std::string &description, bool withId, bool verbose=false) const
virtual ~ExtendedNewick()
std::string nodeToParenthesis(const PhyloDAG &dag, std::shared_ptr< PhyloNode > node, bool writeId=false) const
Get the ExtendedNewick description of a subdag.
void writePhyloDAG(const PhyloDAG &dag, std::ostream &out) const override
Write a PhyloDAG to a stream.
const std::string getFormatName() const override
Defines the basic types of data flow nodes.