1 /*********************************************************************
2 * Clustal Omage - Multiple sequence alignment
4 * Copyright (C) 2010 University College Dublin
6 * Clustal-Omega is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This file is part of Clustal-Omega.
13 ********************************************************************/
16 * RCS $Id: main.cpp 234 2011-04-13 05:26:16Z andreas $
20 * We are using a mix of C and C++, which means that linking has to be
21 * done with a C++ compiler. By using this "fake" main c++ function,
22 * automake is convinced to use a C++ compiler for linking.
36 #include "clustal/util.h"
37 #include "squid/squid.h"
42 * @brief Convert an old Clustal command line parameter in the form of
43 * [-/]param[=value] to new parameter if possible
45 * @param[out] iNewArgC_p
46 * "argc" which will be incremented for each successfully converted option
47 * @param[out] ppcNewArgV_p
48 * "argv" to which each successfully converted options will be added
49 * (caller has to free)
51 * The old parameter and value command line option
55 ConvertOldCmdLineArg(int *iNewArgC_p, char ***ppcNewArgV_p, char *pcOldArg)
57 char *pcOldParam, *pcOldValue, *pcOldArgCopy;
58 char zcNotImplementedMsg[] = "WARNING: Invalid old command line option";
60 pcOldArgCopy = CkStrdup(pcOldArg);
61 pcOldParam = strtok(pcOldArgCopy, "=");
62 pcOldValue = strtok(NULL, "=");
65 /* go through all options in order of appearance in clustalw2 -help
72 if (STR_NC_EQ("INFILE", &pcOldParam[1])) {
73 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-i");
74 if (NULL != pcOldValue)
75 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
77 } else if (STR_NC_EQ("PROFILE1", &pcOldParam[1])) {
78 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--profile1");
79 if (NULL != pcOldValue)
80 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
82 } else if (STR_NC_EQ("PROFILE2", &pcOldParam[1])) {
83 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--profile2");
84 if (NULL != pcOldValue)
85 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
95 } else if (STR_NC_EQ("HELP", &pcOldParam[1])
96 || STR_NC_EQ("CHECK", &pcOldParam[1])) {
97 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-h");
99 } else if (STR_NC_EQ("FULLHELP", &pcOldParam[1])) {
100 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-h");
102 } else if (STR_NC_EQ("ALIGN", &pcOldParam[1])) {
103 char msg[] = "WARNING: The ALIGN option is default in Clustal Omega";
104 fprintf(stderr, "%s\n", msg);
116 } else if (STR_NC_EQ("INTERACTIVE", &pcOldParam[1])) {
117 char msg[] = "WARNING: There is no interactive command-line menu in Clustal Omega";
118 fprintf(stderr, "%s\n", msg);
120 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-h");
122 } else if (STR_NC_EQ("QUICKTREE", &pcOldParam[1])) {
123 char msg[] = "WARNING: The QUICKTREE (i.e. k-tuple distance) option is default in Clustal Omega";
124 fprintf(stderr, "%s\n", msg);
126 } else if (STR_NC_EQ("TYPE", &pcOldParam[1])) {
127 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-t");
128 if (NULL != pcOldValue)
129 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
133 } else if (STR_NC_EQ("OUTFILE", &pcOldParam[1])) {
134 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-o");
135 if (NULL != pcOldValue)
136 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
139 } else if (STR_NC_EQ("OUTPUT", &pcOldParam[1])) {
140 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--outfmt");
141 if (NULL != pcOldValue)
142 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
152 } else if (STR_NC_EQ("MAXSEQLEN", &pcOldParam[1])) {
153 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--maxseqlen");
154 if (NULL != pcOldValue)
155 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
157 } else if (STR_NC_EQ("QUIET", &pcOldParam[1])) {
158 char msg[] = "WARNING: The QUIET option is default in Clustal Omega";
159 fprintf(stderr, "%s\n", msg);
165 /* fast pariwise alignment
177 /* slow pairwise alignments
188 /* multiple alignments
191 } else if (STR_NC_EQ("NEWTREE", &pcOldParam[1])) {
192 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--guidetree-out");
193 if (NULL != pcOldValue)
194 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
196 } else if (STR_NC_EQ("USETREE", &pcOldParam[1])) {
197 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--guidetree-in");
198 if (NULL != pcOldValue)
199 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
212 * TYPE already handled above
219 /* profile alignments
231 /* sequence to profile alignments
234 } else if (STR_NC_EQ("SEQUENCES", &pcOldParam[1])) {
235 fprintf(stderr, "WARNING: %s: %s\n", zcNotImplementedMsg, pcOldArg);
237 /* SEQUENCES and NEWTREE already handled above */
239 /* structure alignments
269 } else if (STR_NC_EQ("CLUSTERING", &pcOldParam[1])) {
270 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-c");
271 if (NULL != pcOldValue)
272 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(pcOldValue);
277 "WARNING: Unsupported old command line option '%s' will be ignored\n",
281 /* FIXME: if not outfile was given, than the old default was to create a
282 * filename based on the input filename but with its extension replaced by
283 * aln. If the input already had the extension aln then the input was
284 * overwritten. What to do here? Strictly mimic the old behaviour?
289 /* end ConvertOldCmdLineArg */
294 * @brief Convert old command line usage to new one. Mix of old and
295 * new style will be tolerated
297 * @param[out] iNewArgC_p
299 * @param[out] ppcNewArgV_p
300 * The updated "argv". Caller has to free.
306 * @note old style parameters look like this:
308 * new style parameters:
314 ConvertOldCmdline(int *iNewArgC_p, char ***ppcNewArgV_p, int argc, char **argv)
316 bool bOldCmdlineDetected = false;
319 /* we can have at most 2*argc converted arguments, plus the few
320 * that we set by default (.e.g --force)
322 (*ppcNewArgV_p) = (char **) CKCALLOC(argc*2+10, sizeof(char*));
324 /* copy first arg which is program name */
325 (*ppcNewArgV_p)[0] = CkStrdup(argv[0]);
328 for (i=1; i<argc; i++) {
329 bool bNewStyle = false;
331 if (strlen(argv[i])<=2) {
332 /* e.g. -i (param) or just numbers (value) */
335 } else if (strlen(argv[i])>2) {
336 if (argv[i][0] == '-' && argv[i][1] == '-') {
337 /* new style long opts */
340 } else if (argv[i][0]=='/' && (NULL!=strchr(&argv[i][1], '/'))) {
341 /* Slash used to be a valid replacement for dash in
342 * Clustal<=2, but could also be file in new style. If
343 * we find at least two slashes, one at the beginning,
344 * it should be a filename and therefore new style */
347 } else if (argv[i][0] != '/' && argv[i][0] != '-') {
348 /* old style opts always start with slash or dash */
354 /* copy and continue if new style arg or attempt to convert
358 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup(argv[i]);
360 ConvertOldCmdLineArg(iNewArgC_p, ppcNewArgV_p, argv[i]);
361 /*LOG_DEBUG("old command line arg: %s", argv[i]);*/
362 bOldCmdlineDetected = true;
366 if (bOldCmdlineDetected) {
367 bool bOutfileOptSet = FALSE;
368 bool bOutFormatOptSet = FALSE;
371 /* old clustal used to write to a file called in.aln by
372 * default. set if not
373 * explicitely requested otherwisee
375 for (i=0; i<*iNewArgC_p; i++) {
376 const char *pcOpt = "-o";
377 if (strlen(pcOpt) <= strlen((*ppcNewArgV_p)[i])) {
378 if (0 == strncmp((*ppcNewArgV_p)[i], pcOpt, strlen(pcOpt))) {
379 bOutfileOptSet = TRUE;
384 if (FALSE == bOutfileOptSet) {
385 #ifdef TOO_LAZY_TO_IMPLEMENT_JUST_USING_DEFAULT_NAME_INSTEAD
386 char *pcDotPos = NULL;
387 char *pcInfileOpt = NULL;
389 /* get infile arg and find last dot in it. if found replace
390 * everything after with "aln", otherwise just add "aln"
392 for (i=0; i<*iNewArgC_p; i++) {
393 const char *pcOpt = "-i";
394 if (strlen(pcOpt) <= strlen((*ppcNewArgV_p)[i])) {
395 if (0 == strncmp((*ppcNewArgV_p)[i], pcOpt, strlen(pcOpt))) {
396 if (*iNewArgC_p<= i+1) {
398 "Oups...error while trying to convert old commandline (%s).\n",
399 "No more arguments left after -i");
402 pcInfileOpt = (*ppcNewArgV_p)[i+1];
407 if (NULL == pcInfileOpt) {
409 "Oups...error while trying to convert old commandline (%s)\n",
410 "No infile opt found");
414 fprintf(stderr, "FIXME: unfinished\n");
417 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-o");
418 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("clustal.aln");
422 /* old clustal used the clustal format by default. set if not
423 * explicitely requested otherwisee
425 for (i=0; i<*iNewArgC_p; i++) {
426 const char *pcOpt = "--outfmt";
427 if (strlen(pcOpt) <= strlen((*ppcNewArgV_p)[i])) {
428 if (0 == strncmp((*ppcNewArgV_p)[i], pcOpt, strlen(pcOpt))) {
429 bOutFormatOptSet = TRUE;
434 if (FALSE == bOutFormatOptSet) {
435 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--outfmt=clustal");
439 /* old clustal was verbose by default
441 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("-v");
443 /* old clustal used to overwrite files by default
445 (*ppcNewArgV_p)[(*iNewArgC_p)++] = CkStrdup("--force");
448 "WARNING: Your old-style command-line options were converted to: ");
449 for (i=0; i<*iNewArgC_p; i++) {
450 fprintf(stderr, " %s", (*ppcNewArgV_p)[i]);
452 fprintf(stderr, "\n");
456 /* end ConvertOldCmdline */
461 main(int argc, char **argv)
464 char **new_argv = NULL;
467 ConvertOldCmdline(&new_argc, &new_argv, argc, argv);
469 MyMain(new_argc, new_argv);
471 for (i=0; i<new_argc; i++) {