bpp-core3  3.0.0
UserAlphabetIndex2.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_SEQ_ALPHABETINDEX_USERALPHABETINDEX2_H
6 #define BPP_SEQ_ALPHABETINDEX_USERALPHABETINDEX2_H
7 
8 #include <Bpp/Numeric/Matrix/MatrixTools.h>
9 
10 #include "AlphabetIndex2.h"
11 
12 // From the STL:
13 #include <vector>
14 
15 namespace bpp
16 {
22  public virtual AlphabetIndex2
23 {
24 private:
25  std::shared_ptr<const Alphabet> alph_;
26  LinearMatrix<double> index_;
27  bool sym_;
28 
29 public:
30  UserAlphabetIndex2(std::shared_ptr<const Alphabet> alph, const Matrix<double>& mat) :
31  alph_(alph),
32  index_(mat),
33  sym_(false)
34  {
35  sym_ = MatrixTools::isSymmetric(index_);
36  }
37 
39  alph_(uAlph.alph_),
40  index_(uAlph.index_),
41  sym_(uAlph.sym_)
42  {}
43 
45  {
46  alph_ = uAlph.alph_;
47  index_ = uAlph.index_;
48  sym_ = uAlph.sym_;
49 
50  return *this;
51  }
52 
53  virtual ~UserAlphabetIndex2() {}
54 
55  UserAlphabetIndex2* clone() const { return new UserAlphabetIndex2(*this); }
56 
57 public:
58  double getIndex(int state1, int state2) const
59  {
60  return index_(alph_->getStateIndex(state1) - 1, alph_->getStateIndex(state2) - 1);
61  }
62 
63  double getIndex(const std::string& state1, const std::string& state2) const
64  {
65  return index_(alph_->getStateIndex(state1) - 1, alph_->getStateIndex(state2) - 1);
66  }
67 
68  void setIndexMatrix(const Matrix<double>& mat)
69  {
70  index_ = mat;
71  sym_ = MatrixTools::isSymmetric(index_);
72  }
73 
74  LinearMatrix<double>* getIndexMatrix() const { return new LinearMatrix<double>(index_); }
75 
76  std::shared_ptr<const Alphabet> getAlphabet() const { return alph_; }
77 
78  const Alphabet& alphabet() const { return *alph_; }
79 
83  virtual bool isSymmetric() const
84  {
85  return sym_;
86  }
87 };
88 } // end of namespace bpp.
89 #endif // BPP_SEQ_ALPHABETINDEX_USERALPHABETINDEX2_H
std::shared_ptr< const Alphabet > getAlphabet() const
Get the alphabet associated to this index.
void setIndexMatrix(const Matrix< double > &mat)
This alphabet is used to deal NumericAlphabet.
virtual bool isSymmetric() const
The Alphabet interface.
Definition: Alphabet.h:96
UserAlphabetIndex2 & operator=(const UserAlphabetIndex2 &uAlph)
std::shared_ptr< const Alphabet > alph_
UserAlphabetIndex2(const UserAlphabetIndex2 &uAlph)
LinearMatrix< double > index_
UserAlphabetIndex2 * clone() const
const Alphabet & alphabet() const
Get the alphabet associated to this index.
Alphabet index given by user.
UserAlphabetIndex2(std::shared_ptr< const Alphabet > alph, const Matrix< double > &mat)
Two dimensionnal alphabet index interface.
double getIndex(int state1, int state2) const
Get the index associated to a pair of states.
LinearMatrix< double > * getIndexMatrix() const
double getIndex(const std::string &state1, const std::string &state2) const
Get the index associated to a pair of states.