bpp-phyl  2.2.0
BppOSubstitutionModelFormat.h
Go to the documentation of this file.
1 //
2 // File: Bpp0SubstitutionModelFormat.h
3 // Created by: Laurent Guéguen
4 // Created on: mercredi 4 juillet 2012, à 13h 26
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _BPPOSUBSTITUTIONMODELFORMAT_H_
41 #define _BPPOSUBSTITUTIONMODELFORMAT_H_
42 
44 #include "../Model/MixedSubstitutionModel.h"
45 
46 // From bpp-seq
47 #include <Bpp/Seq/GeneticCode/GeneticCode.h>
48 
49 namespace bpp
50 {
60  public ISubstitutionModel,
61  public OSubstitutionModel
62 {
63 public:
64  static unsigned char DNA;
65  static unsigned char RNA;
66  static unsigned char NUCLEOTIDE;
67  static unsigned char PROTEIN;
68  static unsigned char CODON;
69  static unsigned char WORD;
70  static unsigned char BINARY;
71  static unsigned char ALL;
72 
73 private:
74  unsigned char alphabetCode_;
77  bool allowGaps_;
78  bool verbose_;
79  std::map<std::string, std::string> unparsedArguments_;
80  const GeneticCode* geneticCode_;
82 
83 public:
94  BppOSubstitutionModelFormat(unsigned char alphabetCode, bool allowCovarions, bool allowMixed, bool allowGaps, bool verbose, int warn):
95  alphabetCode_(alphabetCode),
96  allowCovarions_(allowCovarions),
97  allowMixed_(allowMixed),
98  allowGaps_(allowGaps),
99  verbose_(verbose),
101  geneticCode_(0),
102  warningLevel_(warn)
103  {}
104 
108  allowMixed_(format.allowMixed_),
109  allowGaps_(format.allowGaps_),
110  verbose_(format.verbose_),
112  geneticCode_(format.geneticCode_),
114  {}
115 
117  {
118  alphabetCode_ = format.alphabetCode_;
120  allowMixed_ = format.allowMixed_;
121  allowGaps_ = format.allowGaps_;
122  verbose_ = format.verbose_;
124  geneticCode_ = format.geneticCode_;
125  warningLevel_ = format.warningLevel_;
126  return *this;
127  }
128 
130 
131 public:
132  const std::string getFormatName() const { return "BppO"; }
133 
134  const std::string getFormatDescription() const { return "Bpp Options format."; }
135 
141  void setGeneticCode(const GeneticCode* gCode) {
142  geneticCode_ = gCode;
143  }
144 
145  SubstitutionModel* read(const Alphabet* alphabet, const std::string& modelDescription, const SiteContainer* data = 0, bool parseArguments = true);
146 
147  const std::map<std::string, std::string>& getUnparsedArguments() const { return unparsedArguments_; }
148 
160  void write(const SubstitutionModel& model,
161  OutputStream& out,
162  std::map<std::string, std::string>& globalAliases,
163  std::vector<std::string>& writtenNames) const;
164 
165  void setVerbose(bool verbose) { verbose_=verbose;}
166 
167 private:
168  MixedSubstitutionModel* readMixed_(const Alphabet* alphabet, const std::string& modelDescription, const SiteContainer* data);
169 
170  SubstitutionModel* readWord_(const Alphabet* alphabet, const std::string& modelDescription, const SiteContainer* data);
171 
186  void initialize_(SubstitutionModel& model, const SiteContainer* data) throw (Exception);
187 
188  void writeMixed_(const MixedSubstitutionModel& model,
189  OutputStream& out,
190  std::map<std::string, std::string>& globalAliases,
191  std::vector<std::string>& writtenNames) const;
192 };
193 
194 } // end of namespace bpp.
195 
196 #endif // _BPPOSUBSTITUTIONMODELFORMAT_H_
197 
Interface for all substitution models.
SubstitutionModel * readWord_(const Alphabet *alphabet, const std::string &modelDescription, const SiteContainer *data)
void writeMixed_(const MixedSubstitutionModel &model, OutputStream &out, std::map< std::string, std::string > &globalAliases, std::vector< std::string > &writtenNames) const
std::map< std::string, std::string > unparsedArguments_
BppOSubstitutionModelFormat(unsigned char alphabetCode, bool allowCovarions, bool allowMixed, bool allowGaps, bool verbose, int warn)
Create a new BppOSubstitutionModelFormat object.
void write(const SubstitutionModel &model, OutputStream &out, std::map< std::string, std::string > &globalAliases, std::vector< std::string > &writtenNames) const
Write a substitution model to a stream.
General interface for distance matrix readers.
General interface for distance matrix writers.
const std::map< std::string, std::string > & getUnparsedArguments() const
void initialize_(SubstitutionModel &model, const SiteContainer *data)
Set parameter initial values of a given model according to options.
BppOSubstitutionModelFormat & operator=(const BppOSubstitutionModelFormat &format)
const std::string getFormatDescription() const
MixedSubstitutionModel * readMixed_(const Alphabet *alphabet, const std::string &modelDescription, const SiteContainer *data)
Substitution model I/O in BppO format.
void setGeneticCode(const GeneticCode *gCode)
Set the genetic code to use in case a codon frequencies set should be built.
SubstitutionModel * read(const Alphabet *alphabet, const std::string &modelDescription, const SiteContainer *data=0, bool parseArguments=true)
Read a substitution model from a string.
BppOSubstitutionModelFormat(const BppOSubstitutionModelFormat &format)
Interface for Substitution models, defined as a mixture of "simple" substitution models.