3 #ifndef GEESE_MEAT_CONSTRUCTORS_HPP
4 #define GEESE_MEAT_CONSTRUCTORS_HPP 1
9 this->rengine =
new std::mt19937;
15 this->model->store_psets();
21 std::vector< std::vector<size_t> > & annotations,
22 std::vector< size_t > & geneid,
23 std::vector< int > & parent,
24 std::vector< bool > & duplication
28 this->rengine =
new std::mt19937;
34 this->model->store_psets();
37 if (annotations.size() == 0u)
38 throw std::logic_error(
"Annotations is empty");
43 for (
auto& iter : annotations)
47 throw std::length_error(
48 "Not all the annotations have the same length"
54 for (
size_t i = 0u;
i < geneid.size(); ++
i)
58 std::vector< size_t > & funs(annotations.at(
i));
61 if ((parent.at(
i) >= 0) && (
nodes.find(parent.at(
i)) ==
nodes.end()))
65 auto key_par =
nodes.insert({
67 Node(parent.at(
i), std::numeric_limits< size_t >::max(),
true)
74 auto key_off =
nodes.insert({
76 Node(geneid.at(
i),
i, funs, duplication.at(
i))
80 key_par.first->second.offspring.push_back(
81 &key_off.first->second
85 key_off.first->second.parent = &key_par.first->second;
90 nodes[geneid.at(
i)].duplication = duplication.at(
i);
91 nodes[geneid.at(
i)].annotations = funs;
94 nodes[geneid.at(
i)].id = geneid.at(
i);
96 nodes[parent.at(
i)].offspring.push_back(
109 auto key_off =
nodes.insert({
111 Node(geneid.at(
i),
i, funs, duplication.at(
i))
115 if (parent.at(
i) >= 0)
118 nodes[parent.at(
i)].offspring.push_back(
119 &key_off.first->second
123 key_off.first->second.parent = &
nodes[parent.at(
i)];
130 nodes[geneid.at(
i)].duplication = duplication.at(
i);
131 nodes[geneid.at(
i)].annotations = funs;
133 nodes[geneid.at(
i)].id = geneid.at(
i);
135 if (parent.at(
i) >= 0)
139 nodes[parent.at(
i)].offspring.push_back(
152 std::vector< size_t > ord_count(geneid.size(), 0u);
153 for (
auto& n :
nodes)
156 Node & node = n.second;
159 if (node.
ord == std::numeric_limits< size_t >::max())
162 std::string msg =
"Node id " +
163 std::to_string(node.
id) +
164 " does not have an ord.";
166 throw std::logic_error(msg);
174 std::string msg =
"Node id " +
175 std::to_string(node.
id) +
176 "'s duplication was not properly recorded.";
178 throw std::logic_error(msg);
199 this->n_dupl_events++;
201 this->n_spec_events++;
205 if (++ord_count[node.
ord] > 1u)
208 std::string msg =
"Node id " +
209 std::to_string(node.
id) +
210 "'s ord was repeated.";
211 throw std::logic_error(msg);
224 throw std::logic_error(
"The pruning sequence's length is different from nnodes(). This should not happen! (contact the developers).");
231 states(model_.states),
232 n_zeros(model_.n_zeros),
233 n_ones(model_.n_ones),
234 n_dupl_events(model_.n_dupl_events),
235 n_spec_events(model_.n_spec_events),
236 nfunctions(model_.nfunctions),
238 map_to_state_id(model_.map_to_state_id),
239 pset_loc(model_.pset_loc),
240 sequence(model_.sequence),
241 reduced_sequence(model_.reduced_sequence),
242 initialized(model_.initialized) {
249 if (model_.rengine !=
nullptr)
251 rengine =
new std::mt19937(*(model_.rengine));
255 if (model_.model !=
nullptr)
263 if (model_.rengine !=
nullptr)
265 rengine = model_.rengine;
269 if (model_.model !=
nullptr)
271 model = model_.model;
283 std::reverse(revseq.begin(), revseq.end());
285 for (
auto&
i : revseq)
289 if (this->
nodes[
i].is_leaf())
293 this->
nodes[
i].offspring.clear();
297 auto n = model_.
nodes.find(
i);
299 for (
const auto& off : n->second.offspring)
300 this->
nodes[
i].offspring.push_back(&this->
nodes[off->id]);
312 states(std::move(x.states)),
313 n_zeros(std::move(x.n_zeros)),
314 n_ones(std::move(x.n_ones)),
315 n_dupl_events(std::move(x.n_dupl_events)),
316 n_spec_events(std::move(x.n_spec_events)),
317 nfunctions(x.nfunctions),
318 nodes(std::move(x.nodes)),
319 map_to_state_id(std::move(x.map_to_state_id)),
320 pset_loc(std::move(x.pset_loc)),
321 sequence(std::move(x.sequence)),
322 reduced_sequence(std::move(x.reduced_sequence)),
323 initialized(x.initialized)
326 if (x.delete_rengine)
329 rengine =
new std::mt19937(*x.rengine);
330 delete_rengine =
true;
335 delete_rengine =
false;
339 if (x.delete_support)
343 delete_support =
true;
348 delete_support =
false;
353 if ((model !=
nullptr) && (x.delete_support | x.delete_rengine))
354 model->set_rengine(rengine,
false);
std::vector< size_t > sequence
void calc_reduced_sequence()
void calc_sequence(Node *n=nullptr)
std::map< size_t, Node > nodes
A single node for the model.
std::vector< size_t > annotations
Observed annotations (only defined for Geese)
size_t id
Id of the node (as specified in the input)
size_t ord
Order in which the node was created.
bool is_leaf() const noexcept
Data_Type &&counter_ noexcept
std::vector< double > keygen_full(const PhyloArray &array, const PhyloCounterData *d)
barry::Model< PhyloArray, PhyloCounterData, PhyloRuleData, PhyloRuleDynData > PhyloModel