bpp-phyl  2.2.0
SubstitutionRegister.h
Go to the documentation of this file.
1 //
2 // File: SubstitutionRegister.h
3 // Created by: Julien Dutheil
4 // Created on: Mon Dec 6 16:32 2010
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
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 _SUBSTITUTIONREGISTER_H_
41 #define _SUBSTITUTIONREGISTER_H_
42 
43 #include "../Model/SubstitutionModel.h"
44 #include "../Model/Nucleotide/NucleotideSubstitutionModel.h"
45 #include "../Model/Codon/CodonSubstitutionModel.h"
46 
47 // From bpp-core:
48 #include <Bpp/Clonable.h>
49 #include <Bpp/Numeric/Matrix/Matrix.h>
50 #include <Bpp/Text/StringTokenizer.h>
51 
52 // From bpp-seq:
53 #include <Bpp/Seq/Alphabet/NucleicAlphabet.h>
54 #include <Bpp/Seq/Alphabet/CodonAlphabet.h>
55 #include <Bpp/Seq/GeneticCode/GeneticCode.h>
56 
57 // From the STL:
58 #include <vector>
59 #include <string>
60 #include <algorithm>
61 
62 namespace bpp
63 {
73  public virtual Clonable
74 {
75 public:
77  virtual ~SubstitutionRegister() {}
78 
79 #ifndef NO_VIRTUAL_COV
80  virtual SubstitutionRegister* clone() const = 0;
81 #endif
82 
83 public:
87  virtual const Alphabet* getAlphabet() const = 0;
88 
92  virtual const SubstitutionModel* getSubstitutionModel() const = 0;
93 
97  virtual size_t getNumberOfSubstitutionTypes() const = 0;
98 
107  virtual size_t getType(size_t fromState, size_t toState) const = 0;
108 
118  virtual std::string getTypeName(size_t type) const = 0;
119 };
120 
122  public virtual SubstitutionRegister
123 {
124 protected:
126 
127 public:
129  model_(model)
130  {}
131 
133  model_(asr.model_)
134  {}
135 
137  {
138  model_ = asr.model_;
139  return *this;
140  }
141 
143 
144 public:
145  const SubstitutionModel* getSubstitutionModel() const { return model_; }
146 
147  const Alphabet* getAlphabet() const { return model_->getAlphabet(); }
148 };
149 
157 {
158 protected:
159  bool within_;
161  mutable std::map<int, size_t> categories_;
162  std::vector<std::string> categoryNames_;
163  std::vector< std::vector<size_t> > index_;
164  std::vector< std::vector<size_t> > revIndex_;
165 
166 public:
173  CategorySubstitutionRegister(const SubstitutionModel* model, bool within = false) :
175  within_(within),
176  nbCategories_(0),
177  categories_(),
178  categoryNames_(),
179  index_(),
180  revIndex_()
181  {}
182 
183 protected:
184  template<class T>
185  void setCategories(const std::map<int, T>& categories)
186  {
187  // First index categories:
188  nbCategories_ = 0;
189  std::map<T, size_t> cats;
190  for (typename std::map<int, T>::const_iterator it = categories.begin(); it != categories.end(); ++it)
191  {
192  if (cats.find(it->second) == cats.end())
193  {
194  ++nbCategories_;
195  cats[it->second] = nbCategories_;
196  }
197  }
198 
199  // Now creates categories:
200  categories_.clear();
202  std::vector<int> types = model_->getAlphabetStates();
203  for (size_t i = 0; i < types.size(); ++i)
204  {
205  typename std::map<int, T>::const_iterator it = categories.find(types[i]);
206  if (it != categories.end())
207  {
208  categories_[types[i]] = cats[it->second];
209  categoryNames_[cats[it->second] - 1] += model_->getAlphabet()->intToChar(types[i]);
210  }
211  else
212  {
213  categories_[types[i]] = 0;
214  }
215  }
216 
217  size_t count = 1;
218  index_.resize(nbCategories_);
219  for (size_t i = 0; i < index_.size(); ++i)
220  {
221  index_[i].resize(nbCategories_);
222  for (size_t j = 0; j < index_.size(); ++j)
223  {
224  if (j != i)
225  {
226  index_[i][j] = count++;
227  std::vector<size_t> pos(2);
228  pos[0] = i;
229  pos[1] = j;
230  revIndex_.push_back(pos);
231  }
232  }
233  }
234  if (within_)
235  {
236  for (size_t i = 0; i < index_.size(); ++i)
237  {
238  index_[i][i] = count++;
239  std::vector<size_t> pos(2);
240  pos[0] = i;
241  pos[1] = i;
242  revIndex_.push_back(pos);
243  }
244  }
245  }
246 
247 public:
248  virtual size_t getCategory(size_t state) const
249  {
250  int alphabetState = model_->getAlphabetStateAsInt(state);
251  return categories_[alphabetState];
252  }
253 
254  virtual size_t getCategoryFrom(size_t type) const
255  {
256  if (type <= nbCategories_ * (nbCategories_ - 1))
257  {
258  return revIndex_[type - 1][0] + 1;
259  }
260  else
261  {
262  if (within_)
263  return revIndex_[type - 1][0] + 1;
264  else
265  throw Exception("CategorySubstitutionRegister::getCategoryFrom. Bad substitution type.");
266  }
267  }
268 
269  virtual size_t getCategoryTo(size_t type) const
270  {
271  if (type <= nbCategories_ * (nbCategories_ - 1))
272  {
273  return revIndex_[type - 1][1] + 1;
274  }
275  else
276  {
277  if (within_)
278  return revIndex_[type - 1][1] + 1;
279  else
280  throw Exception("CategorySubstitutionRegister::getCategoryTo. Bad substitution type.");
281  }
282  }
283 
284  virtual std::string getCategoryName(size_t category) const
285  {
286  return categoryNames_[category - 1];
287  }
288 
289  virtual bool allowWithin() const { return within_; }
290 
291  size_t getNumberOfCategories() const { return nbCategories_; }
292 
293  size_t getNumberOfSubstitutionTypes() const { return nbCategories_ * (nbCategories_ - 1) + (within_ ? nbCategories_ : 0); }
294 
295  virtual size_t getType(size_t fromState, size_t toState) const
296  {
297  size_t fromCat = categories_[model_->getAlphabetStateAsInt(fromState)];
298  size_t toCat = categories_[model_->getAlphabetStateAsInt(toState)];
299  if (fromCat > 0 && toCat > 0)
300  return index_[fromCat - 1][toCat - 1];
301  else
302  return 0;
303  }
304 
305  std::string getTypeName(size_t type) const
306  {
307  return getCategoryName(getCategoryFrom(type)) + "->" + getCategoryName(getCategoryTo(type));
308  }
309 };
310 
311 
321 {
322 public:
325  {}
326 
328 
329 public:
330  size_t getNumberOfSubstitutionTypes() const { return 1; }
331 
332  size_t getType(size_t fromState, size_t toState) const
333  {
334  return fromState == toState ? 0 : 1;
335  }
336 
337  std::string getTypeName(size_t type) const
338  {
339  if (type == 0)
340  {
341  return "no substitution";
342  }
343  else if (type == 1)
344  {
345  return "substitution";
346  }
347  else
348  {
349  throw Exception("TotalSubstitutionRegister::getTypeName. Bad substitution type.");
350  }
351  }
352 };
353 
361 {
362 private:
364 
366 
367 public:
370  preg_(reg.clone()),
371  isRegComplete_(true)
372  {
373  size_t size = reg.getAlphabet()->getSize();
374  for (size_t i = 0; i < size; i++)
375  {
376  for (size_t j = 0; j < size; j++)
377  {
378  if ((i != j) && reg.getType(i, j) == 0)
379  {
380  isRegComplete_ = false;
381  return;
382  }
383  }
384  }
385  }
386 
388 
391  preg_(csr.preg_->clone()),
393  {}
394 
396  {
398  preg_ = csr.preg_->clone();
400  return *this;
401  }
402 
404  {
405  if (preg_)
406  delete preg_;
407  preg_ = 0;
408  }
409 
410 public:
412  {
413  return preg_->getNumberOfSubstitutionTypes() + (isRegComplete_ ? 0 : 1);
414  }
415 
416  size_t getType(size_t fromState, size_t toState) const
417  {
418  size_t t = preg_->getType(fromState, toState);
419  if (t == 0)
421  else
422  return t;
423  }
424 
425  std::string getTypeName(size_t type) const
426  {
427  try
428  {
429  return preg_->getTypeName(type);
430  }
431  catch (Exception& e)
432  {
433  if (type == getNumberOfSubstitutionTypes())
434  return "Completion substitution";
435  else
436  throw Exception("CompleteSubstitutionRegister::getTypeName. Bad substitution type.");
437  }
438  }
439 };
440 
450 {
451 public:
452  ComprehensiveSubstitutionRegister(const SubstitutionModel* model, bool within = false) :
453  CategorySubstitutionRegister(model, within)
454  {
455  std::map<int, int> categories;
456  for (int i = 0; i < static_cast<int>(model->getAlphabet()->getSize()); ++i)
457  {
458  categories[i] = i;
459  }
460  setCategories<int>(categories);
461  }
462 
464 };
465 
475 {
476 protected:
480  size_t size_;
481 
486  RowMatrix<size_t> matrix_;
487 
496  std::map<size_t, std::map<size_t, std::vector<size_t> > > types_;
497 
498 public:
501  size_(model->getNumberOfStates()),
502  matrix_(size_, size_),
503  types_()
504  {}
505 
506  GeneralSubstitutionRegister(const SubstitutionModel* model, const RowMatrix<size_t>& matrix) :
508  size_(model->getNumberOfStates()),
509  matrix_(matrix),
510  types_()
511  {
512  if (matrix_.getNumberOfRows() != size_)
513  throw DimensionException("GeneralSubstitutionRegister", size_, matrix_.getNumberOfRows());
514  if (matrix_.getNumberOfColumns() != size_)
515  throw DimensionException("GeneralSubstitutionRegister", size_, matrix_.getNumberOfColumns());
516  updateTypes_();
517  }
518 
521  size_(gsr.size_),
522  matrix_(gsr.matrix_),
523  types_(gsr.types_)
524  {}
525 
527  {
529  size_ = gsr.size_;
530  matrix_ = gsr.matrix_;
531  types_ = gsr.types_;
532  return *this;
533  }
534 
536 
538 
539  size_t getType(size_t i, size_t j) const
540  {
541  return matrix_(i, j);
542  }
543 
545  {
546  return types_.find(0) == types_.end() ? types_.size() : types_.size() - 1;
547  }
548 
552  std::string getTypeName(size_t type) const
553  {
554  if (types_.find(type) != types_.end())
555  return TextTools::toString(type);
556 
557  throw Exception("Bad type number " + TextTools::toString(type) + " in GeneralSubstitutionRegister::getTypeName.");
558  }
559 
560 protected:
561  void updateTypes_();
562 };
563 
564 
575 {
576  std::map<size_t, std::string> categoryNames_;
577 
578 public:
579  SelectedSubstitutionRegister (const SubstitutionModel* model, std::string selectedSubstitutions) :
582  {
583  selectedSubstitutions.erase(std::remove(selectedSubstitutions.begin(), selectedSubstitutions.end(), ' '), selectedSubstitutions.end());
595  size_t typeSubs = 0;
596  size_t coord1 = 0;
597  size_t coord2 = 0;
598  std::string codon1 = "";
599  std::string codon2 = "";
600  StringTokenizer subsGroup(selectedSubstitutions, "()");
601  while (subsGroup.hasMoreToken())
602  {
603  typeSubs++;
604  StringTokenizer namesSubs(subsGroup.nextToken(), ":");
605  if (namesSubs.numberOfRemainingTokens() == 2)
606  {
607  categoryNames_[typeSubs] = namesSubs.nextToken();
608  }
609  else if (namesSubs.numberOfRemainingTokens() == 1)
610  {
611  categoryNames_[typeSubs] = TextTools::toString(typeSubs);
612  }
613  StringTokenizer substitutions(namesSubs.nextToken(), ",");
614  while (substitutions.hasMoreToken())
615  {
616  StringTokenizer coordinates(substitutions.nextToken(), "->");
617  codon1 = coordinates.nextToken();
618  codon2 = coordinates.nextToken();
619  coord1 = model_->getAlphabet()->getStateIndex(codon1);
620  coord2 = model_->getAlphabet()->getStateIndex(codon2);
621  this->matrix_(coord1, coord2) = typeSubs;
622  }
623  }
624  updateTypes_();
625  }
626 
628 
630 
631  std::string getTypeName(size_t type) const
632  {
633  if (types_.find(type) != types_.end())
634  return TextTools::toString(categoryNames_.find(type)->second);
635 
636  throw Exception("Bad type number " + TextTools::toString(type) + " in GeneralSubstitutionRegister::getTypeName.");
637  }
638 };
639 
650 {
651  std::map<std::string, size_t> categoryCorrespondance_;
652 
653 public:
657  {
658  size_t categoryIndex = 1;
659  for (size_t i = 0; i < model->getAlphabet()->getSize(); ++i)
660  {
661  int state1 = model->getAlphabet()->getStateAt(i).getNum();
662  for (size_t j = i + 1; j < model->getAlphabet()->getSize(); ++j)
663  {
664  int state2 = model->getAlphabet()->getStateAt(j).getNum();
665  if (!(model->getGeneticCode()->isStop(state1)) && !(model->getGeneticCode()->isStop(state2)))
666  {
667  if (model->getGeneticCode()->translate(state1) == model->getGeneticCode()->translate(state2))
668  {
669  std::string aminoAcid = model->getGeneticCode()->getTargetAlphabet()->intToChar(model->getGeneticCode()->translate(state1));
670  if (categoryCorrespondance_.find(aminoAcid) == categoryCorrespondance_.end())
671  {
672  categoryCorrespondance_[aminoAcid] = categoryIndex;
673  categoryIndex++;
674  }
675  matrix_(i, j) = categoryCorrespondance_[aminoAcid];
676  matrix_(j, i) = categoryCorrespondance_[aminoAcid];
677  }
678  }
679  }
680  }
681  updateTypes_();
682  }
683 
685 
687 
688 
689  std::string getTypeName(size_t type) const
690  {
691  if (types_.find(type) != types_.end())
692  {
693  for (std::map<std::string, size_t>::const_iterator it = categoryCorrespondance_.begin(); it != categoryCorrespondance_.end(); it++)
694  {
695  if (it->second == type)
696  return TextTools::toString(it->first);
697  }
698  }
699  throw Exception("Bad type number " + TextTools::toString(type) + " in GeneralSubstitutionRegister::getTypeName.");
700  }
701 };
702 
712 {
713  std::map<std::string, size_t> categoryCorrespondance_;
714 
715 public:
719  {
720  size_t categoryIndex = 1;
721  for (size_t i = 0; i < model->getAlphabet()->getSize(); ++i)
722  {
723  int state1 = model->getAlphabet()->getStateAt(i).getNum();
724  for (size_t j = i + 1; j < model->getAlphabet()->getSize(); ++j)
725  {
726  int state2 = model->getAlphabet()->getStateAt(j).getNum();
727  if (!(model->getGeneticCode()->isStop(state1)) && !(model->getGeneticCode()->isStop(state2)))
728  {
729  if (model->getGeneticCode()->translate(state1) != model->getGeneticCode()->translate(state2))
730  {
731  std::string aminoAcid1 = model->getGeneticCode()->getTargetAlphabet()->intToChar(model->getGeneticCode()->translate(state1));
732  std::string aminoAcid2 = model->getGeneticCode()->getTargetAlphabet()->intToChar(model->getGeneticCode()->translate(state2));
733  bool AA1IsNotInGroup = ((categoryCorrespondance_.find(aminoAcid1 + "->" + aminoAcid2) == categoryCorrespondance_.end()));
734  bool AA2IsNotInGroup = ((categoryCorrespondance_.find(aminoAcid2 + "->" + aminoAcid1) == categoryCorrespondance_.end()));
735  if (AA1IsNotInGroup)
736  {
737  categoryCorrespondance_[aminoAcid1 + "->" + aminoAcid2] = categoryIndex;
738  categoryIndex++;
739  }
740  this->matrix_(i, j) = categoryCorrespondance_[aminoAcid1 + "->" + aminoAcid2];
741  if (AA2IsNotInGroup)
742  {
743  categoryCorrespondance_[aminoAcid2 + "->" + aminoAcid1] = categoryIndex;
744  categoryIndex++;
745  }
746  this->matrix_(j, i) = categoryCorrespondance_[aminoAcid2 + "->" + aminoAcid1];
747  }
748  }
749  }
750  }
751  updateTypes_();
752  }
753 
755 
757 
758  std::string getTypeName(size_t type) const
759  {
760  if (types_.find(type) != types_.end())
761  {
762  for (std::map<std::string, size_t>::const_iterator it = categoryCorrespondance_.begin(); it != categoryCorrespondance_.end(); it++)
763  {
764  if (it->second == type)
765  return TextTools::toString(it->first);
766  }
767  }
768  throw Exception("Bad type number " + TextTools::toString(type) + " in GeneralSubstitutionRegister::getTypeName.");
769  }
770 };
771 
782 {
783 public:
784  GCSubstitutionRegister(const NucleotideSubstitutionModel* model, bool within = false) :
785  CategorySubstitutionRegister(model, within)
786  {
787  std::map<int, int> categories;
788  categories[0] = 1;
789  categories[1] = 2;
790  categories[2] = 2;
791  categories[3] = 1;
792  setCategories<int>(categories);
793  }
794 
795  GCSubstitutionRegister* clone() const { return new GCSubstitutionRegister(*this); }
796 };
797 
808 {
809 public:
812  {}
813 
815 
816 public:
817  size_t getNumberOfSubstitutionTypes() const { return 2; }
818 
819  size_t getType(size_t fromState, size_t toState) const
820  {
821  int x = model_->getAlphabetStateAsInt(fromState);
822  int y = model_->getAlphabetStateAsInt(toState);
823  if (x == y)
824  return 0; // nothing happens
825  if ((x == 0 && y == 2)
826  || (x == 2 && y == 0)
827  || (x == 1 && y == 3)
828  || (x == 3 && y == 1))
829  return 1; // This is a transition
830  return 2; // This is a transversion
831  }
832 
833  std::string getTypeName(size_t type) const
834  {
835  if (type == 0)
836  {
837  return "no substitution";
838  }
839  else if (type == 1)
840  {
841  return "transition";
842  }
843  else if (type == 2)
844  {
845  return "transversion";
846  }
847  else
848  {
849  throw Exception("TsTvSubstitutionRegister::getTypeName. Bad substitution type.");
850  }
851  }
852 };
853 
864 {
865 private:
866  const GeneticCode* code_;
868 
869 public:
870  DnDsSubstitutionRegister(const CodonSubstitutionModel* model, bool countMultiple = false) :
872  code_(model->getGeneticCode()),
873  countMultiple_(countMultiple)
874  {}
875 
878  code_(reg.code_),
880  {}
881 
883  {
885  code_ = reg.code_;
887  return *this;
888  }
889 
891 
892 public:
893  size_t getNumberOfSubstitutionTypes() const { return 2; }
894 
895  size_t getType(size_t fromState, size_t toState) const
896  {
897  int x = model_->getAlphabetStateAsInt(fromState);
898  int y = model_->getAlphabetStateAsInt(toState);
899  const CodonAlphabet* cAlpha = dynamic_cast<const CodonAlphabet*>(model_->getAlphabet());
900  if (code_->isStop(x) || code_->isStop(y))
901  return 0;
902  if (x == y)
903  return 0; // nothing happens
904  if (!countMultiple_)
905  {
906  size_t countPos = 0;
907  if (cAlpha->getFirstPosition(x) != cAlpha->getFirstPosition(y))
908  countPos++;
909  if (cAlpha->getSecondPosition(x) != cAlpha->getSecondPosition(y))
910  countPos++;
911  if (cAlpha->getThirdPosition(x) != cAlpha->getThirdPosition(y))
912  countPos++;
913  if (countPos > 1)
914  return 0;
915  }
916  return code_->areSynonymous(x, y) ? 1 : 2;
917  }
918 
919  std::string getTypeName (size_t type) const
920  {
921  if (type == 0)
922  {
923  return "no substitution";
924  }
925  else if (type == 1)
926  {
927  return "synonymous";
928  }
929  else if (type == 2)
930  {
931  return "non synonymous";
932  }
933  else
934  {
935  throw Exception("DnDsSubstitutionRegister::getTypeName. Bad substitution type.");
936  }
937  }
938 };
939 
955 {
956 private:
957  const GeneticCode* code_;
958 
959 public:
960  GCSynonymousSubstitutionRegister(const CodonSubstitutionModel* model, bool within = false) :
961  CategorySubstitutionRegister(model, within),
962  code_(model->getGeneticCode())
963  {
964  const CodonAlphabet* pCA = dynamic_cast<const CodonAlphabet*>(code_->getSourceAlphabet());
965 
966  std::map<int, int> categories;
967  for (int i = 0; i < static_cast<int>(pCA->getSize()); i++)
968  {
969  int n = pCA->getThirdPosition(i);
970  switch (n)
971  {
972  case 0:
973  case 3:
974  categories[i] = 1;
975  break;
976  case 1:
977  case 2:
978  categories[i] = 2;
979  break;
980  }
981  }
982  setCategories<int>(categories);
983  }
984 
987  code_(reg.code_)
988  {}
989 
991  {
993  code_ = reg.code_;
994  return *this;
995  }
996 
998 
999 public:
1000  size_t getNumberOfSubstitutionTypes() const { return 2; }
1001 
1002  size_t getType(size_t fromState, size_t toState) const
1003  {
1004  int x = model_->getAlphabetStateAsInt(fromState);
1005  int y = model_->getAlphabetStateAsInt(toState);
1006  const CodonAlphabet* pCA = dynamic_cast<const CodonAlphabet*>(code_->getSourceAlphabet());
1007  if (code_->isStop(x) || code_->isStop( y) || !code_->areSynonymous(x, y))
1008  return 0;
1009 
1010  // only substitutions between 3rd positions
1011 
1012  if ((pCA->getFirstPosition(x) != pCA->getFirstPosition(y)) ||
1013  (pCA->getSecondPosition(x) != pCA->getSecondPosition(y)))
1014  return 0;
1015 
1016  size_t fromCat = categories_[x];
1017  size_t toCat = categories_[y];
1018 
1019  if (fromCat > 0 && toCat > 0)
1020  return index_[fromCat - 1][toCat - 1];
1021  else
1022  return 0;
1023  }
1024 
1025  std::string getTypeName (size_t type) const
1026  {
1027  if (type == 0)
1028  {
1029  return "no AT<->GC substitution or non-synonymous substitution";
1030  }
1031  else if (type == 1)
1032  {
1033  return "AT->GC synonymous";
1034  }
1035  else if (type == 2)
1036  {
1037  return "GC->AT synonymous";
1038  }
1039  else
1040  {
1041  throw Exception("GCSynonymousSubstitutionRegister::getTypeName. Bad substitution type.");
1042  }
1043  }
1044 };
1045 } // end of namespace bpp.
1046 
1047 #endif // _SUBSTITUTIONREGISTER_H_
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
CompleteSubstitutionRegister * clone() const
GCSynonymousSubstitutionRegister(const GCSynonymousSubstitutionRegister &reg)
Interface for all substitution models.
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
CompleteSubstitutionRegister & operator=(const CompleteSubstitutionRegister &csr)
virtual int getAlphabetStateAsInt(size_t index) const =0
GCSynonymousSubstitutionRegister & operator=(const GCSynonymousSubstitutionRegister &reg)
Completion of a given substitution register to consider all substitutions. The new substitutions are ...
std::map< size_t, std::map< size_t, std::vector< size_t > > > types_
The map from substitution types to the map of from states to the vector of target states...
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
virtual const std::vector< int > & getAlphabetStates() const =0
Distinguishes AT<->GC from GC<->AT.
virtual size_t getCategoryTo(size_t type) const
std::string getTypeName(size_t type) const
names of the types are their number.
virtual SubstitutionRegister * clone() const =0
AAExteriorSubstitutionRegister * clone() const
virtual const SubstitutionModel * getSubstitutionModel() const =0
The SubstitutionRegister interface.
size_t getType(size_t i, size_t j) const
Get the substitution type far a given pair of model states.
virtual const Alphabet * getAlphabet() const =0
GCSubstitutionRegister * clone() const
DnDsSubstitutionRegister(const DnDsSubstitutionRegister &reg)
virtual size_t getCategoryFrom(size_t type) const
GCSubstitutionRegister(const NucleotideSubstitutionModel *model, bool within=false)
const SubstitutionRegister * preg_
RowMatrix< size_t > matrix_
The matrix of the substitution register.
std::map< std::string, size_t > categoryCorrespondance_
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
Indexes only intra amino-acid substitutions. Every group represents a substitutions for the same amin...
Indexes only substitutions between amino-acids. Groups are distinguished by their direction...
AAInteriorSubstitutionRegister * clone() const
std::string getTypeName(size_t type) const
names of the types are their number.
Gather states into defined categories, and count the changes between categories.
TotalSubstitutionRegister(const SubstitutionModel *model)
AAInteriorSubstitutionRegister(const CodonSubstitutionModel *model)
TsTvSubstitutionRegister(const NucleotideSubstitutionModel *model)
GCSynonymousSubstitutionRegister(const CodonSubstitutionModel *model, bool within=false)
size_t size_
The size of the matrix, i.e. the number of states.
CompleteSubstitutionRegister(const SubstitutionRegister &reg)
Class inheriting from GeneralSubstitutionRegister, this one uses a special constructor which allows i...
ComprehensiveSubstitutionRegister(const SubstitutionModel *model, bool within=false)
TsTvSubstitutionRegister * clone() const
Distinguishes synonymous from non-synonymous substitutions.
virtual std::string getCategoryName(size_t category) const
DnDsSubstitutionRegister & operator=(const DnDsSubstitutionRegister &reg)
Sets a Register based on a matrix of integers. If M is the matrix, M[i,j] is the number of the substi...
Distinguishes transitions from transversions.
const SubstitutionModel * getSubstitutionModel() const
AbstractSubstitutionRegister(const SubstitutionModel *model)
virtual size_t getCategory(size_t state) const
ComprehensiveSubstitutionRegister * clone() const
virtual size_t getNumberOfSubstitutionTypes() const =0
SelectedSubstitutionRegister * clone() const
virtual size_t getType(size_t fromState, size_t toState) const =0
Get the substitution type far a given pair of model states.
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
CompleteSubstitutionRegister(const CompleteSubstitutionRegister &csr)
std::vector< std::vector< size_t > > revIndex_
DnDsSubstitutionRegister(const CodonSubstitutionModel *model, bool countMultiple=false)
AbstractSubstitutionRegister & operator=(const AbstractSubstitutionRegister &asr)
Specialisation interface for nucleotide substitution model.
std::map< std::string, size_t > categoryCorrespondance_
TotalSubstitutionRegister * clone() const
virtual std::string getTypeName(size_t type) const =0
Get the name of a given substitution type.
GeneralSubstitutionRegister & operator=(const GeneralSubstitutionRegister &gsr)
GCSynonymousSubstitutionRegister * clone() const
AAExteriorSubstitutionRegister(const CodonSubstitutionModel *model)
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
GeneralSubstitutionRegister * clone() const
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
DnDsSubstitutionRegister * clone() const
AbstractSubstitutionRegister(const AbstractSubstitutionRegister &asr)
Distinguishes all types of substitutions.
GeneralSubstitutionRegister(const SubstitutionModel *model, const RowMatrix< size_t > &matrix)
std::vector< std::string > categoryNames_
std::string getTypeName(size_t type) const
names of the types are their number.
GeneralSubstitutionRegister(const GeneralSubstitutionRegister &gsr)
std::vector< std::vector< size_t > > index_
Abstract class for codon models.
SelectedSubstitutionRegister(const SubstitutionModel *model, std::string selectedSubstitutions)
virtual const GeneticCode * getGeneticCode() const =0
const Alphabet * getAlphabet() const
Distinguishes AT->GC vs GC->AT inside synonymous substitutions on third codon position.
std::map< size_t, std::string > categoryNames_
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
std::string getTypeName(size_t type) const
names of the types are their number.
GeneralSubstitutionRegister(const SubstitutionModel *model)
CategorySubstitutionRegister(const SubstitutionModel *model, bool within=false)
Build a new substitution register with categories. This class is meant to be inherited.
virtual const Alphabet * getAlphabet() const =0
virtual size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
void setCategories(const std::map< int, T > &categories)