17 modelColl_(set.modelColl_),
18 mModelToSubPro_(set.mModelToSubPro_),
19 freqColl_(set.freqColl_),
20 mFreqToSubPro_(set.mFreqToSubPro_),
21 distColl_(set.distColl_),
22 mVConstDist_(set.mVConstDist_),
23 mDistToSubPro_(set.mDistToSubPro_),
24 treeColl_(set.treeColl_),
25 mTreeToSubPro_(set.mTreeToSubPro_),
77 if (parametrizableIndex < 1)
78 throw BadIntegerException(
"SubstitutionProcessCollection::addParametrizable: parametrizableIndex should be at least 1.", (
int)parametrizableIndex);
81 if (std::dynamic_pointer_cast<BranchModelInterface>(parametrizable))
83 modelColl_.addObject(std::dynamic_pointer_cast<BranchModelInterface>(parametrizable), parametrizableIndex);
84 pl =
modelColl_.getParametersForObject(parametrizableIndex);
86 else if (std::dynamic_pointer_cast<FrequencySetInterface>(parametrizable))
88 freqColl_.addObject(std::dynamic_pointer_cast<FrequencySetInterface>(parametrizable), parametrizableIndex);
89 pl =
freqColl_.getParametersForObject(parametrizableIndex);
91 else if (std::dynamic_pointer_cast<DiscreteDistributionInterface>(parametrizable))
93 distColl_.addObject(std::dynamic_pointer_cast<DiscreteDistributionInterface>(parametrizable), parametrizableIndex);
94 pl =
distColl_.getParametersForObject(parametrizableIndex);
96 else if (std::dynamic_pointer_cast<ParametrizablePhyloTree>(parametrizable))
98 treeColl_.addObject(std::dynamic_pointer_cast<ParametrizablePhyloTree>(parametrizable), parametrizableIndex);
99 pl =
treeColl_.getParametersForObject(parametrizableIndex);
103 throw Exception(
"Unknown parametrizable object in SubstitutionProcessCollection::addParametrizable.");
111 if (parametrizableIndex < 1)
112 throw BadIntegerException(
"SubstitutionProcessCollection::addParametrizable: parametrizableIndex should be at least 1.", (
int)parametrizableIndex);
116 if (std::dynamic_pointer_cast<BranchModelInterface>(parametrizable))
124 modelColl_.replaceObject(std::dynamic_pointer_cast<BranchModelInterface>(parametrizable), parametrizableIndex);
125 pl =
modelColl_.getParametersForObject(parametrizableIndex);
127 else if (std::dynamic_pointer_cast<FrequencySetInterface>(parametrizable))
135 freqColl_.replaceObject(std::dynamic_pointer_cast<FrequencySetInterface>(parametrizable), parametrizableIndex);
136 pl =
freqColl_.getParametersForObject(parametrizableIndex);
138 else if (std::dynamic_pointer_cast<DiscreteDistributionInterface>(parametrizable))
146 distColl_.replaceObject(std::dynamic_pointer_cast<DiscreteDistributionInterface>(parametrizable), parametrizableIndex);
147 pl =
distColl_.getParametersForObject(parametrizableIndex);
149 else if (std::dynamic_pointer_cast<ParametrizablePhyloTree>(parametrizable))
157 treeColl_.replaceObject(std::dynamic_pointer_cast<ParametrizablePhyloTree>(parametrizable), parametrizableIndex);
158 pl =
treeColl_.getParametersForObject(parametrizableIndex);
162 throw Exception(
"Unknown parametrizable object in SubstitutionProcessCollection::addParametrizable.");
195 map<size_t, bool> toFire;
199 const vector<size_t>& vD =
distColl_.hasChanged();
201 for (
size_t i = 0; i < vD.size(); i++)
204 for (
size_t j = 0; j < vs.size(); j++)
206 toFire[vs[j]] =
true;
214 for (
size_t j = 0; j < vv.size(); j++)
217 std::dynamic_pointer_cast<ConstantDistribution>(
distColl_[10000 * (vD[i] + 1) + vv[j]])->setParameterValue(
"value", dd->getCategory(j));
218 const vector<size_t>& vs2 =
mDistToSubPro_[10000 * (vD[i] + 1) + vv[j]];
219 for (
size_t k = 0; k < vs2.size(); k++)
221 toFire[vs2[k]] =
true;
231 const vector<size_t>& vT =
treeColl_.hasChanged();
233 for (
size_t i = 0; i < vT.size(); i++)
236 for (
size_t j = 0; j < vs.size(); j++)
238 toFire[vs[j]] =
true;
245 map<size_t, bool>::const_iterator it;
247 for (it = toFire.begin(); it != toFire.end(); it++)
259 it.second->setNamespace(prefix);
268 if (it.second->hasParameter(p2))
271 it.second->deleteParameter_(p);
281 it.second->updateParameters();
288 for (
auto& itp : unparsedParams)
290 string p2 = itp.second;
294 if (it.second->hasParameter(p2))
295 it.second->deleteParameter_(p2);
319 if (nTree != 0 && !
treeColl_.hasObject(nTree))
325 auto pSMS = shared_ptr<SubstitutionProcessCollectionMember>(
330 std::map<size_t, std::vector<unsigned int>>::iterator it;
331 for (it = mModBr.begin(); it != mModBr.end(); it++)
333 pSMS->addModel(it->first, it->second);
337 pSMS->isFullySetUp(nTree != 0);
386 sort(ids.begin(), ids.end());
389 size_t maxMod = *max_element(vModN.begin(), vModN.end());
391 std::map<size_t, std::vector<unsigned int>> mModBr;
392 mModBr[nMod] = vector<uint>(1, ids[0]);
394 for (
auto it = ids.begin() + 1; it != ids.end(); it++)
396 size_t mNb = maxMod + *it;
398 mModBr[mNb] = vector<uint>(1, *it);
408 vector<string> sharedParameterNames2;
413 for (i = 0; i < sharedParameterNames.size(); i++)
415 if (sharedParameterNames[i].find(
"*") != string::npos)
417 for (j = 0; j < sharedParameters.
size(); j++)
421 string parn = sharedParameters[j].getName();
431 pos2 = parn.find(g, pos1);
432 if (pos2 == string::npos)
437 pos1 = pos2 + g.length();
440 ((g.length() == 0) || (pos1 == parn.length()) || (parn.rfind(g) == parn.length() - g.length())))
441 sharedParameterNames2.push_back(parn);
444 else if (!sharedParameters.
hasParameter(sharedParameterNames[i]))
445 throw Exception(
"SubstitutionProcessCollection::addOnePerBranchSubstitutionProcess. Parameter '" + sharedParameterNames[i] +
"' is not valid.");
447 sharedParameterNames2.push_back(sharedParameterNames[i]);
454 for (
const auto& pname : sharedParameterNames2)
456 for (
auto it = mModBr.begin(); it != mModBr.end(); it++)
458 if (it != mModBr.begin())
void addParameters_(const ParameterList ¶meters)
void unaliasParameters(const std::string &p1, const std::string &p2)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
void aliasParameters(const std::string &p1, const std::string &p2)
ParameterList getAliasedParameters(const ParameterList &pl) const
void setNamespace(const std::string &prefix)
ParameterList getFromParameters(const ParameterList &pl) const
ParameterList & getParameters_() override
virtual std::vector< EdgeIndex > getAllEdgesIndexes() const=0
BranchModelInterface * clone() const =0
virtual const ParameterList & getIndependentParameters() const=0
virtual bool hasParameter(const std::string &name) const
virtual void addParameters(const ParameterList ¶ms)
virtual void addParameter(const Parameter ¶m)
virtual void includeParameters(const ParameterList ¶ms)
virtual void deleteParameters(const std::vector< std::string > &names, bool mustExist=true)
const std::string & nextToken()
bool hasMoreToken() const
void setRootFrequencies(size_t numFreq)
Set the root Frequencies Set.
SubstitutionProcessCollectionMember * clone() const override
Collection of Substitution Process, which owns all the necessary objects: Substitution models,...
ParametrizableCollection< DiscreteDistributionInterface > distColl_
void setNamespace(const std::string &prefix)
std::map< size_t, std::shared_ptr< SubstitutionProcessCollectionMember > > mSubProcess_
SubstitutionProcessCollection & operator=(const SubstitutionProcessCollection &set)
ParametrizableCollection< BranchModelInterface > modelColl_
std::vector< size_t > getModelNumbers() const
Get the numbers of the specified objects from the collections.
std::map< size_t, std::vector< size_t > > mDistToSubPro_
bool hasModelNumber(size_t n) const
std::map< size_t, std::vector< size_t > > mModelToSubPro_
ParameterList getNonDerivableParameters() const
Get the Non-derivable parameters.
void fireParameterChanged(const ParameterList ¶meters)
AbstractParameterAliasable functions, redirected towards the process members.
bool hasTreeNumber(size_t n) const
BranchModelInterface & model(size_t modelIndex)
Get a BranchModel from the collection.
void clear()
Resets all the information contained in this object.
SubstitutionProcessCollectionMember & substitutionProcess(size_t i)
std::shared_ptr< DiscreteDistributionInterface > getRateDistribution(size_t distributionIndex)
Get a DiscreteDistribution from the collection.
void replaceParametrizable(std::shared_ptr< Parametrizable > parametrizable, size_t parametrizableIndex, bool withParameters=true)
ParametrizableCollection< FrequencySetInterface > freqColl_
bool hasFrequenciesNumber(size_t n) const
void addOnePerBranchSubstitutionProcess(size_t nProc, size_t nMod, size_t nTree, size_t nRate, size_t nFreq, const std::vector< std::string > &sharedParameterNames)
void aliasParameters(const std::string &p1, const std::string &p2)
std::map< size_t, std::vector< size_t > > mTreeToSubPro_
void unaliasParameters(const std::string &p1, const std::string &p2)
std::shared_ptr< BranchModelInterface > getModel(size_t modelIndex)
SubstitutionProcessCollection()
Create empty collections.
ParametrizableCollection< ParametrizablePhyloTree > treeColl_
bool hasDistributionNumber(size_t n) const
void addModel(std::shared_ptr< BranchModelInterface > model, size_t modelIndex)
specific methods to add specific objects.
void addParametrizable(std::shared_ptr< Parametrizable > parametrizable, size_t parametrizableIndex, bool withParameters=true)
Add a new parametrizable to the matching collection with a given number.
void addSubstitutionProcess(size_t nProc, std::map< size_t, std::vector< unsigned int >> mModBr, size_t nTree, size_t nRate, size_t nFreq)
ParameterList getSubstitutionProcessParameters() const
std::map< size_t, std::vector< size_t > > mVConstDist_
std::shared_ptr< ParametrizablePhyloTree > getTree(size_t treeIndex)
std::map< size_t, std::vector< size_t > > mFreqToSubPro_
ParametrizablePhyloTree & tree(size_t treeIndex)
Get a tree from the set.
std::string toString(T t)
Defines the basic types of data flow nodes.