bpp-seq3  3.0.0
CodonFromProteicAlphabetIndex1.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_CODONFROMPROTEICALPHABETINDEX1_H
6 #define BPP_SEQ_ALPHABETINDEX_CODONFROMPROTEICALPHABETINDEX1_H
7 
8 
9 #include "../Alphabet/CodonAlphabet.h"
10 #include "../GeneticCode/GeneticCode.h"
11 #include "AlphabetIndex1.h"
12 
13 namespace bpp
14 {
19  public virtual AlphabetIndex1
20 {
21 private:
22  std::shared_ptr<const CodonAlphabet> alpha_;
23  std::shared_ptr<const GeneticCode> gencode_;
24  std::vector<double> vIndex_;
25 
26 public:
28  std::shared_ptr<const GeneticCode> gencode,
29  std::shared_ptr<const AlphabetIndex1> protalphindex) :
31  alpha_(AlphabetTools::DNA_CODON_ALPHABET),
32  gencode_(gencode),
33  vIndex_(64)
34  {
35  if (!AlphabetTools::isProteicAlphabet(protalphindex->alphabet()))
36  throw Exception("CodonFromProteicAlphabetIndex1: Not a Proteic Alphabet for CodonAlphabetIndex1.");
37  fillIndex_(protalphindex);
38  }
39 
41  alpha_(cfp.alpha_),
42  gencode_(cfp.gencode_),
43  vIndex_(cfp.vIndex_)
44  {}
45 
47  {
48  alpha_ = cfp.alpha_;
49  gencode_ = cfp.gencode_;
50  vIndex_ = cfp.vIndex_;
51 
52  return *this;
53  }
54 
56 
58  {
59  return new CodonFromProteicAlphabetIndex1(*this);
60  }
61 
62 public:
63  double getIndex(int state) const override
64  {
65  return vIndex_[getAlphabet()->getStateIndex(state) - 1];
66  }
67 
68  double getIndex(const std::string& state) const override
69  {
70  return vIndex_[getAlphabet()->getStateIndex(state) - 1];
71  }
72 
73  std::shared_ptr<const Alphabet> getAlphabet() const override
74  {
75  return alpha_;
76  }
77 
78  const Alphabet& alphabet() const override
79  {
80  return *alpha_;
81  }
82 
83  const std::vector<double>& indexVector() const override
84  {
85  return vIndex_;
86  }
87 
88 private:
89  void fillIndex_(std::shared_ptr<const AlphabetIndex1> protAlphIndex_)
90  {
91  for (int i = 0; i < 64; i++)
92  {
93  vIndex_[getAlphabet()->getStateIndex(i) - 1] = gencode_->isStop(i) ? 0 : protAlphIndex_->getIndex(gencode_->translate(i));
94  }
95  }
96 };
97 } // end of namespace bpp.
98 #endif // BPP_SEQ_ALPHABETINDEX_CODONFROMPROTEICALPHABETINDEX1_H
One dimensionnal alphabet index interface.
Utilitary functions dealing with alphabets.
Definition: AlphabetTools.h:32
static bool isProteicAlphabet(const Alphabet &alphabet)
The Alphabet interface.
Definition: Alphabet.h:99
AlphabetIndex1 for codon based on ProteicAlphabetIndex1.
const std::vector< double > & indexVector() const override
CodonFromProteicAlphabetIndex1(std::shared_ptr< const GeneticCode > gencode, std::shared_ptr< const AlphabetIndex1 > protalphindex)
const Alphabet & alphabet() const override
Get the alphabet associated to this index.
CodonFromProteicAlphabetIndex1 * clone() const override
double getIndex(const std::string &state) const override
Get the index associated to a state.
std::shared_ptr< const CodonAlphabet > alpha_
double getIndex(int state) const override
Get the index associated to a state.
std::shared_ptr< const Alphabet > getAlphabet() const override
Get the alphabet associated to this index.
CodonFromProteicAlphabetIndex1 & operator=(const CodonFromProteicAlphabetIndex1 &cfp)
CodonFromProteicAlphabetIndex1(const CodonFromProteicAlphabetIndex1 &cfp)
std::shared_ptr< const GeneticCode > gencode_
void fillIndex_(std::shared_ptr< const AlphabetIndex1 > protAlphIndex_)
This alphabet is used to deal NumericAlphabet.