bpp-seq3  3.0.0
IoDistanceMatrix.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_IODISTANCEMATRIX_H
6 #define BPP_PHYL_IO_IODISTANCEMATRIX_H
7 
8 #include <Bpp/Io/IoFormat.h>
10 
11 // From the STL:
12 #include <iostream>
13 #include <fstream>
14 
15 namespace bpp
16 {
21  public virtual IOFormat
22 {
23 public:
25  virtual ~IODistanceMatrix() {}
26 
27 public:
28  virtual const std::string getDataType() const { return "Distance matrix"; }
29 };
30 
35  public virtual IODistanceMatrix
36 {
37 public:
39  virtual ~IDistanceMatrix() {}
40 
41 public:
49  virtual std::unique_ptr<DistanceMatrix> readDistanceMatrix(const std::string& path) const = 0;
57  virtual std::unique_ptr<DistanceMatrix> readDistanceMatrix(std::istream& in) const = 0;
58 };
59 
64  public virtual IODistanceMatrix
65 {
66 public:
68  virtual ~ODistanceMatrix() {}
69 
70 public:
80  virtual void writeDistanceMatrix(const DistanceMatrix& dist, const std::string& path, bool overwrite) const = 0;
88  virtual void writeDistanceMatrix(const DistanceMatrix& dist, std::ostream& out) const = 0;
89 };
90 
95  public virtual IDistanceMatrix
96 {
97 public:
100 
101 public:
102  virtual std::unique_ptr<DistanceMatrix> readDistanceMatrix(const std::string& path) const
103  {
104  std::ifstream input(path.c_str(), std::ios::in);
105  auto mat = readDistanceMatrix(input);
106  input.close();
107  return mat;
108  }
109  virtual std::unique_ptr<DistanceMatrix> readDistanceMatrix(std::istream& in) const = 0;
110 };
111 
116  public virtual ODistanceMatrix
117 {
118 public:
121 
122 public:
123  virtual void writeDistanceMatrix(const DistanceMatrix& dist, const std::string& path, bool overwrite) const
124  {
125  // Open file in specified mode
126  std::ofstream output(path.c_str(), overwrite ? (std::ios::out) : (std::ios::out | std::ios::app));
127  writeDistanceMatrix(dist, output);
128  output.close();
129  }
130  virtual void writeDistanceMatrix(const DistanceMatrix& dist, std::ostream& out) const = 0;
131 };
132 } // end of namespace bpp.
133 #endif // BPP_PHYL_IO_IODISTANCEMATRIX_H
Partial implementation of the IDistanceMatrix interface.
virtual std::unique_ptr< DistanceMatrix > readDistanceMatrix(const std::string &path) const
Read a distance matrix from a file.
virtual std::unique_ptr< DistanceMatrix > readDistanceMatrix(std::istream &in) const =0
Read a distance matrix from a stream.
Partial implementation of the ODistanceMatrix interface.
virtual void writeDistanceMatrix(const DistanceMatrix &dist, std::ostream &out) const =0
Write a distance matrix to a stream.
virtual void writeDistanceMatrix(const DistanceMatrix &dist, const std::string &path, bool overwrite) const
Write a distance matrix to a file.
A Matrix class to store phylogenetic distances.
General interface for distance matrix readers.
virtual std::unique_ptr< DistanceMatrix > readDistanceMatrix(const std::string &path) const =0
Read a distance matrix from a file.
virtual std::unique_ptr< DistanceMatrix > readDistanceMatrix(std::istream &in) const =0
Read a distance matrix from a stream.
General interface for distance matrix I/O.
virtual const std::string getDataType() const
General interface for distance matrix writers.
virtual void writeDistanceMatrix(const DistanceMatrix &dist, const std::string &path, bool overwrite) const =0
Write a distance matrix to a file.
virtual void writeDistanceMatrix(const DistanceMatrix &dist, std::ostream &out) const =0
Write a distance matrix to a stream.
This alphabet is used to deal NumericAlphabet.