32 bool add_branch_length;
34 bool force_bootstraps;
37 bool replace_problem_chars;
40 static inline const char *getarg(
int& argc,
const char**& argv) {
41 return argc>0 ? (--argc,*argv++) :
NULp;
43 inline const char *expect_arg(
int& argc,
const char**& argv) {
44 const char *arg = getarg(argc, argv);
46 error =
"expected argument missing";
51 inline LabelQuoting parse_quoting_mode(
int& argc,
const char**& argv) {
52 const char *quoting_mode_str= expect_arg(argc, argv);
53 if (strcasecmp(quoting_mode_str,
"none") == 0) {
55 }
else if (strcasecmp(quoting_mode_str,
"single") == 0) {
57 }
else if (strcasecmp(quoting_mode_str,
"double") == 0) {
65 void parse(
int& argc,
const char**& argv) {
66 const char *arg = getarg(argc, argv);
68 if (strcmp(arg,
"--db") == 0) database = expect_arg(argc, argv);
69 else if (strcmp(arg,
"--tree") == 0) tree = expect_arg(argc, argv);
70 else if (strcmp(arg,
"--newick-file") == 0) newick_file = expect_arg(argc, argv);
71 else if (strcmp(arg,
"--leaf-aci") == 0) leaf_aci = expect_arg(argc, argv);
72 else if (strcmp(arg,
"--quoting") == 0) quoting_mode = parse_quoting_mode(argc, argv);
73 else if (strcmp(arg,
"--add-branch-lengths") == 0) add_branch_length =
true;
74 else if (strcmp(arg,
"--add-bootstraps") == 0) add_bootstraps =
true;
75 else if (strcmp(arg,
"--add-custom-remarks") == 0) add_remarks =
true;
76 else if (strcmp(arg,
"--force-bootstraps") == 0) force_bootstraps =
true;
77 else if (strcmp(arg,
"--add-group-names") == 0) add_group_names =
true;
78 else if (strcmp(arg,
"--replace-problem-chars") == 0) replace_problem_chars =
true;
79 else if (strcmp(arg,
"--pretty") == 0) pretty =
true;
80 else if (strcmp(arg,
"--help") == 0) helpWanted =
true;
86 void check_required_arguments() {
87 if (database.empty()) error =
"no input database specified";
88 else if (tree.empty()) error =
"no tree name specified";
89 else if (newick_file.empty()) error =
"no output file specified";
93 CLI(
int argc,
const char **argv) :
96 leaf_aci(
"readdb(\"name\")"),
98 add_branch_length(
false),
99 add_bootstraps(
false),
100 force_bootstraps(
false),
102 add_group_names(
false),
103 replace_problem_chars(
false),
108 while (!error && argc>0 && !helpWanted) {
114 check_required_arguments();
115 if (error) helpWanted =
true;
119 if (force_bootstraps) add_bootstraps =
true;
124 "arb_export_newick -- export a tree in newick format\n"
125 "Usage: arb_export_newick [switches]\n"
127 "mandatory arguments:\n"
128 "--db <dbname> ARB database to export from\n"
129 "--tree <treename> name of the tree to export\n"
130 "--newick-file <outname> name of generated newick file\n"
133 "--leaf-aci <aci> specify content for the leaf names using ACI\n"
134 " (default: \"readdb(name)\"; see http://help.arb-home.de/aci.html)\n"
135 "--quoting <mode> none, single, double. Single and double are forced.\n"
137 "--add-branch-lengths add the branch lengths to the newick file.\n"
138 " (default: branch lengths are omitted)\n"
139 "--add-bootstraps add the bootstrap values to the newick file.\n"
140 " (default: bootstrap values are omitted)\n"
141 "--force-bootstraps for branches without bootstrap values always save 100%\n"
142 " (implies: --add-bootstraps)\n"
143 "--add-custom-remarks add the custom remarks to the newick file.\n"
144 " (default: custom remarks are omitted)\n"
145 "--add-group-names add the group names to the newick file.\n"
146 " (default: group names are omitted)\n"
147 "--replace-problem-chars problematic characters in names will be replaced\n"
148 " (default: no characters are replaced)\n"
149 "--pretty prettify the newick tree\n"
150 " (default: tree is not prettified)\n"
151 "--help show this help message\n"
160 const char *
get_tree()
const {
return tree.c_str(); }
169 if (add_bootstraps) {
176 else if (add_bootstraps) {
190 SmartCharPtr leaf_aci;
193 explicit ACI_Labeler(
const char *leaf_aci_) : leaf_aci(strdup(leaf_aci_)) {}
196 if (!gb_species)
return leafNode->name;
211 return innerNode->
name;
253 int main(
int argc,
char **argv) {
255 CLI args(argc, const_cast<const char**>(argv));
266 fprintf(stderr,
"Error: %s\n", error);
const char * speciesLabel(GBDATA *gb_main, GBDATA *gb_species, TreeNode *leafNode, const char *tree_name) const OVERRIDE
GBDATA * GB_open(const char *path, const char *opent)
const char * groupLabel(GBDATA *, GBDATA *, TreeNode *innerNode, const char *) const
GB_ERROR GB_incur_error()
BootstrapSaveStyle shall_add_bootstraps() const
LabelQuoting get_quoting_mode() const
const char * GBS_global_string(const char *templat,...)
bool shall_replace_problem_chars() const
const char * get_leaf_aci() const
GB_ERROR GB_export_error(const char *error)
GB_ERROR GB_await_error()
bool shall_add_branch_length() const
const char * get_tree() const
GB_ERROR TREE_write_Newick(GBDATA *gb_main, const char *tree_name, const TreeLabeler &labeler, bool save_branchlengths, BootstrapSaveStyle bootstrap_style, bool save_groupnames, bool pretty, LabelQuoting quoteMode, const char *path)
static void error(const char *msg)
const char * get_database() const
#define RETURN_LOCAL_ALLOC(mallocation)
static SearchTree * tree[SEARCH_PATTERNS]
int main(int argc, char **argv)
fputs(TRACE_PREFIX, stderr)
bool shall_add_group_names() const
CLI(int argc, const char **argv)
bool shall_be_pretty() const
ACI_Labeler(const char *leaf_aci_)
NOT4PERL char * GB_command_interpreter_in_env(const char *str, const char *commands, const GBL_call_env &callEnv)
const char * get_newick_file() const
GB_ERROR get_error() const
void ARB_redirect_handlers_to(FILE *errStream, FILE *outStream)
char * GBS_global_string_copy(const char *templat,...)
void GB_close(GBDATA *gbd)
static GB_ERROR export_newick(const CLI &args)