annotate tools/taxonomy/t2ps_wrapper.py @ 1:cdcb0ce84a1b

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