5 #ifndef BPP_PHYL_IO_IOTREE_H
6 #define BPP_PHYL_IO_IOTREE_H
9 #include "../Tree/PhyloTree.h"
10 #include "../Tree/Tree.h"
51 virtual const std::string
getDataType()
const {
return "Tree"; }
77 virtual std::unique_ptr<Tree>
readTree(
const std::string& path)
const = 0;
86 virtual std::unique_ptr<Tree>
readTree(std::istream& in)
const = 0;
107 virtual std::unique_ptr<PhyloTree>
readPhyloTree(
const std::string& path)
const = 0;
116 virtual std::unique_ptr<PhyloTree>
readPhyloTree(std::istream& in)
const = 0;
140 virtual void writeTree(
const Tree& tree,
const std::string& path,
bool overwrite)
const = 0;
195 std::unique_ptr<Tree>
readTree(std::istream& in)
const override
198 return std::unique_ptr<Tree>(tree.release());
201 std::unique_ptr<Tree>
readTree(
const std::string& path)
const override
203 std::ifstream input(path.c_str(), std::ios::in);
211 virtual std::unique_ptr<TreeTemplate<Node>>
readTreeTemplate(
const std::string& path)
const
213 std::ifstream input(path.c_str(), std::ios::in);
233 std::unique_ptr<PhyloTree>
readPhyloTree(std::istream& in)
const override = 0;
235 std::unique_ptr<PhyloTree>
readPhyloTree(
const std::string& path)
const override
237 std::ifstream input(path.c_str(), std::ios::in);
239 throw IOException (
"AbstractIPhyloTree::readPhyloTree(path): failed to read from path " + path);
263 virtual void writeTree(
const Tree& tree,
const std::string& path,
bool overwrite)
const
269 std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out | std::ios::app));
271 throw Exception(
"Problem opening file " + path +
"in write Tree.");
277 std::stringstream ss;
278 ss << e.
what() <<
"\nProblem writing tree to file " << path <<
"\n Is the file path correct and do \
279 you have the proper authorizations? ";
303 std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out | std::ios::app));
305 throw Exception(
"Problem opening file " + path +
"in writePhyloTree.");
311 std::stringstream ss;
312 ss << e.
what() <<
"\nProblem writing tree to file " << path <<
"\n Is the file path correct and do \
313 you have the proper authorizations? ";
338 virtual void readTrees(
const std::string& path, std::vector<std::unique_ptr<Tree>>& trees)
const = 0;
347 virtual void readTrees(std::istream& in, std::vector<std::unique_ptr<Tree>>& trees)
const = 0;
365 virtual void readPhyloTrees(
const std::string& path, std::vector<std::unique_ptr<PhyloTree>>& trees)
const = 0;
374 virtual void readPhyloTrees(std::istream& in, std::vector<std::unique_ptr<PhyloTree>>& trees)
const = 0;
398 const std::vector<const Tree*>& trees,
399 const std::string& path,
400 bool overwrite)
const = 0;
410 const std::vector<const Tree*>& trees,
411 std::ostream& out)
const = 0;
435 const std::vector<const PhyloTree*>& trees,
436 const std::string& path,
437 bool overwrite)
const = 0;
447 const std::vector<const PhyloTree*>& trees,
448 std::ostream& out)
const = 0;
462 virtual void readTrees(std::istream& in, std::vector<std::unique_ptr<Tree>>& trees)
const override = 0;
464 virtual void readTrees(
const std::string& path, std::vector<std::unique_ptr<Tree>>& trees)
const override
466 std::ifstream input(path.c_str(), std::ios::in);
483 virtual void readPhyloTrees(std::istream& in, std::vector<std::unique_ptr<PhyloTree>>& trees)
const override = 0;
485 virtual void readPhyloTrees(
const std::string& path, std::vector<std::unique_ptr<PhyloTree>>& trees)
const override
487 std::ifstream input(path.c_str(), std::ios::in);
504 virtual void writeTrees(
const std::vector<const Tree*>& trees, std::ostream& out)
const = 0;
505 virtual void writeTrees(
const std::vector<const Tree*>& trees,
const std::string& path,
bool overwrite)
const
509 std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out | std::ios::app));
526 virtual void writePhyloTrees(
const std::vector<const PhyloTree*>& trees, std::ostream& out)
const = 0;
528 virtual void writePhyloTrees(
const std::vector<const PhyloTree*>& trees,
const std::string& path,
bool overwrite)
const
532 std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out | std::ios::app));
Partial implementation of the IMultiTree interface.
virtual void readPhyloTrees(std::istream &in, std::vector< std::unique_ptr< PhyloTree >> &trees) const override=0
Read trees from a stream.
AbstractIMultiPhyloTree()
virtual ~AbstractIMultiPhyloTree()
virtual void readPhyloTrees(const std::string &path, std::vector< std::unique_ptr< PhyloTree >> &trees) const override
Read trees from a file.
Partial implementation of the IMultiTree interface.
virtual void readTrees(const std::string &path, std::vector< std::unique_ptr< Tree >> &trees) const override
Read trees from a file.
virtual void readTrees(std::istream &in, std::vector< std::unique_ptr< Tree >> &trees) const override=0
Read trees from a stream.
virtual ~AbstractIMultiTree()
std::unique_ptr< PhyloTree > readPhyloTree(std::istream &in) const override=0
Read a tree from a stream.
std::unique_ptr< PhyloTree > readPhyloTree(const std::string &path) const override
Read a tree from a file.
virtual ~AbstractIPhyloTree()
Element getElement(const std::string &elt) const
Partial implementation of the ITree interface.
std::unique_ptr< Tree > readTree(const std::string &path) const override
Read a tree from a file.
virtual std::unique_ptr< TreeTemplate< Node > > readTreeTemplate(const std::string &path) const
virtual std::unique_ptr< TreeTemplate< Node > > readTreeTemplate(std::istream &in) const =0
virtual Element getElement(const std::string &elt) const
std::unique_ptr< Tree > readTree(std::istream &in) const override
Read a tree from a stream.
Partial implementation of the OTree interface.
virtual ~AbstractOMultiPhyloTree()
virtual void writePhyloTrees(const std::vector< const PhyloTree * > &trees, std::ostream &out) const =0
Write trees to a stream.
AbstractOMultiPhyloTree()
virtual void writePhyloTrees(const std::vector< const PhyloTree * > &trees, const std::string &path, bool overwrite) const
Write trees to a file.
Partial implementation of the OTree interface.
virtual ~AbstractOMultiTree()
virtual void writeTrees(const std::vector< const Tree * > &trees, std::ostream &out) const =0
Write trees to a stream.
virtual void writeTrees(const std::vector< const Tree * > &trees, const std::string &path, bool overwrite) const
Write trees to a file.
Partial implementation of the OTree interface.
virtual void writePhyloTree(const PhyloTree &tree, std::ostream &out) const =0
Write a tree to a stream.
virtual ~AbstractOPhyloTree()
virtual void writePhyloTree(const PhyloTree &tree, const std::string &path, bool overwrite) const
Write a tree to a file.
Partial implementation of the OTree interface.
virtual void writeTree(const Tree &tree, std::ostream &out) const =0
Write a tree to a stream.
virtual void writeTree(const Tree &tree, const std::string &path, bool overwrite) const
Write a tree to a file.
const char * what() const noexcept override
virtual void readPhyloTrees(const std::string &path, std::vector< std::unique_ptr< PhyloTree >> &trees) const =0
Read trees from a file.
virtual ~IMultiPhyloTree()
virtual void readPhyloTrees(std::istream &in, std::vector< std::unique_ptr< PhyloTree >> &trees) const =0
Read trees from a stream.
General interface for multiple trees readers.
virtual void readTrees(std::istream &in, std::vector< std::unique_ptr< Tree >> &trees) const =0
Read trees from a stream.
virtual void readTrees(const std::string &path, std::vector< std::unique_ptr< Tree >> &trees) const =0
Read trees from a file.
General interface for tree I/O.
virtual const std::string getDataType() const
General interface for tree readers.
virtual std::unique_ptr< PhyloTree > readPhyloTree(std::istream &in) const =0
Read a tree from a stream.
virtual std::unique_ptr< PhyloTree > readPhyloTree(const std::string &path) const =0
Read a tree from a file.
General interface for tree readers.
virtual std::unique_ptr< Tree > readTree(std::istream &in) const =0
Read a tree from a stream.
virtual std::unique_ptr< Tree > readTree(const std::string &path) const =0
Read a tree from a file.
General interface for tree writers.
virtual ~OMultiPhyloTree()
virtual void writePhyloTrees(const std::vector< const PhyloTree * > &trees, const std::string &path, bool overwrite) const =0
Write trees to a file.
virtual void writePhyloTrees(const std::vector< const PhyloTree * > &trees, std::ostream &out) const =0
Write trees to a stream.
General interface for tree writers.
virtual void writeTrees(const std::vector< const Tree * > &trees, const std::string &path, bool overwrite) const =0
Write trees to a file.
virtual void writeTrees(const std::vector< const Tree * > &trees, std::ostream &out) const =0
Write trees to a stream.
General interface for tree writers.
virtual void writePhyloTree(const PhyloTree &tree, const std::string &path, bool overwrite) const =0
Write a tree to a file.
virtual void writePhyloTree(const PhyloTree &tree, std::ostream &out) const =0
Write a tree to a stream.
General interface for tree writers.
virtual void writeTree(const Tree &tree, std::ostream &out) const =0
Write a tree to a stream.
virtual void writeTree(const Tree &tree, const std::string &path, bool overwrite) const =0
Write a tree to a file.
Interface for phylogenetic tree objects.
Defines the basic types of data flow nodes.