annotate t2ps_wrapper.py @ 1:dee81096ec71 draft

Uploaded tool help images.
author devteam
date Tue, 03 Jun 2014 12:36:57 -0400
parents 9e2b9ca7f33a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
1 """
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
2 Wrapper for tree2PS-fast
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
3 Requires ps2pdf (a part of ghostscript package) to be installed
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
4
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
5 t2ps_wrapper.py <taxonomy file> <output PDF file> <max_tree_level> <font_size> <max_leaves> <count_duplicate_tax_id>
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
6
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
7 taxonomy file - tree file produced by taxonomy2tree program written by Sergei Kosakovski Pond
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
8 output PDF file - tree image
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
9 max_tree_level - integer from 0 to 21; 0 = show all levels
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
10 font_size - integer from 2 to 255 (8 is the best)
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
11 max_leaves - integer from 0 to infinity (0 = show all)
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
12 count_duplicate - 0 (do not count) or 1 (count)
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
13
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
14 anton nekrutenko | anton@bx.psu.edu
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
15 tree2PS-fast is written by Sergei Kosakovski Pond | sergeilkp@mac.com
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
16 """
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
17
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
18 import string, sys, tempfile, subprocess
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
19
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
20 def stop_err(msg):
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
21 sys.stderr.write(msg)
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
22 sys.exit()
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
23
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
24
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
25 try:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
26 tree_file = sys.argv[1]
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
27 pdf_file = sys.argv[2]
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
28 max_tree_level = sys.argv[3]
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
29 font_size = sys.argv[4]
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
30 max_leaves = sys.argv[5]
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
31 dups = sys.argv[6]
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
32 except:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
33 stop_err('Check arguments\n')
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
34
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
35 newick_file = tempfile.NamedTemporaryFile('w')
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
36 ps_file = tempfile.NamedTemporaryFile('w')
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
37
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
38 # Execute taxonomy2tree
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
39
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
40 try:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
41 t2t_cmd = 'taxonomy2tree %s %s %s /dev/null 1 > /dev/null 2>&1' % ( tree_file, max_tree_level, newick_file.name )
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
42 retcode = subprocess.call( t2t_cmd, shell=True )
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
43 if retcode < 0:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
44 print >>sys.stderr, "Execution of taxonomy2tree terminated by signal", -retcode
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
45 except OSError, e:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
46 print >>sys.stderr, "Execution of taxonomy2tree failed:", e
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
47
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
48
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
49 # Execute tree2PS-fast
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
50
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
51 try:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
52 t2ps_cmd = 'tree2PS-fast %s %s %s %s %s %s' % ( newick_file.name, ps_file.name, max_tree_level, font_size, max_leaves, dups )
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
53 retcode = subprocess.call( t2ps_cmd, shell=True )
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
54 if retcode < 0:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
55 print >>sys.stderr, "Execution of tree2PS-fast terminated by signal", -retcode
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
56 except OSError, e:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
57 print >>sys.stderr, "Execution of tree2PS-fast failed:", e
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
58
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
59 # Convert PS to PDF
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
60
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
61 try:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
62 ps2pdf_cmd = 'ps2pdf %s %s' % ( ps_file.name, pdf_file )
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
63 retcode = subprocess.call( ps2pdf_cmd, shell=True )
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
64 if retcode < 0:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
65 print >>sys.stderr, "Execution of ps2pdf terminated by signal", -retcode
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
66 except OSError, e:
9e2b9ca7f33a Imported from capsule None
devteam
parents:
diff changeset
67 print >>sys.stderr, "Execution of ps2pdf failed:", e