bpp-phyl3  3.0.0
NucleotideFrequencySet.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_MODEL_FREQUENCYSET_NUCLEOTIDEFREQUENCYSET_H
6 #define BPP_PHYL_MODEL_FREQUENCYSET_NUCLEOTIDEFREQUENCYSET_H
7 
9 
10 #include "FrequencySet.h"
11 
12 namespace bpp
13 {
18  public virtual FrequencySetInterface
19 {
20 public:
21  NucleotideFrequencySetInterface* clone() const override = 0;
22 
23  virtual std::shared_ptr<const NucleicAlphabet> getNucleicAlphabet() const = 0;
24 };
25 
30  public virtual NucleotideFrequencySetInterface,
32 {
33 public:
34  GCFrequencySet(std::shared_ptr<const NucleicAlphabet> alphabet) :
35  AbstractFrequencySet(std::make_shared<const CanonicalStateMap>(alphabet, false), "GC.", "GC")
36  {
38  getFreq_(0) = getFreq_(1) = getFreq_(2) = getFreq_(3) = 0.25;
39  }
40 
41  GCFrequencySet(std::shared_ptr<const NucleicAlphabet> alphabet, double theta) :
42  AbstractFrequencySet(std::make_shared<const CanonicalStateMap>(alphabet, false), "GC.", "GC")
43  {
44  addParameter_(new Parameter("GC.theta", theta, Parameter::PROP_CONSTRAINT_IN));
45  getFreq_(0) = getFreq_(3) = (1. - theta) / 2.;
46  getFreq_(1) = getFreq_(2) = theta / 2.;
47  }
48 
49  GCFrequencySet* clone() const override
50  {
51  return new GCFrequencySet(*this);
52  }
53 
56  {}
57 
58 public:
59  std::shared_ptr<const NucleicAlphabet> getNucleicAlphabet() const override
60  {
61  return std::dynamic_pointer_cast<const NucleicAlphabet>(getAlphabet());
62  }
63 
64  void setFrequencies(const std::vector<double>& frequencies) override;
65 
66 protected:
67  void fireParameterChanged(const ParameterList& parameters) override;
68 };
69 
92  public virtual NucleotideFrequencySetInterface,
94 {
95 public:
97  std::shared_ptr<const NucleicAlphabet> alphabet,
98  bool allowNullFreqs = false,
99  const std::string& name = "Full");
100 
102  std::shared_ptr<const NucleicAlphabet> alphabet,
103  double theta, double theta1, double theta2,
104  bool allowNullFreqs = false,
105  const std::string& name = "Full");
106 
107  FullNucleotideFrequencySet* clone() const override { return new FullNucleotideFrequencySet(*this); }
108 
109 public:
110  std::shared_ptr<const NucleicAlphabet> getNucleicAlphabet() const override
111  {
112  return std::dynamic_pointer_cast<const NucleicAlphabet>(getAlphabet());
113  }
114 
115  void setFrequencies(const std::vector<double>& frequencies) override;
116 
117 protected:
118  void fireParameterChanged(const ParameterList& parameters) override;
119 };
120 
121 
128  public virtual NucleotideFrequencySetInterface,
129  public FixedFrequencySet
130 {
131 public:
133  std::shared_ptr<const NucleicAlphabet> alphabet,
134  const std::vector<double>& initFreqs,
135  const std::string& name = "Fixed") :
136  FixedFrequencySet(std::make_shared<const CanonicalStateMap>(alphabet, false), initFreqs, name) {}
137 
143  std::shared_ptr<const NucleicAlphabet> alphabet,
144  const std::string& name = "Fixed") :
145  FixedFrequencySet(std::make_shared<const CanonicalStateMap>(alphabet, false), name) {}
146 
147  FixedNucleotideFrequencySet* clone() const override { return new FixedNucleotideFrequencySet(*this); }
148 
149  std::shared_ptr<const NucleicAlphabet> getNucleicAlphabet() const override
150  {
151  return std::dynamic_pointer_cast<const NucleicAlphabet>(getAlphabet());
152  }
153 };
154 
161  public virtual NucleotideFrequencySetInterface,
162  public UserFrequencySet
163 {
164 public:
166  std::shared_ptr<const NucleicAlphabet> alphabet,
167  const std::string& path,
168  size_t nCol = 1) :
169  UserFrequencySet(std::make_shared<const CanonicalStateMap>(alphabet, false), path, nCol) {}
170 
171  UserNucleotideFrequencySet* clone() const override { return new UserNucleotideFrequencySet(*this); }
172 
173  std::shared_ptr<const NucleicAlphabet> getNucleicAlphabet() const override
174  {
175  return std::dynamic_pointer_cast<const NucleicAlphabet>(getAlphabet());
176  }
177 };
178 } // end of namespace bpp.
179 #endif // BPP_PHYL_MODEL_FREQUENCYSET_NUCLEOTIDEFREQUENCYSET_H
Basic implementation of the FrequencySet interface.
Definition: FrequencySet.h:102
const Alphabet & alphabet() const override
Definition: FrequencySet.h:142
std::shared_ptr< const Alphabet > getAlphabet() const override
Definition: FrequencySet.h:140
double & getFreq_(size_t i)
Definition: FrequencySet.h:179
void addParameter_(Parameter *parameter)
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
FrequencySet useful for homogeneous and stationary models.
Definition: FrequencySet.h:347
FrequencySet useful for homogeneous and stationary models, nucleotide implementation.
FixedNucleotideFrequencySet * clone() const override
FixedNucleotideFrequencySet(std::shared_ptr< const NucleicAlphabet > alphabet, const std::string &name="Fixed")
Construction with uniform frequencies on the letters of the alphabet.
FixedNucleotideFrequencySet(std::shared_ptr< const NucleicAlphabet > alphabet, const std::vector< double > &initFreqs, const std::string &name="Fixed")
std::shared_ptr< const NucleicAlphabet > getNucleicAlphabet() const override
Parametrize a set of state frequencies.
Definition: FrequencySet.h:29
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
virtual const Alphabet & alphabet() const =0
Nucleotide FrequencySet using three independent parameters (theta, theta1, theta2) to modelize the fo...
void fireParameterChanged(const ParameterList &parameters) override
FullNucleotideFrequencySet * clone() const override
FullNucleotideFrequencySet(std::shared_ptr< const NucleicAlphabet > alphabet, bool allowNullFreqs=false, const std::string &name="Full")
void setFrequencies(const std::vector< double > &frequencies) override
Set the parameters in order to match a given set of frequencies.
std::shared_ptr< const NucleicAlphabet > getNucleicAlphabet() const override
Nucleotide FrequencySet using only one parameter, the GC content.
GCFrequencySet(const GCFrequencySet &gcf)
GCFrequencySet(std::shared_ptr< const NucleicAlphabet > alphabet, double theta)
GCFrequencySet * clone() const override
void setFrequencies(const std::vector< double > &frequencies) override
Set the parameters in order to match a given set of frequencies.
void fireParameterChanged(const ParameterList &parameters) override
std::shared_ptr< const NucleicAlphabet > getNucleicAlphabet() const override
GCFrequencySet(std::shared_ptr< const NucleicAlphabet > alphabet)
Parametrize a set of state frequencies for nucleotides.
virtual std::shared_ptr< const NucleicAlphabet > getNucleicAlphabet() const =0
NucleotideFrequencySetInterface * clone() const override=0
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_IN
FrequencySet to be read in a file. More specifically, a frequency set is read in a column of a given ...
Definition: FrequencySet.h:386
FrequencySet useful for homogeneous and stationary models, nucleotide implementation.
UserNucleotideFrequencySet * clone() const override
UserNucleotideFrequencySet(std::shared_ptr< const NucleicAlphabet > alphabet, const std::string &path, size_t nCol=1)
std::shared_ptr< const NucleicAlphabet > getNucleicAlphabet() const override
Defines the basic types of data flow nodes.