comparison src/breadcrumbs/src/circlader/circlader.py @ 0:0de566f21448 draft default tip

v2
author sagun98
date Thu, 03 Jun 2021 18:13:32 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0de566f21448
1 #!/usr/bin/env python
2
3 #-----------------------------------------------------------------------------
4 # NAME: circlader.py
5 # DESCRIPTION: Circlader (circular cladogram buider) is a python script for
6 # creating images of circular cladogram starting from any guide
7 # tree in tabular or Newick format
8 #
9 # Author: Nicola Segata
10 # email: nsegata@hsph.harvard.edu
11 #
12 # Copyright: (c) 2011
13 # Licence: <your licence>
14 #
15 #-----------------------------------------------------------------------------
16
17
18 import os
19 import sys,argparse
20 import circlader_lib as cir
21
22 def read_params(args):
23 parser = argparse.ArgumentParser(description='Circlader')
24
25 parser.add_argument('tree_file', nargs='?', default=None, type=str,
26 help= "the input tree in Newick format (unless --tf is specified)"
27 "[stdin if not present]")
28 parser.add_argument('out_image', nargs='?', default=None, type=str,
29 help= "the output image (the format is guessed from the extension "
30 "[windows visualization if not present]")
31 parser.add_argument('--tree_format', choices=['newick','tabular'],
32 default='newick', type=str,
33 help= "specifies the input tree format (default \"newick\", "
34 "other choice is \"tabular\")")
35 parser.add_argument('--style_file', nargs='?', default=os.getcwd()+"/default_styles/style.txt", type=str,
36 help= "set the style file (default_styles/style.txt if not specified)")
37 parser.add_argument('--color_file', nargs='?', default=None, type=str,
38 help= "set the color file (default_styles/colors.txt if not specified)")
39 parser.add_argument('--highlight_file', nargs='?', default=None, type=str,
40 help= "set the highlight file (default none)")
41 parser.add_argument('--tick_file', nargs='?', default=None, type=str,
42 help= "set the label file for level's names (default none)")
43 parser.add_argument('--size_file', nargs='?', default=None, type=str,
44 help= "set the file containing the dimentison of the circles (default none)")
45 parser.add_argument('--circle_file', nargs='?', default=None, type=str,
46 help= "set the external circles file (default none) [BETA FEATURE]")
47 parser.add_argument('--format', choices=['png','pdf','ps','eps','svg'], default=None, type=str,
48 help= "set the format of the output image (default none "
49 "meaning that the format is guessed from the output "
50 "file extension)")
51 parser.add_argument('--dpi', default=300, type=int )
52
53 return vars(parser.parse_args())
54
55 params = read_params(sys.argv)
56
57 cladogram = cir.Tree()
58 cladogram.read_colors(params['color_file'])
59 cladogram.read_style(params['style_file'])
60 cladogram.read_sizes(params['size_file'])
61 cladogram.read_circles(params['circle_file'])
62 cladogram.read_highlights(params['highlight_file'])
63 cladogram.read_tick_labels(params['tick_file'])
64 if params['tree_format'] == 'newick':
65 cladogram.load_newick(params['tree_file'])
66 else:
67 cladogram.load_lefse(params['tree_file'])
68 cladogram.pos_rad_leaves()
69 cladogram.set_pos()
70 cladogram.draw(params['out_image'],outformat=params['format'],dpi=params['dpi'])