1 / 16

Drawing phylogenies

Drawing phylogenies. We've seen several tree data structures but we still can't draw a tree  In the tree drawing exercise we write a drawtree function for the Node class:. Drawing other trees. Can we reuse this phylogeny drawtree method with other trees?

allenmark
Download Presentation

Drawing phylogenies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Drawing phylogenies We've seen several tree data structures but we still can't draw a tree  In the tree drawing exercise we write a drawtree function for the Node class:

  2. Drawing other trees Can we reuse this phylogeny drawtree method with other trees? • drawtree needs to know child nodes and name of node No problem: A node in any tree has some sons (or none) and a name. Node specifics for drawtree: • uses method get_sons (returns list of child nodes) • used method get_name (returns string) Problem: Corresponding methods in other trees may have different names

  3. Can't use drawtree directly We want: General tree drawing tool that can draw any tree if given a converter object: an "interpreter" which knows what methods to call for the given kind of node instead of get_sons get_name • For each tree data structure we need to write a converter • Need to modify drawtree slightly to use a converter

  4. A converter class for tree data structure X • Should have two methods, each taking an X node as argument: • one for returning a list of the node's sons • one for returning the name of the node node

  5. New version of drawtree module • All functions that call get_name or get_sons on a node some_node must also take a converter object converteras argument • All occurrences of some_node.get_name() and some_node.get_sons() are replaced with converter.get_name( some_node ) and converter.get_sons( some_node )

  6. Example: converter for XML DOM trees A DOM tree consists of nodes representing tags in the XML data xml_draw.py (part 1) drawtree doesn’t knowhow to get to the sons and the name of a DOM tree node, but this XML converter tells it how

  7. Drawing XML DOM trees Import modified drawtree module xml_draw.py (part 2) Parse XML file, obtain DOM tree Please draw this tree, here is how (neat!)

  8. Drawing article2.xml

  9. And now for something completely different os module: Interface to operating system functionality os.linesep The string used to terminate lines on the current platform. This may be a single character, such as '\n' for Unix or '\r' for Mac OS, or multiple characters, for example, '\r\n' for Windows. os.getcwd() Returns a string representing the current directory os.mkdir( path ) Creates a directory with the given name os.listdir( path ) Returns a list of all entries in the given directory path

  10. os.path module: functions on pathnames os.path.split( path ) Split the pathname path into a pair, (head, tail) where tail is the part after the last / and head is everything leading up to that. os.path.dirname( path ) , os.path.basename( path ) Returns the head and tail of path, respectively. os.path.splitext( path ) Split the path into a pair (root, ext) such that root + ext == path, and ext is the extension. os.path.exists( path ) Returns true if the given file or directory exists, false otherwise. os.path.join( path1[, path2[, ...]] ) Joins the paths to form a new path in format valid on current platform: os.path.join( "/users/chili/PBI", "plan.html" ) gives /users/chili/PBI/plan.html

  11. os.walk - recursively traverse directory os.walk( top ) walk() generates the entries in a directory tree, by walking the tree either top down or bottom up. It returns a list of tuples: Each directory in the tree rooted at directory top (including top itself) yields a 3-tuple (dirpath, dirnames, filenames). dirpath is a string, the path to the directory. dirnames is a list of the names of the subdirectories in dirpath (excluding '.' and '..'). filenames is a list of the names of the non-directory files in dirpath. Notes ProgramExamples figures FromCourseNotes

  12. Find all python programs in PBI directories dirwalk.py Traversal is top-down by default: OK to remove a directory from the subdirs list to avoid visiting it

  13. Notes ProgramExamples figures FromCourseNotes /users/chili/PBI/Exercises contains 3 .py files (out of 211 files) /users/chili/PBI/Exercises/Solutions contains 29 .py files (out of 67 files) /users/chili/PBI/ProgramExamples contains 48 .py files (out of 89 files) /users/chili/PBI/ProgramExamples/FromCourseNotes contains 25 .py files (out of 27 files)

  14. Now that we have a drawtree function.. entry names only local: join with root to get full path dirdraw.py

  15. Tadaa!

  16. ..on to the exercises

More Related