5 #include "../Likelihood/ParametrizablePhyloTree.h"
18 name_(tree ? tree->name_ :
"")
28 std::vector<shared_ptr<PhyloNode>> nodes =
getAllNodes();
29 for (
unsigned int i = 0; i < nodes.size(); i++)
44 if (it->hasName() && it->getName() == name)
48 return std::make_shared<PhyloNode>();
57 for (vector<shared_ptr<PhyloNode>>::const_iterator it = vpn.begin(); it != vpn.end(); it++)
59 vn.push_back((*it)->getName());
68 for (vector<shared_ptr<PhyloBranch>>::iterator currBranch = branches.begin(); currBranch != branches.end(); currBranch++)
70 if ((*currBranch)->hasLength())
71 (*currBranch)->setLength((*currBranch)->getLength() * factor);
88 if (std::find(leaves.begin(), leaves.end(), leaf->getName()) == leaves.end())
90 while (leaf &&
isLeaf(leaf))
102 vector<shared_ptr<PhyloBranch>> vpn =
getAllEdges();
114 vector<shared_ptr<PhyloBranch>> vpn =
getAllEdges();
118 vl.push_back(it->getLength());
126 vector<shared_ptr<PhyloBranch>> vpn =
getAllEdges();
134 if (!it->hasLength() || !phylotree.
getEdge(ei)->hasLength())
135 throw Exception(
"Phylotree::operator+= : no summing of branches without length.");
137 it->setLength(it->getLength() + phylotree.
getEdge(ei)->getLength());
145 vector<shared_ptr<PhyloBranch>> vpn =
getAllEdges();
153 if (!it->hasLength() || !phylotree.
getEdge(ei)->hasLength())
154 throw Exception(
"Phylotree::operator+= : no summing of branches without length.");
156 it->setLength(it->getLength() - phylotree.
getEdge(ei)->getLength());
164 vector<shared_ptr<PhyloBranch>> vpn =
getAllEdges();
172 if (!it->hasLength() || !phylotree.
getEdge(ei)->hasLength())
173 throw Exception(
"Phylotree::operator/= : no summing of branches without length.");
175 it->setLength(it->getLength() / phylotree.
getEdge(ei)->getLength());
183 vector<shared_ptr<PhyloBranch>> vpn =
getAllEdges();
191 if (!it->hasLength() || !phylotree.
getEdge(ei)->hasLength())
192 throw Exception(
"Phylotree::operator/= : no summing of branches without length.");
194 it->setLength(it->getLength() * phylotree.
getEdge(ei)->getLength());
204 const Node& fils = *node[i];
207 auto soni = std::make_shared<PhyloNode>(fils.
hasName() ? fils.
getName() :
"");
211 for (
const auto& prop:propi)
216 auto branchi = std::make_shared<PhyloBranch> ();
223 for (
const auto& prop:propi)
bool isLeaf(const Nref node) const
virtual std::vector< std::shared_ptr< N > > getAllLeaves() const=0
virtual std::vector< std::shared_ptr< E > > getAllEdges() const=0
virtual NodeIndex setNodeIndex(const std::shared_ptr< N > nodeObject, NodeIndex index)=0
virtual void deleteNode(std::shared_ptr< N > nodeObject)=0
virtual std::shared_ptr< N > getRoot() const=0
virtual EdgeIndex getEdgeIndex(const std::shared_ptr< E > edgeObject) const=0
virtual std::vector< std::shared_ptr< N > > getAllNodes() const=0
virtual EdgeIndex setEdgeIndex(const std::shared_ptr< E > edgeObject, EdgeIndex index)=0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const=0
virtual bool hasEdge(EdgeIndex edgeIndex) const=0
virtual void createNode(std::shared_ptr< N > newNodeObject)=0
bool hasFather(const std::shared_ptr< N > nodeObject) const
std::shared_ptr< E > getEdgeToFather(const std::shared_ptr< N > nodeObject) const
std::shared_ptr< N > getFatherOfNode(const std::shared_ptr< N > nodeObject) const
std::vector< std::shared_ptr< E > > getSubtreeEdges(const std::shared_ptr< N > localRoot) 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 hasDistanceToFather() const
Tell is this node has a distance to the father.
virtual Clonable * getBranchProperty(const std::string &name)
virtual std::vector< std::string > getBranchPropertyNames() const
virtual bool hasName() const
Tell is this node has a name.
virtual std::vector< std::string > getNodePropertyNames() const
virtual double getDistanceToFather() const
Get the distance to the father node is there is one, otherwise throw a NodeException.
virtual size_t getNumberOfSons() const
PhyloTree with Parametrizable Phylo Branches. They SHARE their branch length parameters.
General exception thrown when something is wrong with a particular branch.
PhyloTree & operator*=(const PhyloTree &phylotree)
Multiplies the lengths of branches of this phylotree by the ones of another phylotree....
void scaleTree(double factor)
Multiply all branch lengths by a given factor.
void addSubTree(std::shared_ptr< PhyloNode > phyloNode, const Node &node)
Concatenate the subtree under a Node (in a TreeTemplate<Node>) to this PhyloTree, under the given phy...
Vdouble getBranchLengths() const
PhyloTree(bool rooted=false)
std::vector< std::string > getAllLeavesNames() const
std::shared_ptr< PhyloNode > getPhyloNode(const std::string &name) const
PhyloTree & operator+=(const PhyloTree &phylotree)
Add the lengths of branches of another phylotree to this one. Just branch ids are considered,...
PhyloTree & operator-=(const PhyloTree &phylotree)
Subtracts the lengths of branches of another phylotree to this one. Just branch ids are considered,...
void pruneTree(std::vector< std::string > leaves)
Prune a tree to a given set of leaf names.
void setBranchLengths(double l)
PhyloTree & operator/=(const PhyloTree &phylotree)
Divides the lengths of branches of this phylotree by the ones of another phylotree....
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble