root/galaxy-central/tools/taxonomy/t2ps_wrapper.py

リビジョン 2, 2.2 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1"""
2Wrapper for tree2PS-fast
3Requires ps2pdf (a part of ghostscript package) to be installed
4
5t2ps_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   
14anton nekrutenko | anton@bx.psu.edu
15tree2PS-fast is written by Sergei Kosakovski Pond | sergeilkp@mac.com
16"""
17
18import string, sys, tempfile, subprocess
19
20def stop_err(msg):
21    sys.stderr.write(msg)
22    sys.exit()
23
24
25try:
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]
32except:
33    stop_err('Check arguments\n')
34
35newick_file = tempfile.NamedTemporaryFile('w')   
36ps_file = tempfile.NamedTemporaryFile('w')
37
38# Execute taxonomy2tree
39   
40try:
41    t2t_cmd = 'taxonomy2tree %s %s %s /dev/null 1 &> /dev/null' % ( 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
45except OSError, e:
46    print >>sys.stderr, "Execution of taxonomy2tree failed:", e
47
48
49# Execute tree2PS-fast
50   
51try:
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
56except OSError, e:
57    print >>sys.stderr, "Execution of tree2PS-fast failed:", e
58   
59# Convert PS to PDF
60
61try:
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
66except OSError, e:
67    print >>sys.stderr, "Execution of ps2pdf failed:", e
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。