5 #include "../../Model/MixedTransitionModel.h"
14 shared_ptr<TransitionModelInterface> model,
15 shared_ptr<FrequencySetInterface> rootFreqs,
20 if (model->getAlphabet()->getAlphabetType() != rootFreqs->getAlphabet()->getAlphabetType())
21 throw AlphabetMismatchException(
"SubstitutionModelSetTools::createHomogeneousModelSet()", model->getAlphabet(), rootFreqs->getAlphabet());
23 throw Exception(
"createHomogeneousModelSet non yet programmed for mixture models.");
25 auto modelSet = make_unique<SubstitutionModelSet>(model->getAlphabet());
27 modelSet->setRootFrequencies(rootFreqs);
32 for (
unsigned int i = 0; i < ids.size(); ++i)
40 ids.erase(ids.begin() + pos);
41 modelSet->addModel(model, ids);
47 shared_ptr<TransitionModelInterface> model,
48 shared_ptr<FrequencySetInterface> rootFreqs,
50 const map<string, string>& aliasFreqNames,
51 const map<
string, vector<Vint>>& globalParameterNames
55 if (rootFreqs && model->alphabet().getAlphabetType() != rootFreqs->alphabet().getAlphabetType())
56 throw AlphabetMismatchException(
"SubstitutionModelSetTools::createNonHomogeneousModelSet()", model->getAlphabet(), rootFreqs->getAlphabet());
58 globalParameters = model->getParameters();
62 map<string, vector<Vint>> globalParameterNames2;
66 for (
const auto& name : globalParameterNames)
70 if (complName.size() == 0)
71 throw Exception(
"SubstitutionModelSetTools::createNonHomogeneousModelSet. Parameter '" + name.first +
"' is not valid.");
73 for (
auto& cni : complName)
75 globalParameterNames2[cni] = name.second;
79 auto modelSet = make_unique<SubstitutionModelSet>(model->getAlphabet());
82 modelSet->setRootFrequencies(rootFreqs);
88 for (
size_t i = 0; i < ids.size(); ++i)
97 ids.erase(ids.begin() +
static_cast<ptrdiff_t
>(pos));
98 for (
size_t i = 0; i < ids.size(); ++i)
100 modelSet->addModel(shared_ptr<TransitionModelInterface>(model->clone()), vector<int>(1, ids[i]));
104 for (
size_t nn = 0; nn < globalParameters.
size(); ++nn)
106 const Parameter& param = globalParameters[nn];
108 string pname = param.
getName();
110 if (globalParameterNames2.find(pname) != globalParameterNames2.end())
112 const vector<Vint>& vvids(globalParameterNames2[pname]);
114 if (vvids.size() == 0)
116 size_t fmid = modelSet->getModelIndexForNode(ids[0]) + 1;
117 for (
size_t i = 1; i < ids.size(); ++i)
123 for (
const auto& vids : vvids)
125 size_t fmid = modelSet->getModelIndexForNode(vids[0] + 1);
126 for (
size_t i = 1; i < vids.size(); i++)
135 for (
auto& it : aliasFreqNames)
137 if (globalParameterNames2.find(it.second) != globalParameterNames2.end())
138 modelSet->aliasParameters(it.second +
"_1", it.first);
Interface for Transition models, defined as a mixture of "simple" transition models.
virtual std::vector< std::string > getParameterNames() const
virtual const std::string & getName() const
Interface for phylogenetic tree objects.
virtual std::vector< int > getNodesId() const =0
virtual int getRootId() const =0
std::string toString(T t)
Defines the basic types of data flow nodes.