5 #ifndef BPP_PHYL_MAPPING_SUBSTITUTIONREGISTER_H
6 #define BPP_PHYL_MAPPING_SUBSTITUTIONREGISTER_H
9 #include "../Model/StateMap.h"
56 virtual std::shared_ptr<const Alphabet>
getAlphabet()
const = 0;
66 virtual std::shared_ptr<const StateMapInterface>
getStateMap()
const = 0;
79 virtual const std::string&
getName()
const = 0;
89 virtual size_t getType(
size_t fromState,
size_t toState)
const = 0;
163 size_t getType(
size_t fromState,
size_t toState)
const override
165 return fromState == toState ? 0 : 1;
176 return "substitution";
180 throw Exception(
"TotalSubstitutionRegister::getTypeName. Bad substitution type.");
195 std::shared_ptr<const SubstitutionRegisterInterface>
preg_;
205 size_t size = reg->alphabet().getSize();
206 for (
size_t i = 0; i < size; ++i)
208 for (
size_t j = 0; j < size; ++j)
210 if ((i != j) && reg->getType(i, j) == 0)
243 size_t getType(
size_t fromState,
size_t toState)
const override
245 if (fromState == toState)
248 size_t t =
preg_->getType(fromState, toState);
259 return preg_->getTypeName(type);
264 return "Completion_substitution";
266 throw Exception(
"CompleteSubstitutionRegister::getTypeName. Bad substitution type.");
287 std::vector< std::shared_ptr<SubstitutionRegisterInterface>>
vSubReg_;
307 void addRegister(std::shared_ptr<SubstitutionRegisterInterface> reg)
312 throw Exception(
"VectorOfSubstitutionRegisters::addRegister : mismatch between state maps");
318 size_t getType(
size_t i,
size_t j)
const override
325 for (
size_t p = 0; p <
vSubReg_.size(); ++p)
327 x *=
vSubReg_[p]->getNumberOfSubstitutionTypes();
328 size_t z =
vSubReg_[p]->getType(i, j);
344 for (
size_t i = 0; i <
vSubReg_.size(); ++i)
346 n *=
vSubReg_[i]->getNumberOfSubstitutionTypes();
361 std::string res =
"";
362 size_t ty = type - 1;
364 for (
size_t p =
vSubReg_.size(); p > 0; p--)
370 ty /=
vSubReg_[p - 1]->getNumberOfSubstitutionTypes();
405 std::map<size_t, std::map<size_t, std::vector<size_t>>>
types_;
451 size_t getType(
size_t i,
size_t j)
const override
494 selectedSubstitutions.erase(std::remove(selectedSubstitutions.begin(), selectedSubstitutions.end(),
' '), selectedSubstitutions.end());
509 std::string codon1 =
"";
510 std::string codon2 =
"";
532 this->
matrix_(coord1, coord2) = typeSubs;
566 std::shared_ptr<const StateMapInterface>
stateMap,
567 std::shared_ptr<const GeneticCode> genCode) :
602 if (it->second == type)
612 size_t categoryIndex = 1;
623 std::string aminoAcid =
genCode_->getTargetAlphabet()->intToChar(
genCode_->translate(state1));
652 std::shared_ptr<const StateMapInterface>
stateMap,
653 std::shared_ptr<const GeneticCode> genCode) :
687 if (it->second == type)
697 size_t categoryIndex = 1;
708 std::string aminoAcid1 =
genCode_->getTargetAlphabet()->intToChar(
genCode_->translate(state1));
709 std::string aminoAcid2 =
genCode_->getTargetAlphabet()->intToChar(
genCode_->translate(state2));
777 size_t getType(
size_t fromState,
size_t toState)
const
787 auto cAlpha =
genCode_->getCodonAlphabet();
795 if (cAlpha->getFirstPosition(x) != cAlpha->getFirstPosition(y))
797 if (cAlpha->getSecondPosition(x) != cAlpha->getSecondPosition(y))
799 if (cAlpha->getThirdPosition(x) != cAlpha->getThirdPosition(y))
834 throw Exception(
"TsTvSubstitutionRegister::getTypeName. Bad substitution type.");
866 std::shared_ptr<const StateMapInterface>
stateMap,
867 std::shared_ptr<const GeneticCode> genCode) :
889 size_t getType(
size_t fromState,
size_t toState)
const
899 auto cAlpha =
genCode_->getCodonAlphabet();
906 nd = cAlpha->getFirstPosition(x);
907 na = cAlpha->getFirstPosition(y);
910 if (cAlpha->getSecondPosition(x) != cAlpha->getSecondPosition(y)
911 || (cAlpha->getThirdPosition(x) != cAlpha->getThirdPosition(y)))
916 nd = cAlpha->getSecondPosition(x);
917 na = cAlpha->getSecondPosition(y);
920 if (cAlpha->getThirdPosition(x) != cAlpha->getThirdPosition(y))
925 nd = cAlpha->getThirdPosition(x);
926 na = cAlpha->getThirdPosition(y);
939 return (na == 3) ? 4 : 3;
941 return (na == 2) ? 1 : 2;
943 return (na == 1) ? 1 : 2;
945 return (na == 0) ? 4 : 3;
966 throw Exception(
"SWSubstitutionRegister::getTypeName. Bad substitution type.");
989 std::shared_ptr<const StateMapInterface>
stateMap,
990 std::shared_ptr<const GeneticCode> genCode,
991 bool countMultiple =
false) :
1016 size_t getType(
size_t fromState,
size_t toState)
const
1021 auto cAlpha =
genCode_->getCodonAlphabet();
1022 if (cAlpha->isGap(x)
1031 size_t countPos = 0;
1032 if (cAlpha->getFirstPosition(x) != cAlpha->getFirstPosition(y))
1034 if (cAlpha->getSecondPosition(x) != cAlpha->getSecondPosition(y))
1036 if (cAlpha->getThirdPosition(x) != cAlpha->getThirdPosition(y))
1041 return genCode_->areSynonymous(x, y) ? 1 : 2;
1060 throw Exception(
"DnDsSubstitutionRegister::getTypeName. Bad substitution type.");
1093 std::shared_ptr<const StateMapInterface>
stateMap,
1094 std::shared_ptr<const GeneticCode> genCode) :
1119 for (
size_t i = 0; i < 20; ++i)
1122 for (
size_t j = 0; j < 20; ++j)
1224 size_t getType(
size_t fromState,
size_t toState)
const
1226 if (fromState == toState)
1233 if (
genCode_->getSourceAlphabet()->isGap(x)
1234 ||
genCode_->getSourceAlphabet()->isGap(y)
1242 auto cAlpha =
genCode_->getCodonAlphabet();
1244 size_t countPos = 0;
1245 if (cAlpha->getFirstPosition(x) != cAlpha->getFirstPosition(y))
1247 if (cAlpha->getSecondPosition(x) != cAlpha->getSecondPosition(y))
1249 if (cAlpha->getThirdPosition(x) != cAlpha->getThirdPosition(y))
1258 return types_[
static_cast<size_t>(x)][
static_cast<size_t>(y)] ? 1 : 2;
1277 throw Exception(
"KrKcSubstitutionRegister::getTypeName. Bad substitution type.");
Indexes only substitutions between amino-acids. Groups are distinguished by their direction.
AAExteriorSubstitutionRegister * clone() const
std::shared_ptr< const GeneticCode > genCode_
std::string getTypeName(size_t type) const
names of the types are their number.
AAExteriorSubstitutionRegister(const AAExteriorSubstitutionRegister &ais)
AAExteriorSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode)
~AAExteriorSubstitutionRegister()
AAExteriorSubstitutionRegister & operator=(const AAExteriorSubstitutionRegister &ais)
std::map< std::string, size_t > categoryCorrespondance_
Indexes only intra amino-acid substitutions. Every group represents a substitutions for the same amin...
AAInteriorSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode)
AAInteriorSubstitutionRegister & operator=(const AAInteriorSubstitutionRegister &ais)
AAInteriorSubstitutionRegister * clone() const
AAInteriorSubstitutionRegister(const AAInteriorSubstitutionRegister &ais)
std::map< std::string, size_t > categoryCorrespondance_
std::string getTypeName(size_t type) const
names of the types are their number.
~AAInteriorSubstitutionRegister()
std::shared_ptr< const GeneticCode > genCode_
virtual ~AbstractSubstitutionRegister()
AbstractSubstitutionRegister(const AbstractSubstitutionRegister &asr)
std::shared_ptr< const Alphabet > getAlphabet() const override
AbstractSubstitutionRegister & operator=(const AbstractSubstitutionRegister &asr)
const std::string & getName() const override
Get the name of the register.
AbstractSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, const std::string &name)
const StateMapInterface & stateMap() const override
const Alphabet & alphabet() const override
std::shared_ptr< const StateMapInterface > getStateMap() const override
std::shared_ptr< const StateMapInterface > stateMap_
virtual size_t getStateIndex(int state) const=0
virtual const AlphabetState & getStateAt(size_t stateIndex) const=0
Completion of a given substitution register to consider all substitutions. The new substitutions are ...
size_t getType(size_t fromState, size_t toState) const override
Get the substitution type far a given pair of model states.
std::shared_ptr< const SubstitutionRegisterInterface > preg_
CompleteSubstitutionRegister(const CompleteSubstitutionRegister &csr)
virtual ~CompleteSubstitutionRegister()
std::string getTypeName(size_t type) const override
Get the name of a given substitution type.
CompleteSubstitutionRegister & operator=(const CompleteSubstitutionRegister &csr)
size_t getNumberOfSubstitutionTypes() const override
CompleteSubstitutionRegister * clone() const override
CompleteSubstitutionRegister(std::shared_ptr< const SubstitutionRegisterInterface > reg)
Distinguishes synonymous from non-synonymous substitutions.
DnDsSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode, bool countMultiple=false)
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
DnDsSubstitutionRegister & operator=(const DnDsSubstitutionRegister ®)
size_t getNumberOfSubstitutionTypes() const
DnDsSubstitutionRegister * clone() const
std::shared_ptr< const GeneticCode > genCode_
DnDsSubstitutionRegister(const DnDsSubstitutionRegister ®)
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
Sets a Register based on a matrix of integers. If M is the matrix, M[i,j] is the number of the substi...
GeneralSubstitutionRegister(const GeneralSubstitutionRegister &gsr)
virtual ~GeneralSubstitutionRegister()
std::string getTypeName(size_t type) const override
names of the types are their number.
GeneralSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap)
GeneralSubstitutionRegister & operator=(const GeneralSubstitutionRegister &gsr)
size_t size_
The size of the matrix, i.e. the number of states.
RowMatrix< size_t > matrix_
The matrix of the substitution register.
size_t getType(size_t i, size_t j) const override
Get the substitution type far a given pair of model states.
GeneralSubstitutionRegister * clone() const override
GeneralSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, const RowMatrix< size_t > &matrix)
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 getNumberOfSubstitutionTypes() const override
Count conservative and radical amino-acid substitutions.
KrKcSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap)
KrKcSubstitutionRegister(const KrKcSubstitutionRegister &kreg)
std::shared_ptr< const GeneticCode > genCode_
KrKcSubstitutionRegister * clone() const
KrKcSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode)
size_t getNumberOfSubstitutionTypes() const
KrKcSubstitutionRegister & operator=(const KrKcSubstitutionRegister &kreg)
std::vector< std::vector< bool > > types_
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.
size_t getNumberOfRows() const
size_t getNumberOfColumns() const
Distinguishes substitutions given the link between the changed nucleotides : S for strong (GC) and W ...
size_t getNumberOfSubstitutionTypes() const
std::shared_ptr< const GeneticCode > genCode_
useful for codon alphabet
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
SWSubstitutionRegister & operator=(const SWSubstitutionRegister ®)
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
SWSubstitutionRegister(const SWSubstitutionRegister ®)
SWSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode)
SWSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap)
SWSubstitutionRegister * clone() const
Class inheriting from GeneralSubstitutionRegister, this one uses a special constructor which allows i...
SelectedSubstitutionRegister * clone() const
std::map< size_t, std::string > categoryNames_
~SelectedSubstitutionRegister()
std::string getTypeName(size_t type) const
names of the types are their number.
SelectedSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::string selectedSubstitutions)
Map the states of a given alphabet which have a model state.
virtual const Alphabet & alphabet() const =0
virtual size_t getNumberOfModelStates() const =0
virtual int getAlphabetStateAsInt(size_t index) const =0
size_t numberOfRemainingTokens() const
const std::string & nextToken()
bool hasMoreToken() const
The SubstitutionRegister interface.
virtual std::string getTypeName(size_t type) const =0
Get the name of a given substitution type.
virtual const StateMapInterface & stateMap() const =0
SubstitutionRegisterInterface()
virtual size_t getNumberOfSubstitutionTypes() const =0
virtual size_t getType(size_t fromState, size_t toState) const =0
Get the substitution type far a given pair of model states.
virtual std::shared_ptr< const StateMapInterface > getStateMap() const =0
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
virtual const std::string & getName() const =0
Get the name of the register.
virtual const Alphabet & alphabet() const =0
virtual SubstitutionRegisterInterface * clone() const =0
virtual ~SubstitutionRegisterInterface()
std::string getTypeName(size_t type) const override
Get the name of a given substitution type.
size_t getType(size_t fromState, size_t toState) const override
Get the substitution type far a given pair of model states.
size_t getNumberOfSubstitutionTypes() const override
TotalSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap)
TotalSubstitutionRegister * clone() const override
Distinguishes transitions from transversions.
TsTvSubstitutionRegister(const TsTvSubstitutionRegister ®)
size_t getType(size_t fromState, size_t toState) const
Get the substitution type far a given pair of model states.
TsTvSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap, std::shared_ptr< const GeneticCode > genCode)
TsTvSubstitutionRegister & operator=(const TsTvSubstitutionRegister ®)
std::string getTypeName(size_t type) const
Get the name of a given substitution type.
std::shared_ptr< const GeneticCode > genCode_
useful for codon alphabet
size_t getNumberOfSubstitutionTypes() const
TsTvSubstitutionRegister(std::shared_ptr< const StateMapInterface > stateMap)
TsTvSubstitutionRegister * clone() const
Sets a Register based on a vector of Registers. The categories are intersection of categories of thos...
std::vector< std::shared_ptr< SubstitutionRegisterInterface > > vSubReg_
the vector of pointers to SubstitutionRegisters.
VectorOfSubstitutionRegisters(const VectorOfSubstitutionRegisters &vosr)
size_t getNumberOfSubstitutionTypes() const override
VectorOfSubstitutionRegisters(std::shared_ptr< const StateMapInterface > stateMap)
std::string getTypeName(size_t type) const override
names of the types are the list of their types in the registers (separated with _).
virtual ~VectorOfSubstitutionRegisters()
VectorOfSubstitutionRegisters * clone() const override
size_t getType(size_t i, size_t j) const override
Get the substitution type far a given pair of model states.
void addRegister(std::shared_ptr< SubstitutionRegisterInterface > reg)
std::string toString(T t)
Defines the basic types of data flow nodes.
ExtendedFloat abs(const ExtendedFloat &ef)