Question: Phylogenetic trees Place your code in a file called PhylogeneticTrees.py The problems below will make use of the following sample tree, which you can cut-
Phylogenetic trees Place your code in a file called PhylogeneticTrees.py The problems below will make use of the following sample tree, which you can cut- and-paste this into your homework file. Goodies = ( "X", "LO, O) "C, O,O Using the techniques we've discussed for operating on trees, write the following functions: leafCount (Tree) >>> leafcount (Groodies) >>leafcount((5,(3,"A", ,),"B", , ,c, o, o)) find(node, Tree) This function returns True if the given node is in the given Tree and returns False otherwise. Some examples of find: >find('w,Groodies) True > find( A',Groodies) False find'E',Groodies) True subtree(node, Tree) Returns the subtree of the given Tree rooted at the given node. Said another way, this function returns the tree beginning at node. This function can be very short, and may have as few as four lines in its body. It will be recursive, but can also call the find function for help. In particular, if the root of the Tree matches node then we just return that Tree. If not, we can use find to determine whether the species is in the left subtree or the right subtree, and then proceed from there. You can assume that node is present in Tree. Here are some examples: >>>subtree(", Groodies) >> subtree("Y", Groodies) >>> subtree("Z", Groodies) Phylogenetic trees Place your code in a file called PhylogeneticTrees.py The problems below will make use of the following sample tree, which you can cut- and-paste this into your homework file. Goodies = ( "X", "LO, O) "C, O,O Using the techniques we've discussed for operating on trees, write the following functions: leafCount (Tree) >>> leafcount (Groodies) >>leafcount((5,(3,"A", ,),"B", , ,c, o, o)) find(node, Tree) This function returns True if the given node is in the given Tree and returns False otherwise. Some examples of find: >find('w,Groodies) True > find( A',Groodies) False find'E',Groodies) True subtree(node, Tree) Returns the subtree of the given Tree rooted at the given node. Said another way, this function returns the tree beginning at node. This function can be very short, and may have as few as four lines in its body. It will be recursive, but can also call the find function for help. In particular, if the root of the Tree matches node then we just return that Tree. If not, we can use find to determine whether the species is in the left subtree or the right subtree, and then proceed from there. You can assume that node is present in Tree. Here are some examples: >>>subtree(", Groodies) >> subtree("Y", Groodies) >>> subtree("Z", Groodies)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
