5 #ifndef BPP_PHYL_MAPPING_CATEGORYSUBSTITUTIONREGISTER_H
6 #define BPP_PHYL_MAPPING_CATEGORYSUBSTITUTIONREGISTER_H
33 std::vector< std::vector<size_t>>
index_;
61 std::map<size_t, T> modelCategories;
62 for (
typename std::map<int, T>::const_iterator it = categories.begin(); it != categories.end(); ++it)
65 for (
auto st : states)
67 modelCategories[st] = it->second;
71 setModelCategories<T>(modelCategories);
79 std::map<T, size_t> cats;
80 for (
auto it = categories.begin(); it != categories.end(); ++it)
82 if (cats.find(it->second) == cats.end())
94 auto it = categories.find(i);
95 if (it != categories.end())
108 for (
size_t i = 0; i <
index_.size(); ++i)
111 for (
size_t j = 0; j <
index_.size(); ++j)
116 std::vector<size_t> pos(2);
125 for (
size_t i = 0; i <
index_.size(); ++i)
128 std::vector<size_t> pos(2);
153 throw Exception(
"CategorySubstitutionRegister::getCategoryFrom. Bad substitution type.");
168 throw Exception(
"CategorySubstitutionRegister::getCategoryTo. Bad substitution type.");
193 virtual size_t getType(
size_t fromState,
size_t toState)
const
197 if (fromCat > 0 && toCat > 0)
198 return index_[fromCat - 1][toCat - 1];
224 std::map<int, int> categories;
229 setAlphabetCategories<int>(categories);
250 std::map<int, int> categories;
255 setAlphabetCategories<int>(categories);
286 auto pCA =
genCode_->getCodonAlphabet();
288 std::map<int, int> categories;
289 for (
int i = 0; i < static_cast<int>(pCA->getSize()); i++)
291 int n = pCA->getThirdPosition(i);
304 setAlphabetCategories<int>(categories);
322 size_t getType(
size_t fromState,
size_t toState)
const
327 auto pCA =
genCode_->getCodonAlphabet();
334 if ((pCA->getFirstPosition(x) != pCA->getFirstPosition(y)) ||
335 (pCA->getSecondPosition(x) != pCA->getSecondPosition(y)))
341 if (fromCat > 0 && toCat > 0)
342 return index_[fromCat - 1][toCat - 1];
352 return "no AT<->GC substitution or non-synonymous substitution";
354 return "AT->GC synonymous";
356 return "GC->AT synonymous";
358 return "AT->AT synonymous";
360 return "GC->GC synonymous";
362 throw Exception(
"GCSynonymousSubstitutionRegister::getTypeName. Bad substitution type.");
387 std::shared_ptr<const StateMapInterface>
stateMap,
388 std::shared_ptr<const GeneticCode> genCode,
390 bool within =
false) :
395 auto pCA =
genCode_->getCodonAlphabet();
397 std::map<int, int> categories;
398 for (
int i = 0; i < static_cast<int>(pCA->getSize()); i++)
400 int n = pCA->getNPosition(i,
pos_);
413 setAlphabetCategories<int>(categories);
433 size_t getType(
size_t fromState,
size_t toState)
const
438 auto pCA =
genCode_->getCodonAlphabet();
445 for (
size_t pos = 0; pos < 3; pos++)
448 if (pCA->getNPosition(x, pos) != pCA->getNPosition(y, pos))
455 if (fromCat > 0 && toCat > 0)
456 return index_[fromCat - 1][toCat - 1];
468 return "no AT" + p +
"<->GC" + p +
" substitution";
470 return "AT" + p +
"->GC" + p;
472 return "GC" + p +
"->AT" + p;
474 return "AT" + p +
"->AT" + p;
476 return "GC" + p +
"->GC" + p;
478 throw Exception(
"GCPositionSubstitutionRegister::getTypeName. Bad substitution type.");
AbstractSubstitutionRegister & operator=(const AbstractSubstitutionRegister &asr)
const StateMapInterface & stateMap() const override
The CategorySubstitutionRegisters.
void setAlphabetCategories(const std::map< int, T > &categories)
virtual size_t getCategoryFrom(size_t type) const
size_t getNumberOfSubstitutionTypes() const
virtual size_t getCategoryTo(size_t type) const
virtual std::string getCategoryName(size_t category) const
std::vector< std::vector< size_t > > revIndex_
virtual size_t getCategory(size_t state) const
virtual bool allowWithin() const
std::vector< std::vector< size_t > > index_
std::vector< std::string > categoryNames_
std::map< size_t, size_t > categories_
void setModelCategories(const std::map< size_t, T > &categories)
void setStationarity(bool stat)
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
CategorySubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, bool within=false)
Build a new substitution register with categories. This class is meant to be inherited.
bool isStationary() const
size_t getNumberOfCategories() const
virtual size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
Distinguishes all types of substitutions.
ComprehensiveSubstitutionRegister * clone() const
ComprehensiveSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, bool within=false)
Distinguishes AT->GC vs GC->AT on given codon position (0, 1, or 2)
GCPositionSubstitutionRegister & operator=(const GCPositionSubstitutionRegister ®)
GCPositionSubstitutionRegister * 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.
GCPositionSubstitutionRegister(const GCPositionSubstitutionRegister ®)
std::shared_ptr< const GeneticCode > genCode_
GCPositionSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode, size_t pos, bool within=false)
Distinguishes AT<->GC from GC<->AT.
GCSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, bool within=false)
GCSubstitutionRegister * clone() const
Distinguishes AT->GC vs GC->AT inside synonymous substitutions on third codon position.
GCSynonymousSubstitutionRegister(const GCSynonymousSubstitutionRegister ®)
GCSynonymousSubstitutionRegister * clone() const
std::shared_ptr< const GeneticCode > genCode_
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
GCSynonymousSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode, bool within=false)
GCSynonymousSubstitutionRegister & operator=(const GCSynonymousSubstitutionRegister ®)
virtual size_t getNumberOfModelStates() const =0
virtual std::string getStateDescription(size_t index) const =0
virtual std::vector< size_t > getModelStates(const std::string &code) const =0
virtual int getAlphabetStateAsInt(size_t index) const =0
std::string toString(T t)
std::size_t count(const std::string &s, const std::string &pattern)
Defines the basic types of data flow nodes.