bpp-phyl3  3.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BppOSubstitutionModelFormat.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_BPPOSUBSTITUTIONMODELFORMAT_H
6 #define BPP_PHYL_IO_BPPOSUBSTITUTIONMODELFORMAT_H
7 
8 
10 #include "../Model/MixedTransitionModel.h"
11 
12 // From bpp-seq
15 
16 namespace bpp
17 {
25  public ISubstitutionModel,
26  public OSubstitutionModel
27 {
28 public:
29  static unsigned char DNA;
30  static unsigned char RNA;
31  static unsigned char NUCLEOTIDE;
32  static unsigned char PROTEIN;
33  static unsigned char CODON;
34  static unsigned char WORD;
35  static unsigned char BINARY;
36  static unsigned char INTEGER;
37  static unsigned char ALL;
38 
39 protected:
40  unsigned char alphabetCode_;
43  bool allowGaps_;
44  bool verbose_;
45  std::map<std::string, std::string> unparsedArguments_;
46  std::shared_ptr<const GeneticCode> geneticCode_;
48 
49 public:
60  BppOSubstitutionModelFormat(unsigned char alphabetCode, bool allowCovarions, bool allowMixed, bool allowGaps, bool verbose, int warn) :
61  alphabetCode_(alphabetCode),
62  allowCovarions_(allowCovarions),
63  allowMixed_(allowMixed),
64  allowGaps_(allowGaps),
65  verbose_(verbose),
67  geneticCode_(0),
68  warningLevel_(warn)
69  {}
70 
74  allowMixed_(format.allowMixed_),
75  allowGaps_(format.allowGaps_),
76  verbose_(format.verbose_),
78  geneticCode_(format.geneticCode_),
80  {}
81 
83  {
86  allowMixed_ = format.allowMixed_;
87  allowGaps_ = format.allowGaps_;
88  verbose_ = format.verbose_;
90  geneticCode_ = format.geneticCode_;
92  return *this;
93  }
94 
96 
97 public:
98  const std::string getFormatName() const override { return "BppO"; }
99 
100  const std::string getFormatDescription() const override { return "Bpp Options format."; }
101 
107  void setGeneticCode(std::shared_ptr<const GeneticCode> gCode)
108  {
109  geneticCode_ = gCode;
110  }
111 
112  std::unique_ptr<SubstitutionModelInterface> readSubstitutionModel(
113  std::shared_ptr<const Alphabet> alphabet,
114  const std::string& modelDescription,
115  const std::map<size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
116  size_t nData,
117  bool parseArguments = true) override;
118 
119  const std::map<std::string, std::string>& getUnparsedArguments() const override
120  {
121  return unparsedArguments_;
122  }
123 
135  void write(const BranchModelInterface& model,
136  OutputStream& out,
137  std::map<std::string, std::string>& globalAliases,
138  std::vector<std::string>& writtenNames) const override;
139 
140  void setVerbose(bool verbose) { verbose_ = verbose;}
141 
142 private:
143  std::unique_ptr<SubstitutionModelInterface> readWord_(
144  std::shared_ptr<const Alphabet> alphabet,
145  const std::string& modelDescription,
146  const std::map<size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
147  size_t nData);
148 
149  void writeMixed_(const MixedTransitionModelInterface& model,
150  OutputStream& out,
151  std::map<std::string, std::string>& globalAliases,
152  std::vector<std::string>& writtenNames) const;
153 
154 protected:
158  void updateParameters_(
159  BranchModelInterface& model,
160  std::map<std::string, std::string>& args);
161 
176  void initialize_(
177  BranchModelInterface& model,
178  std::shared_ptr<const AlignmentDataInterface> data);
179 };
180 } // end of namespace bpp.
181 #endif // BPP_PHYL_IO_BPPOSUBSTITUTIONMODELFORMAT_H
Substitution model I/O in BppO format.
void writeMixed_(const MixedTransitionModelInterface &model, OutputStream &out, std::map< std::string, std::string > &globalAliases, std::vector< std::string > &writtenNames) const
std::unique_ptr< SubstitutionModelInterface > readWord_(std::shared_ptr< const Alphabet > alphabet, const std::string &modelDescription, const std::map< size_t, std::shared_ptr< const AlignmentDataInterface >> &mData, size_t nData)
void write(const BranchModelInterface &model, OutputStream &out, std::map< std::string, std::string > &globalAliases, std::vector< std::string > &writtenNames) const override
Write a substitution model to a stream.
const std::string getFormatDescription() const override
BppOSubstitutionModelFormat & operator=(const BppOSubstitutionModelFormat &format)
BppOSubstitutionModelFormat(unsigned char alphabetCode, bool allowCovarions, bool allowMixed, bool allowGaps, bool verbose, int warn)
Create a new BppOSubstitutionModelFormat object.
void updateParameters_(BranchModelInterface &model, std::map< std::string, std::string > &args)
Finish parsing of parameters, taking care of aliases.
std::unique_ptr< SubstitutionModelInterface > readSubstitutionModel(std::shared_ptr< const Alphabet > alphabet, const std::string &modelDescription, const std::map< size_t, std::shared_ptr< const AlignmentDataInterface >> &mData, size_t nData, bool parseArguments=true) override
Read a substitution model from a string.
std::shared_ptr< const GeneticCode > geneticCode_
const std::string getFormatName() const override
const std::map< std::string, std::string > & getUnparsedArguments() const override
BppOSubstitutionModelFormat(const BppOSubstitutionModelFormat &format)
void setGeneticCode(std::shared_ptr< const GeneticCode > gCode)
Set the genetic code to use in case a codon frequencies set should be built.
std::map< std::string, std::string > unparsedArguments_
void initialize_(BranchModelInterface &model, std::shared_ptr< const AlignmentDataInterface > data)
Set parameter initial values of a given model according to options.
Interface for all Branch models.
General interface for model readers.
Interface for Transition models, defined as a mixture of "simple" transition models.
General interface for distance matrix writers.
Defines the basic types of data flow nodes.