University of Arizona, Department of Computer Science

CSc 120: Prettyprinting Phylogenetic Trees

The __str__() method specified for phylogenetic trees does not always make their structure easy to understand. If you want, you can use this code to print your tree in a more visually appealing manner. Download this code into the same directory as the rest of your code, import using
from prettyprint import *
and call the pretty-printing routine as pretty_print(tree) where tree is your tree. However, note that:

Example: The str() representation of the phylogenetic tree obtained from the data file SARS.fasta (12 strains of the human SARS virus), with N-gram size = 6, is

((((KF514413.1, KF514423.1), (KF514415.1, KF514418.1)), ((KF514419.1, KF514422.1), KF514421.1)), (((KF514414.1, KF514416.1), KF514420.1), (KF514412.1, KF514417.1)))

The prettyprinting code mentioned above displays this tree as follows:

                    +--- KF514413.1
               +---|
              |     +--- KF514423.1
          +---|
         |    |     +--- KF514415.1
         |     +---|
     +---|          +--- KF514418.1
    |    |
    |    |          +--- KF514419.1
    |    |     +---|
    |     +---|     +--- KF514422.1
+---|         |
    |          +--- KF514421.1
    |
    |               +--- KF514414.1
    |          +---|
    |     +---|     +--- KF514416.1
    |    |    |
     +---|     +--- KF514420.1
         |
         |     +--- KF514412.1
          +---|
               +--- KF514417.1