Phylogenetics: Python Primer

From EEBedia
Revision as of 03:02, 4 February 2009 by PaulLewis (Talk | contribs)

Jump to: navigation, search
Adiantum.png EEB 349: Phylogenetics
This lab represents an introduction to the Python computing language, which will be useful for upcoming homework assignments as well as for software written as Python extensions (i.e. Phycas)

What is Python?

Python is one of two programming languages that we will use this semester (the other being R). One might make the case that programs like PAUP that are associated with a unique command language also represent programming languages; however, Python and R are different in being general purpose (i.e. not written specifically for phylogenetics).

Python is one of a number of different high-level computing languages in common use. All of the software we use is written in one of these languages. PAUP is written entirely in the C language, while SplitsTree is written in Java. Knowing a little bit of computer programming can save you immense amounts of time by allowing you to automate things. You will being realizing these savings doing homework for this class. While it is possible to do all the homework assignments by hand using a calculator, you will find that using Python will save you time and is more accurate (a mistake on a calculator early on in a calculation can be very costly in terms of time and accuracy). Python is a good language to learn first because it is relatively simple (not many words or punctuation rules to learn) and is much more forgiving than other languages. It is in a class of languages known as scripting languages because the program is interpreted as it is read - languages such as C require two additional steps (compiling and linking) before they can be run.

Installing Python

Mac users

Mac logo.jpg
If you have a Mac, then Python is already installed on your computer because it is used in many parts of the Mac OS X operating system. To verify this, and to see what version of Python you have, start your Terminal program (in the Applications/Utilities folder), then type the following at the unix prompt (note: the prompt is represented by a dollar sign ($), so you should only type the "python -V" part):
$ python -V
Python 2.5.1

Windows users

Win logo.png
If you have Windows, you will need to download and install Python from the http://www.python.org/download/ web site. Note that there are two current versions of Python. You should install the older one (Python 2.6.1). (We would use Python 3.0 except that some Python software that we will use later in the semester is not yet compatible with Python 3.0, so it makes sense to stick with 2.6 for now.) There are several different types of downloads: choose Python 2.6.1 Windows installer (Windows binary -- does not include source) and follow the directions once you start it up.

Once you have Python installed, you can invoke it from a console window (in Vista, use Start, All Programs, Accessories, Command Prompt) by typing python:

C:\Users\Administrator>python -V
Python 2.6.1

Everyone

You should download the documentation from http://docs.python.org/download.html so that it can be accessed quickly. I find the HTML form best: I unpacked the zip file and bookmarked it in my browser as follows:

file:///Users/plewis/Documents/Manuals/python-html/index.html