32 bool add_branch_length;
35 bool replace_problem_chars;
38 static inline const char *getarg(
int& argc,
const char**& argv) {
39 return argc>0 ? (--argc,*argv++) :
NULp;
41 inline const char *expect_arg(
int& argc,
const char**& argv) {
42 const char *arg = getarg(argc, argv);
44 error =
"expected argument missing";
49 inline LabelQuoting parse_quoting_mode(
int& argc,
const char**& argv) {
50 const char *quoting_mode_str= expect_arg(argc, argv);
51 if (strcasecmp(quoting_mode_str,
"none") == 0) {
53 }
else if (strcasecmp(quoting_mode_str,
"single") == 0) {
55 }
else if (strcasecmp(quoting_mode_str,
"double") == 0) {
63 void parse(
int& argc,
const char**& argv) {
64 const char *arg = getarg(argc, argv);
66 if (strcmp(arg,
"--db") == 0) database = expect_arg(argc, argv);
67 else if (strcmp(arg,
"--tree") == 0) tree = expect_arg(argc, argv);
68 else if (strcmp(arg,
"--newick-file") == 0) newick_file = expect_arg(argc, argv);
69 else if (strcmp(arg,
"--leaf-aci") == 0) leaf_aci = expect_arg(argc, argv);
70 else if (strcmp(arg,
"--quoting") == 0) quoting_mode = parse_quoting_mode(argc, argv);
71 else if (strcmp(arg,
"--add-branch-lengths") == 0) add_branch_length =
true;
72 else if (strcmp(arg,
"--add-bootstraps") == 0) add_bootstraps =
true;
73 else if (strcmp(arg,
"--add-group-names") == 0) add_group_names =
true;
74 else if (strcmp(arg,
"--replace-problem-chars") == 0) replace_problem_chars =
true;
75 else if (strcmp(arg,
"--pretty") == 0) pretty =
true;
76 else if (strcmp(arg,
"--help") == 0) helpWanted =
true;
82 void check_required_arguments() {
83 if (database.empty()) error =
"no input database specified";
84 else if (tree.empty()) error =
"no tree name specified";
85 else if (newick_file.empty()) error =
"no output file specified";
89 CLI(
int argc,
const char **argv) :
92 leaf_aci(
"readdb(\"name\")"),
94 add_branch_length(
false),
95 add_bootstraps(
false),
96 add_group_names(
false),
97 replace_problem_chars(
false),
102 while (!error && argc>0 && !helpWanted) {
108 check_required_arguments();
109 if (error) helpWanted =
true;
116 "arb_export_newick -- export a tree in newick format\n"
117 "Usage: arb_export_newick [switches]\n"
119 "mandatory arguments:\n"
120 "--db <dbname> ARB database to export from\n"
121 "--tree <treename> name of the tree to export\n"
122 "--newick-file <outname> name of generated newick file\n"
125 "--leaf-aci <aci> specify content for the leaf names using ACI\n"
126 " (default: \"readdb(name)\"; see http://help.arb-home.de/aci.html)\n"
127 "--quoting <mode> none, single, double. Single and double are forced.\n"
129 "--add-branch-lengths add the branch lengths to the newick file.\n"
130 " (default: branch lengths are omitted)\n"
131 "--add-bootstraps add the bootstrap values to the newick file.\n"
132 " (default: bootstrap values are omitted)\n"
133 "--add-group-names add the group names to the newick file.\n"
134 " (default: group names are omitted)\n"
135 "--replace-problem-chars problematic characters in names will be replaced\n"
136 " (default: no characters are replaced)\n"
137 "--pretty prettify the newick tree\n"
138 " (default: tree is not prettified)\n"
139 "--help show this help message\n"
148 const char *
get_tree()
const {
return tree.c_str(); }
162 SmartCharPtr leaf_aci;
165 explicit ACI_Labeler(
const char *leaf_aci_) : leaf_aci(strdup(leaf_aci_)) {}
182 return innerNode->
name;
224 int main(
int argc,
char **argv) {
226 CLI args(argc, const_cast<const char**>(argv));
237 fprintf(stderr,
"Error: %s\n", error);
const char * speciesLabel(GBDATA *gb_main, GBDATA *gb_species, TreeNode *, 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()
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
static void error(const char *msg)
bool shall_add_bootstraps() const
const char * get_database() const
#define RETURN_LOCAL_ALLOC(mallocation)
static SearchTree * tree[SEARCH_PATTERNS]
GB_ERROR TREE_write_Newick(GBDATA *gb_main, const char *tree_name, const TreeLabeler &labeler, bool save_branchlengths, bool save_bootstraps, bool save_groupnames, bool pretty, LabelQuoting quoteMode, const char *path)
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)