comparison t2ps_wrapper.py @ 0:9e2b9ca7f33a draft

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