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
12namespace bpp
13{
37 public AbstractIPhyloDAG,
38 public AbstractOPhyloDAG,
41{
42protected:
46
47public:
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
65public:
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
85private:
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 std::map<std::string, std::shared_ptr<PhyloNode>>& mapEvent,
93 bool withId,
94 bool verbose) const;
95
96public:
97 std::unique_ptr<PhyloDAG> parenthesisToPhyloDAG(
98 const std::string& description,
99 bool withId,
100 bool verbose = false) const;
101
110public:
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 }
141protected:
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
159 std::string edgeToParenthesis(const PhyloDAG& dag, std::shared_ptr<PhyloBranch> edge, std::vector<std::shared_ptr<PhyloNode>>& writtenNodes, bool writeId = false) const;
160
170 std::string dagToParenthesis(const PhyloDAG& dag, bool writeId = false) const;
171};
172} // end of namespace bpp.
173#endif // BPP_PHYL_IO_EXTENDEDNEWICK_H
Partial implementation of the IMultiDAG interface.
Definition: IoDAG.h:251
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:121
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:272
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:150
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...
std::shared_ptr< PhyloNode > parenthesisToNode(PhyloDAG &dag, std::shared_ptr< PhyloNode > father, const std::string &description, unsigned int &nodeCounter, unsigned int &branchCounter, std::map< std::string, std::shared_ptr< PhyloNode > > &mapEvent, bool withId, bool verbose) const
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.
void readPhyloDAGs(std::istream &in, std::vector< std::unique_ptr< PhyloDAG > > &dags) const override
Read dags from a stream.
Element getElement(const std::string &elt) const override
std::string edgeToParenthesis(const PhyloDAG &dag, std::shared_ptr< PhyloBranch > edge, std::vector< std::shared_ptr< PhyloNode > > &writtenNodes, bool writeId=false) const
Get the ExtendedNewick description of a subdag.
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
Read a DAG from a stream.
void writePhyloDAGs(const std::vector< const PhyloDAG * > &dags, std::ostream &out) const override
Write dags to a stream.
std::unique_ptr< PhyloDAG > parenthesisToPhyloDAG(const std::string &description, bool withId, bool verbose=false) const
virtual ~ExtendedNewick()
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.