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.

Slides:



Advertisements
Similar presentations
Directory and File Paths Copyright © Software Carpentry and The University of Edinburgh This work is licensed under the Creative Commons Attribution.
Advertisements

Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
1 Drawing phylogenies We've seen several tree data structures but we still can't draw a tree  In today's first exercise we write a drawtree module for.
1 Parsing XML sequence? We have i2xml filter (exercise) – we want xml2i also Don’t have to write XML parser, Python provides one Thus, algorithm: – Open.
1 Extensible Markup Language: XML HTML: widely supported protocol for formatting data XML: widely supported protocol for describing data XML is quickly.
Chapter 5 Accessing Files and Directories. How Directories Get Created OS installation: usr, dev, etc, export, kernel and others places to store installation.
File Management System The way a user or application may access files Programmer does not need to develop file management software You take files for granted.
Building Suffix Trees in O(m) time Weiner had first linear time algorithm in 1973 McCreight developed a more space efficient algorithm in 1976 Ukkonen.
Computer Science 210 Computer Organization Modular Decomposition Making a Library Separate Compilation.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
Zach Moshe Rotem Naar.  File upload vulnerabilities overview  FUV – detailed overview  Live demonstration  In the future…
1 Spidering the Web in Python CSC 161: The Art of Programming Prof. Henry Kautz 11/23/2009.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 17 Reading and Writing Files 5/10/09 Python Mini-Course: Lesson 17 1.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
Chapter 14 Files and Exceptions II. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. What we already.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
H3D API Training  Part 3.1: Python – Quick overview.
Chapter 8 Cookies And Security JavaScript, Third Edition.
1 CS 177 Week 16 Recitation Recursion. 2 Objective To understand and be able to program recursively by breaking down a problem into sub problems and joining.
Spring 2010CS 2251 Trees Chapter 6. Spring 2010CS 2252 Chapter Objectives Learn to use a tree to represent a hierarchical organization of information.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
1 Using Modules. 2 Modules A Perl module is a collection of subroutines and variables that typically implements some common functionality – and "packaged"
Copyrighted material John Tullis 10/17/2015 page 1 04/15/00 XML Part 3 John Tullis DePaul Instructor
1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Progress with migration to SVN Part3: How to work with g4svn and geant4tags tools. Geant4.
Built-in Data Structures in Python An Introduction.
Javadoc Comments.  Java API has a documentation tool called javadoc  The javadoc tool is used on the source code embedded with javadoc-style comments.
# 1 CMPS 450 Syntax-Directed Translations CMPS 450 J. Moloney.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
Javadoc Dwight Deugo Nesa Matic
Storing and Retrieving Data
Chapter 3 Understanding Ant datatypes and properties.
Python – reading and writing files. ??? ???two ways to open a file open and file ??? How to write to relative and absolute paths?
PC204 Lecture 5 Conrad Huang Genentech Hall, N453A
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
FILES. open() The open() function takes a filename and path as input and returns a file object. file object = open(file_name [, access_mode][, buffering])
CS2021 Python Programming Week 3 Systems Programming PP-Part II.
LECTURE 7 The Standard Library Part 1: Built-ins, time, sys, and os.
File Paths *referenced from
Head First Python: Ch 3. Files and Exceptions: Dealing with Errors Aug 26, 2013 Kyung-Bin Lim.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
CITA 310 Section 4 Apache Configuration (Selected Topics from Textbook Chapter 6)
Python Files and Lists. Files  Chapter 9 actually introduces you to opening up files for reading  Chapter 14 has more on file I/O  Python can read.
18-1 Chapter 18 Binary Trees Data Structures and Design in Java © Rick Mercer.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Today… Strings: –String Methods Demo. Raising Exceptions. os Module Winter 2016CISC101 - Prof. McLeod1.
Python: File Directories What is a directory? A hierarchical file system that contains folders and files. Directory (root folder) Sub-directory (folder.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
Topic 2: binary Trees COMP2003J: Data Structures and Algorithms 2
Python’s Modules Noah Black.
Intro to Python Programming – Part III
Data Structures and Design in Java © Rick Mercer
Intro to Python Programming – Part II
CSC1018F: Functional Programming
OS The os module allows interaction with the Operating System, either generically or specific to a particular OS.
Creating and Modifying Text part 2
Find in a linked list? first last 7  4  3  8 NULL
Fundamentals of Programming I Files
Winter 2018 CISC101 12/5/2018 CISC101 Reminders
This lecture Introduction to arcpy Debugging Using arcpy.
Intro to PHP.
CISC101 Reminders Assn 3 sample solution is posted.
Bryan Burlingame 17 April 2019
Browsing Directories Using walk
Tree (new ADT) Terminology: A tree is a collection of elements (nodes)
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 converter as 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 drawtree doesn’t know how to get to the sons and the name of a DOM tree node, but this XML converter tells it how xml_draw.py (part 1)

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

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( 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. os.walk - recursively traverse directory NotesProgramExamples figuresFromCourseNotes

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 /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) NotesProgramExamples figuresFromCourseNotes

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

15 Tadaa!

16..on to the exercises