Mercurial > repos > devteam > t2ps
changeset 0:9e2b9ca7f33a draft
Imported from capsule None
author | devteam |
---|---|
date | Mon, 27 Jan 2014 09:28:14 -0500 |
parents | |
children | dee81096ec71 |
files | t2ps_wrapper.py t2ps_wrapper.xml tool_dependencies.xml |
diffstat | 3 files changed, 202 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/t2ps_wrapper.py Mon Jan 27 09:28:14 2014 -0500 @@ -0,0 +1,67 @@ +""" +Wrapper for tree2PS-fast +Requires ps2pdf (a part of ghostscript package) to be installed + +t2ps_wrapper.py <taxonomy file> <output PDF file> <max_tree_level> <font_size> <max_leaves> <count_duplicate_tax_id> + + taxonomy file - tree file produced by taxonomy2tree program written by Sergei Kosakovski Pond + output PDF file - tree image + max_tree_level - integer from 0 to 21; 0 = show all levels + font_size - integer from 2 to 255 (8 is the best) + max_leaves - integer from 0 to infinity (0 = show all) + count_duplicate - 0 (do not count) or 1 (count) + +anton nekrutenko | anton@bx.psu.edu +tree2PS-fast is written by Sergei Kosakovski Pond | sergeilkp@mac.com +""" + +import string, sys, tempfile, subprocess + +def stop_err(msg): + sys.stderr.write(msg) + sys.exit() + + +try: + tree_file = sys.argv[1] + pdf_file = sys.argv[2] + max_tree_level = sys.argv[3] + font_size = sys.argv[4] + max_leaves = sys.argv[5] + dups = sys.argv[6] +except: + stop_err('Check arguments\n') + +newick_file = tempfile.NamedTemporaryFile('w') +ps_file = tempfile.NamedTemporaryFile('w') + +# Execute taxonomy2tree + +try: + t2t_cmd = 'taxonomy2tree %s %s %s /dev/null 1 > /dev/null 2>&1' % ( tree_file, max_tree_level, newick_file.name ) + retcode = subprocess.call( t2t_cmd, shell=True ) + if retcode < 0: + print >>sys.stderr, "Execution of taxonomy2tree terminated by signal", -retcode +except OSError, e: + print >>sys.stderr, "Execution of taxonomy2tree failed:", e + + +# Execute tree2PS-fast + +try: + t2ps_cmd = 'tree2PS-fast %s %s %s %s %s %s' % ( newick_file.name, ps_file.name, max_tree_level, font_size, max_leaves, dups ) + retcode = subprocess.call( t2ps_cmd, shell=True ) + if retcode < 0: + print >>sys.stderr, "Execution of tree2PS-fast terminated by signal", -retcode +except OSError, e: + print >>sys.stderr, "Execution of tree2PS-fast failed:", e + +# Convert PS to PDF + +try: + ps2pdf_cmd = 'ps2pdf %s %s' % ( ps_file.name, pdf_file ) + retcode = subprocess.call( ps2pdf_cmd, shell=True ) + if retcode < 0: + print >>sys.stderr, "Execution of ps2pdf terminated by signal", -retcode +except OSError, e: + print >>sys.stderr, "Execution of ps2pdf failed:", e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/t2ps_wrapper.xml Mon Jan 27 09:28:14 2014 -0500 @@ -0,0 +1,129 @@ +<tool id="Draw_phylogram" name="Draw phylogeny" version="1.0.0"> + <description></description> + <requirements> + <requirement type="package" version="1.0.0">taxonomy</requirement> + </requirements> + <command interpreter="python">t2ps_wrapper.py $input $out_file1 $max_tree_level $font_size $max_leaves 1</command> + <inputs> + <param format="taxonomy" name="input" type="data" label="Draw phylogram for"></param> + <param name="max_tree_level" label="show ranks from root to" type="select" help="Choosing to show entire tree may produce very large PDF file disabling your viewer"> + <option value="8">Class</option> + <option value="0">Show entire tree</option> + <option value="1">Superkingdom</option> + <option value="2">Kingdom</option> + <option value="3">Subkingdom</option> + <option value="4">Superphylum</option> + <option value="5">Phylum</option> + <option value="6">Subphylum</option> + <option value="7">Superclass</option> + <option value="9">Subclass</option> + <option value="10">Superorder</option> + <option value="11">Order</option> + <option value="12">Suborder</option> + <option value="13">Superfamily</option> + <option value="14">Family</option> + <option value="15">Subfamily</option> + <option value="16">Tribe</option> + <option value="17">Subtribe</option> + <option value="18">Genus</option> + <option value="19">Subgenus</option> + <option value="20">Species</option> + <option value="21">Subspecies</option> + </param> + <param name="font_size" type="select" label="select font size"> + <option value="8">Normal</option> + <option value="4">Tiny</option> + <option value="12">Large</option> + </param> + <param name="max_leaves" type="text" size="5" value="0" label="maximum number of leaves" help="set to 0 to show all"/> + </inputs> + <outputs> + <data format="pdf" name="out_file1" /> + </outputs> + <requirements> + <requirement type="binary">tree2PS-fast</requirement> + </requirements> + <help> + +**What it does** + +Given taxonomy representation (produced by *Fetch taxonomic representation* tool) this utility produces a graphical representations of phylogenetic tree in PDF format. + +-------- + +**Example 1: Fake data** + +Suppose you have the following dataset:: + + Species_1 1 root superkingdom1 kingdom1 subkingdom1 superphylum1 phylum1 subphylum1 superclass1 class1 subclass1 superorder1 order1 suborder1 superfamily1 family1 subfamily1 tribe1 subtribe1 genus1 subgenus1 species1 subspecies1 + Species_2 2 root superkingdom1 kingdom1 subkingdom1 superphylum1 phylum1 subphylum1 superclass1 class1 subclass1 superorder1 order1 suborder1 superfamily1 family1 subfamily1 tribe1 subtribe1 genus2 subgenus2 species2 subspecies2 + Species_3 3 root superkingdom1 kingdom1 subkingdom1 superphylum1 phylum3 subphylum3 superclass3 class3 subclass3 superorder3 order3 suborder3 superfamily3 family3 subfamily3 tribe3 subtribe3 genus3 subgenus3 species3 subspecies3 + Species_4 4 root superkingdom1 kingdom1 subkingdom1 superphylum1 phylum4 subphylum4 superclass4 class4 subclass4 superorder4 order4 suborder4 superfamily4 family4 subfamily4 tribe4 subtribe4 genus4 subgenus4 species4 subspecies4 + +Drawing the tree with default parameters (without changing anything in the interface) will produce this tree: + +.. image:: ${static_path}/images/t2ps_ideal.png + :width: 500 + +(for explanation of colors and numbers on the tree scroll to the bottom of this help section) + +Here *Class* rank represent terminal nodes (leaves) of the tree because it is the default setting of the "*show ranks from root to*" drop-down. Changing the drop-down to "*Subspecies*" will produce this: + +.. image:: ${static_path}/images/t2ps_ideal_ssp.png + :width: 1000 + +-------- + +**Example 2: Fake data with missing nodes** + +Real taxonomic datasets almost always contain empty nodes. These are represented with "**n**" as shown below:: + + Species_1 1 root superkingdom1 kingdom1 subkingdom1 superphylum1 phylum1 subphylum1 superclass1 class1 subclass1 superorder1 order1 suborder1 superfamily1 family1 subfamily1 tribe1 subtribe1 genus1 subgenus1 species1 subspecies1 + Species_2 2 root superkingdom1 kingdom1 subkingdom1 superphylum1 phylum1 subphylum1 superclass1 class1 subclass1 superorder1 order1 suborder1 superfamily1 family1 subfamily1 tribe1 subtribe1 genus2 n species2 subspecies2 + Species_3 3 root superkingdom1 kingdom1 subkingdom1 superphylum1 n subphylum3 superclass3 class3 subclass3 superorder3 order3 suborder3 superfamily3 family3 subfamily3 tribe3 subtribe3 genus3 subgenus3 species3 subspecies3 + Species_4 4 root superkingdom1 kingdom1 subkingdom1 superphylum1 phylum4 subphylum4 superclass4 class4 subclass4 superorder4 order4 suborder4 superfamily4 family4 subfamily4 tribe4 subtribe4 genus4 subgenus4 species4 subspecies4 + +(here *phylum* for Species_3 and *subgenus* for Species_2 are unassigned) + +A full tree for this dataset will look like this: + +.. image:: ${static_path}/images/t2ps_missing_nodes.png + :width: 1000 + +Missing nodes are simply omitted from the tree (there are no gray boxes corresponding to "n") but the branch length is maintained so that taxa belonging to the same taxonomic rank are always aligned with each other + +-------- + +**Autoscaling the tree** + +You can use the "*maximum number of leaves*" to restrict the tree to a specified number of leaves (external nodes). Using the following setting on the above dataset (note *show ranks from root to* set to *show entire tree* and *maximum number of leaves* is set *3*): + +.. image:: ${static_path}/images/t2ps_autoscale.png + +will produce this tree: + +.. image:: ${static_path}/images/t2ps_autoscale_tree.png + :width: 1000 + +Here the tree is automatically trimmed at a taxonomic rank that will only have 3 outer nodes. This is very useful for initial evaluation of very large trees where you want to only see, say, 1,000 outer nodes at once. + +------- + +**Explanation of phylogenetic tree markup** + +Branches of the tree are colored according to the heatmap below. The "bluer" the branch the lesser the number of leaves it leads to and vice versa. + +.. image:: ${static_path}/images/t2ps_heatmap.png + +Each node is labeled with taxonomic name and the number of tree leaves belonging to this taxonomic group: + +.. image:: ${static_path}/images/t2ps_node_label.png + + + + + + </help> +</tool> + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool_dependencies.xml Mon Jan 27 09:28:14 2014 -0500 @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<tool_dependency> + <package name="taxonomy" version="1.0.0"> + <repository changeset_revision="c011d4659306" name="package_taxonomy_1_0_0" owner="devteam" prior_installation_required="False" toolshed="http://toolshed.g2.bx.psu.edu" /> + </package> +</tool_dependency>