36 auto phyloT = std::make_shared<PhyloTree>(
true);
39 auto rooti = std::make_shared<PhyloNode>(root.
hasName() ? root.
getName() :
"");
40 phyloT->createNode(rooti);
41 phyloT->setRoot(rooti);
42 phyloT->setNodeIndex(rooti, (uint)root.
getId());
45 for (
const auto& prop:propi)
50 phyloT->addSubTree(rooti, root);
60 for (
size_t i = 0; i < edges.size(); i++)
63 if (edges[i]->hasLength())
64 dist = edges[i]->getLength();
68 double c = getHeight(tree, get<1>(tree.
getNodes(edges[i]))) + dist;
79 vector<shared_ptr<PhyloNode>> sons = tree.
getSons(node);
80 vector<size_t> h(sons.size());
81 for (
size_t i = 0; i < sons.size(); i++)
83 h[i] = initBranchLengthsGrafen(tree, sons[i]);
85 size_t thish = sons.size() == 0 ? 0 : VectorTools::sum<size_t>(h) + sons.size() - 1;
86 for (
size_t i = 0; i < sons.size(); i++)
96 initBranchLengthsGrafen(tree, tree.
getRoot());
101 std::shared_ptr<PhyloNode> node,
105 double& heightRaised)
107 vector<shared_ptr<PhyloNode>> sons = tree.
getSons(node);
108 vector<double> hr(sons.size());
110 for (
size_t i = 0; i < sons.size(); i++)
114 if (branch->hasLength())
117 computeBranchLengthsGrafen(tree, sons[i], power, total, h, hr[i]);
118 double d = h + branch->getLength();
123 throw PhyloBranchPException (
"PhyloTreeTools::computeBranchLengthsGrafen. Branch length lacking.", branch.get());
125 heightRaised =
std::pow(height / total, power) * total;
126 for (
size_t i = 0; i < sons.size(); i++)
135 shared_ptr<PhyloNode> root = tree.
getRoot();
138 initBranchLengthsGrafen(tree);
141 double totalHeight = getHeight(tree, root);
143 computeBranchLengthsGrafen(tree, root, power, totalHeight, h, hr);
148 vector<shared_ptr<PhyloNode>> sons = tree.
getSons(node);
150 vector<double> h(sons.size());
154 for (
size_t i = 0; i < sons.size(); i++)
158 if (branch->hasLength())
160 h[i] = convertToClockTree(tree, sons[i]);
163 l += h[i] + branch->getLength();
166 throw PhyloBranchPException (
"PhyloTreeTools::convertToClockTree. Branch length lacking.", branch.get());
169 l /= (double)sons.size();
172 for (
size_t i = 0; i < sons.size(); i++)
182 vector<shared_ptr<PhyloNode>> sons = tree.
getSons(node);
183 vector<double> h(sons.size());
187 for (
size_t i = 0; i < sons.size(); i++)
191 if (branch->hasLength())
193 h[i] = convertToClockTree2(tree, sons[i]);
196 l += h[i] + branch->getLength();
199 throw PhyloBranchPException(
"PhyloTreeTools::convertToClockTree2. Branch length lacking.", branch.get());
202 l /= (double)sons.size();
203 for (
size_t i = 0; i < sons.size(); i++)
205 tree.
scaleTree(sons[i], h[i] > 0 ? l / h[i] : 0);
215 throw Exception(
"The tree has to be rooted on the branch of interest to determine the midpoint position of the root");
217 vector<shared_ptr<PhyloNode>> sons = tree.
getSons(tree.
getRoot());
220 throw Exception(
"The tree is multifurcated at the root, which is not allowed.");
228 length = branch0->getLength() + branch1->getLength();
231 double x = bestRootPosition_(tree, sons[0], sons[1], length);
233 branch0->setLength(length * x);
234 branch1->setLength(length * (1 - x));
245 m1 = statFromNode_(tree, node1);
246 m2 = statFromNode_(tree, node2);
247 A = 4 * m1.
N * (m2.
N * length) * length;
248 B = 4 * length * (m2.
N * m1.
sum - m1.
N * m2.
sum - length * m1.
N * m2.
N);
281 vector<shared_ptr<PhyloNode>> sons = tree.
getSons(root);
282 for (
size_t i = 0; i < sons.size(); i++)
284 mtmp = statFromNode_(tree, sons[i]);
287 double bLength = branch->getLength();
289 m.
sum += mtmp.
sum + bLength * mtmp.
N;
bool isLeaf(const Nref node) const
std::pair< Nref, Nref > getNodes(Eref edge) const
virtual std::shared_ptr< N > getRoot() const=0
virtual std::vector< std::shared_ptr< E > > getOutgoingEdges(const std::shared_ptr< N > node) const=0
std::vector< std::shared_ptr< N > > getSons(const std::shared_ptr< N > node) const
std::shared_ptr< E > getEdgeToFather(const std::shared_ptr< N > nodeObject) const
The phylogenetic node class.
virtual std::string getName() const
Get the name associated to this node, if there is one, otherwise throw a NodeException.
virtual Clonable * getNodeProperty(const std::string &name)
virtual int getId() const
Get the node's id.
virtual bool hasName() const
Tell is this node has a name.
virtual std::vector< std::string > getNodePropertyNames() const
General exception thrown when something is wrong with a particular branch.
void scaleTree(double factor)
Multiply all branch lengths by a given factor.
The phylogenetic tree class.
virtual N * getRootNode()
Defines the basic types of data flow nodes.
ExtendedFloat pow(const ExtendedFloat &ef, double exp)