PTreeGenerator  1.0
Simple phylogenetic tree generation from multiple sequence alignment.
•All Classes Namespaces Files Functions Variables
main.py
Go to the documentation of this file.
1 ## @package main
2 # The main module with the main method.
3 # Handles the comand line options
4 # and delegates actions to other modules.
5 
6 from argparse import ArgumentParser
7 
8 import ptreegen
9 
10 ##
11 # The main method. First to be executed
12 # when the program is run.
13 def main():
14  description="This is a simple tool for generating phylogenetic trees from multiple sequence alignments. " \
15  "It implements two tree building approaches (Neigbor-Joining and Maximum Parsimony)." \
16  "It can also do some simple visualizations and export the tree in the Newick format."
17  epilog = "For more info see the GitHub page (https://github.com/martin-sicho/PTreeGenerator) " \
18  "or contact 'sichom@vscht.cz'."
19  arg_parser = ArgumentParser(prog="ptreegen", description=description, epilog=epilog)
20  arg_parser.add_argument('--version'
21  , action='version'
22  , version='1.0-alpha')
23  arg_parser.add_argument('alignment_file'
24  , help='Multiple sequence alignment in FASTA format.')
25  arg_parser.add_argument('-m'
26  ,'--method'
27  , action='store'
28  , default=ptreegen.TreeBuildAlgorithms.NJ
29  , help='Method used to build the tree. One of the following: "'
30  + ptreegen.TreeBuildAlgorithms.NJ + '" for neigbor joining and "'
31  + ptreegen.TreeBuildAlgorithms.PARSIMONY + '" for a parsimony method. '
32  + 'Neigbor joining is the default method.'
33  )
34  arg_parser.add_argument('-i'
35  , '--pars-tree-count'
36  , action='store'
37  , default=1000
38  , help="Number of trees used to build a consensus tree from when using "
39  + "the parsimony method. Default value is 1000.")
40  arg_parser.add_argument('-g'
41  , '--no-gaps'
42  , action='store_true'
43  , help="Remove all gapped postions from the alignment before tree building.")
44  arg_parser.add_argument('-p'
45  , '--gap-penalty'
46  , action='store'
47  , default=0.5
48  , help="Gap penalty. Default value is 0.5.")
49  arg_parser.add_argument('-c'
50  , '--no-cleaning'
51  , action='store_true'
52  , help="Do not clean badly conserved regions from the alignment before tree building.")
53  arg_parser.add_argument('-u'
54  , '--gap-cutoff'
55  , action='store'
56  , default=0.8
57  , help="When cleaning the alignment, keep only columns with "
58  + "non-gap frequency above this threshold. Default value is 0.8.")
59  arg_parser.add_argument('-r'
60  , '--pair-cutoff'
61  , action='store'
62  , default=0.3
63  , help="When cleaning the alignment, keep only columns where the frequency of identical pairs is above this threshold. Default value is 0.3.")
64  arg_parser.add_argument('-s'
65  , '--sequence-type'
66  , action='store'
67  , default=ptreegen.SeqTypes.AA
68  , help='Type of the sequences in the alignment (proteins by default): "'
69  + ptreegen.SeqTypes.AA + '" for proteins, "'
70  + ptreegen.SeqTypes.DNA + '" for DNA and "'
71  + ptreegen.SeqTypes.RNA + '" for RNA.'
72  )
73  arg_parser.add_argument('-d'
74  , '--dist-measure'
75  , action='store'
76  , default=ptreegen.DistMeasures.JUKES_CANTOR
77  , help='Distance function to be used to compute distance '
78  + 'between sequences (Jukes-Cantor by default): "'
79  + ptreegen.DistMeasures.P_DISTANCE + '" for p-distance, "'
80  + ptreegen.DistMeasures.POISSON_CORRECTED + '" for Poisson correction and "'
81  + ptreegen.DistMeasures.JUKES_CANTOR + '" for Jukes-Cantor.'
82  )
83 
84  # visualization arguments
85  arg_parser.add_argument('-f'
86  , '--out-form'
87  , action='store'
88  , default=ptreegen.OutputForm.PRINT + "," + ptreegen.OutputForm.NEWICK
89  , help='The output formats for the resulting tree as a comma separated list. '
90  + 'Possible options: "'
91  + ptreegen.OutputForm.PRINT + '" prints the tree to command line, "'
92  + ptreegen.OutputForm.NEWICK + '" saves the tree in newick format to a file in the input directory, "'
93  + ptreegen.OutputForm.IMAGE_PNG + '" saves the tree as a PNG image in the input directory, "'
94  + ptreegen.OutputForm.IMAGE_SVG + '" saves the tree as a PNG image in the input directory, "'
95  + ptreegen.OutputForm.GUI + '" shows the tree in a graphical viewer.'
96  )
97  arg_parser.add_argument('-t'
98  , '--tree-type'
99  , action='store'
100  , default=ptreegen.TreeType.CIRC
101  , help='The type of the tree to be rendered. '
102  + 'The default is circular. Can be one of: "'
103  + ptreegen.TreeType.CIRC + '" for circular or "'
104  + ptreegen.TreeType.RECT + '" for rectangular.'
105  )
106 
107 
108  arguments = arg_parser.parse_args()
109  results = ptreegen.Computation(vars(arguments))
110  results.showResults()
111 
112  return 0
113 
114 if __name__ == "__main__":
115  exit(main())
116 
117