| Bsoft 2.0.5 Bernard's software package

btree.cpp
Go to the documentation of this file.
1
9 #include "rwtree.h"
10 #include "ps_tree.h"
11 #include "utilities.h"
12 #include "options.h"
13 #include "timer.h"
14
15 // Declaration of global variables
16 extern int verbose; // Level of output to the screen
17
18 // Usage assistance
19 const char* use[] = {
20 " ",
21 "Usage: btree [options] tree.ph tree.ps",
22 "--------------------------------------",
23 "Draws phylogenetic trees as postscript.",
24 "Handles phylip format trees as input.",
25 " ",
26 "Parameters:",
27 "-verbose 7 Verbosity of output.",
28 "-scale 350 Scale for postscript output (default 200).",
29 "-rotate 110 Rotate for postscript output (default 0 degrees).",
30 " ",
31 NULL
32 };
33
34 int main(int argc, char** argv)
35 {
36 // Initialize variables
37 double scale = 200; // Postscript output scale
38 double angle(0); // Angle to rotate the tree
39
40 int optind;
41 Boption* option = get_option_list(use, argc, argv, optind);
42 Boption* curropt;
43 for ( curropt = option; curropt; curropt = curropt->next ) {
44 if ( curropt->tag == "scale" )
45 if ( ( scale = curropt->value.real() ) < 0.0001 )
46 cerr << "-scale: A scale must be specified" << endl;
47 if ( curropt->tag == "rotate" ) {
48 if ( ( angle = curropt->value.real() ) < 1 )
49 cerr << "-rotate: An angle must be specified" << endl;
50 else
51 if ( angle > M_PI || angle < -M_PI ) angle *= M_PI/180;
52 }
53 }
54 option_kill(option);
55
56 double ti = timer_start();
57
58 Bnode* root = read_tree(argv[optind++]);
59
60 if ( angle != 0 ) tree_rotate(root, angle);
61
62 Bstring output;
63 if ( optind < argc ) {
64 output = argv[optind];
65 ps_draw_tree(output, root, scale);
66 }
67
68 tree_delete_node(root);
69
70 if ( verbose & VERB_TIME )
71 timer_report(ti);
72
73 bexit(0);
74 }
75
Bstring::real
double real()
Definition: Bstring.cpp:545
read_tree
Bnode * read_tree(char *filename)
Reads a phylip format tree file.
Definition: rwtree.cpp:23
verbose
int verbose
tree_delete_node
int tree_delete_node(Bnode *node)
Deletes a node with all daughter nodes.
Definition: rwtree.cpp:160
utilities.h
Header file for general utilities.
ps_draw_tree
int ps_draw_tree(Bstring &filename, Bnode *root, float scale)
Draws a tree into a postscript file.
Definition: ps_tree.cpp:28
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
tree_rotate
int tree_rotate(Bnode *node, float angle)
Adds an angle to all nodes.
Definition: rwtree.cpp:184
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
timer.h
Utilities for timing functions.
M_PI
#define M_PI
Definition: utilities.h:59
rwtree.h
Header file for reading (and writing) trees.
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
main
int main(int argc, char **argv)
Definition: btree.cpp:34
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bnode
Definition: rwtree.h:24
options.h
Header file for option handlers.
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
ps_tree.h
Header file for writing a tree into a postcsript file.
use
const char * use[]
Definition: btree.cpp:19