4 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.
13 #include "CommandLineParser.h"
14 #include "../substitutionMatrix/globalmatrix.h"
15 #include "general/Utility.h"
16 #include "general/statsObject.h"
25 CommandLineParser::CommandLineParser(StringArray* args, bool xmenus)
87 setSecStructOutput(-1),
106 // The rest of the variables are arrays!
109 clustalObj = new Clustal();
111 // selecting the size prevents the resizing of the vector which is expensive.
112 typeArg = new StringArray(3);
113 bootLabelsArg = new StringArray(3);
114 outOrderArg = new StringArray(3);
115 caseArg = new StringArray(3);
116 seqNoArg = new StringArray(3);
117 seqNoRangeArg = new StringArray(3);
118 scoreArg = new StringArray(3);
119 outputArg = new StringArray(7);
120 outputTreeArg = new StringArray(5);
121 outputSecStrArg = new StringArray(5);
122 cmdLineType = new StringArray(6);
123 clusterAlgorithm = new StringArray(3);
124 iterationArg = new StringArray(4);
126 params = new StringArray; // Wait until I need it!!!!!!!!!
127 paramArg = new StringArray;
129 catch(const exception &ex)
131 cerr << ex.what() << endl;
132 cerr << "Terminating program. Cannot continue" << std::endl;
136 (*typeArg)[0] = "protein";
137 (*typeArg)[1] = "dna";
140 (*bootLabelsArg)[0] = "node";
141 (*bootLabelsArg)[1] = "branch";
142 (*bootLabelsArg)[2] = "";
144 (*outOrderArg)[0] = "input";
145 (*outOrderArg)[1] = "aligned";
146 (*outOrderArg)[2] = "";
148 (*caseArg)[0] = "lower";
149 (*caseArg)[1] = "upper";
152 (*seqNoArg)[0] = "off";
153 (*seqNoArg)[1] = "on";
156 (*seqNoRangeArg)[0] = "off";
157 (*seqNoRangeArg)[1] = "on";
158 (*seqNoRangeArg)[2] = "";
160 (*scoreArg)[0] = "percent";
161 (*scoreArg)[1] = "absolute";
164 (*outputArg)[0] = "gcg";
165 (*outputArg)[1] = "gde";
166 (*outputArg)[2] = "pir";
167 (*outputArg)[3] = "phylip";
168 (*outputArg)[4] = "nexus";
169 (*outputArg)[5] = "fasta";
170 (*outputArg)[6] = "";
172 (*outputTreeArg)[0] = "nj";
173 (*outputTreeArg)[1] = "phylip";
174 (*outputTreeArg)[2] = "dist";
175 (*outputTreeArg)[3] = "nexus";
176 (*outputTreeArg)[4] = "";
178 (*outputSecStrArg)[0] = "structure";
179 (*outputSecStrArg)[1] = "mask";
180 (*outputSecStrArg)[2] = "both";
181 (*outputSecStrArg)[3] = "none";
182 (*outputSecStrArg)[4] = "";
184 (*cmdLineType)[0] = " ";
185 (*cmdLineType)[1] = "=n ";
186 (*cmdLineType)[2] = "=f ";
187 (*cmdLineType)[3] = "=string ";
188 (*cmdLineType)[4] = "=filename ";
189 (*cmdLineType)[5] = "";
191 (*clusterAlgorithm)[0] = "nj";
192 (*clusterAlgorithm)[1] = "upgma";
193 (*clusterAlgorithm)[2] = "";
195 (*iterationArg)[0] = "tree";
196 (*iterationArg)[1] = "alignment";
197 (*iterationArg)[2] = "none";
198 (*iterationArg)[3] = "";
201 pwUserMatrixName = "";
202 DNAUserMatrixName = "";
203 pwDNAUserMatrixName = "";
205 clustalTreeName = "";
213 // NOTE there were only 3 params for the last one, so I put in NULL for the 4th.
215 cmdLineFile[ctr++] = getCmdLineDataStruct("infile", &setInfile, FILARG, NULL);
216 cmdLineFile[ctr++] = getCmdLineDataStruct("profile1", &setProfile1, FILARG, NULL);
217 cmdLineFile[ctr++] = getCmdLineDataStruct("profile2", &setProfile2, FILARG, NULL);
218 cmdLineFile[ctr++] = getCmdLineDataStruct("", NULL, -1, NULL);
219 // FIXME: final ctr index is hardcoded in CommandLineParser
222 cmdLineVerb[ctr++] = getCmdLineDataStruct("help", &setHelp, NOARG, NULL);
223 cmdLineVerb[ctr++] = getCmdLineDataStruct("fullhelp", &setFullHelp, NOARG, NULL);
224 cmdLineVerb[ctr++] = getCmdLineDataStruct("quiet", &setQuiet, NOARG, NULL);
225 cmdLineVerb[ctr++] = getCmdLineDataStruct("check", &setHelp, NOARG, NULL);
226 cmdLineVerb[ctr++] = getCmdLineDataStruct("options", &setOptions, NOARG, NULL);
227 cmdLineVerb[ctr++] = getCmdLineDataStruct("align", &setAlign, NOARG, NULL);
228 cmdLineVerb[ctr++] = getCmdLineDataStruct("newtree", &setNewTree, FILARG, NULL);
229 cmdLineVerb[ctr++] = getCmdLineDataStruct("usetree", &setUseTree, FILARG, NULL);
230 cmdLineVerb[ctr++] = getCmdLineDataStruct("newtree1", &setNewTree1, FILARG, NULL);
231 cmdLineVerb[ctr++] = getCmdLineDataStruct("usetree1", &setUseTree1, FILARG, NULL);
232 cmdLineVerb[ctr++] = getCmdLineDataStruct("newtree2", &setNewTree2, FILARG, NULL);
233 cmdLineVerb[ctr++] = getCmdLineDataStruct("usetree2", &setUseTree2, FILARG, NULL);
234 cmdLineVerb[ctr++] = getCmdLineDataStruct("bootstrap", &setBootstrap, NOARG, NULL);
235 cmdLineVerb[ctr++] = getCmdLineDataStruct("tree", &setTree, NOARG, NULL);
236 cmdLineVerb[ctr++] = getCmdLineDataStruct("quicktree", &setQuickTree, NOARG, NULL);
237 cmdLineVerb[ctr++] = getCmdLineDataStruct("convert", &setConvert, NOARG, NULL);
238 cmdLineVerb[ctr++] = getCmdLineDataStruct("interactive", &setInteractive, NOARG, NULL);
239 cmdLineVerb[ctr++] = getCmdLineDataStruct("batch", &setBatch, NOARG, NULL);
240 // Mark change 16-feb-2007 I added options for doing LE and iteration
241 cmdLineVerb[ctr++] = getCmdLineDataStruct("iteration", &setDoIteration,
242 OPTARG, iterationArg);
243 cmdLineVerb[ctr++] = getCmdLineDataStruct("", NULL, -1, NULL);
244 // FIXME: final ctr index is hardcoded in CommandLineParser.h
246 // NOTE Start back here!!!!!!!!!!!!
248 cmdLinePara[ctr++] = getCmdLineDataStruct("type", &setType, OPTARG, typeArg);
249 cmdLinePara[ctr++] = getCmdLineDataStruct("profile", &setProfile, NOARG, NULL);
250 cmdLinePara[ctr++] = getCmdLineDataStruct("sequences", &setSequences, NOARG, NULL);
251 cmdLinePara[ctr++] = getCmdLineDataStruct("matrix", &setMatrix, FILARG, NULL);
252 cmdLinePara[ctr++] = getCmdLineDataStruct("dnamatrix", &setDNAMatrix, FILARG, NULL);
253 cmdLinePara[ctr++] = getCmdLineDataStruct("negative", &setNegative, NOARG, NULL);
254 cmdLinePara[ctr++] = getCmdLineDataStruct("noweights", &setNoWeights, NOARG, NULL);
255 cmdLinePara[ctr++] = getCmdLineDataStruct("gapopen", &setGapOpen, FLTARG, NULL);
256 cmdLinePara[ctr++] = getCmdLineDataStruct("gapext", &setGapExtend, FLTARG, NULL);
257 cmdLinePara[ctr++] = getCmdLineDataStruct("endgaps", &setUseEndGaps, NOARG, NULL);
258 cmdLinePara[ctr++] = getCmdLineDataStruct("nopgap", &setNoPGap, NOARG, NULL);
259 cmdLinePara[ctr++] = getCmdLineDataStruct("nohgap", &setNoHGap, NOARG, NULL);
260 cmdLinePara[ctr++] = getCmdLineDataStruct("novgap", &setNoVGap, NOARG, NULL);
261 cmdLinePara[ctr++] = getCmdLineDataStruct("hgapresidues", &setHGapRes, STRARG, NULL);
262 cmdLinePara[ctr++] = getCmdLineDataStruct("maxdiv", &setMaxDiv, INTARG, NULL);
263 cmdLinePara[ctr++] = getCmdLineDataStruct("gapdist", &setGapDist, INTARG, NULL);
264 cmdLinePara[ctr++] = getCmdLineDataStruct("pwmatrix", &setPWMatrix, FILARG, NULL);
265 cmdLinePara[ctr++] = getCmdLineDataStruct("pwdnamatrix", &setPWDNAMatrix, FILARG, NULL);
266 cmdLinePara[ctr++] = getCmdLineDataStruct("pwgapopen", &setPWGapOpen, FLTARG, NULL);
267 cmdLinePara[ctr++] = getCmdLineDataStruct("pwgapext", &setPWGapExtend, FLTARG, NULL);
268 cmdLinePara[ctr++] = getCmdLineDataStruct("ktuple", &setKtuple, INTARG, NULL);
269 cmdLinePara[ctr++] = getCmdLineDataStruct("window", &setWindow, INTARG, NULL);
270 cmdLinePara[ctr++] = getCmdLineDataStruct("pairgap", &setPairGap, INTARG, NULL);
271 cmdLinePara[ctr++] = getCmdLineDataStruct("topdiags", &setTopDiags, INTARG, NULL);
272 cmdLinePara[ctr++] = getCmdLineDataStruct("score", &setScore, OPTARG, scoreArg);
273 cmdLinePara[ctr++] = getCmdLineDataStruct("transweight", &setTransWeight, FLTARG, NULL);
274 cmdLinePara[ctr++] = getCmdLineDataStruct("seed", &setSeed, INTARG, NULL);
275 cmdLinePara[ctr++] = getCmdLineDataStruct("kimura", &setKimura, NOARG, NULL);
276 cmdLinePara[ctr++] = getCmdLineDataStruct("tossgaps", &setTossGaps, NOARG, NULL);
277 cmdLinePara[ctr++] = getCmdLineDataStruct("bootlabels", &setBootLabels, OPTARG,
279 cmdLinePara[ctr++] = getCmdLineDataStruct("debug", &setDebug, INTARG, NULL);
280 cmdLinePara[ctr++] = getCmdLineDataStruct("output", &setOutput, OPTARG, outputArg);
281 cmdLinePara[ctr++] = getCmdLineDataStruct("outputtree", &setOutputTree, OPTARG,
283 cmdLinePara[ctr++] = getCmdLineDataStruct("outfile", &setOutfile, FILARG, NULL);
284 cmdLinePara[ctr++] = getCmdLineDataStruct("outorder", &setOutOrder, OPTARG, outOrderArg);
285 cmdLinePara[ctr++] = getCmdLineDataStruct("case", &setCase, OPTARG, caseArg);
286 cmdLinePara[ctr++] = getCmdLineDataStruct("seqnos", &setSeqNo, OPTARG, seqNoArg);
287 cmdLinePara[ctr++] = getCmdLineDataStruct("seqno_range", &setSeqNoRange, OPTARG,
289 cmdLinePara[ctr++] = getCmdLineDataStruct("range", &setRange, STRARG, NULL);
290 cmdLinePara[ctr++] = getCmdLineDataStruct("nosecstr1", &setSecStruct1, NOARG, NULL);
291 cmdLinePara[ctr++] = getCmdLineDataStruct("nosecstr2", &setSecStruct2, NOARG, NULL);
292 cmdLinePara[ctr++] = getCmdLineDataStruct("secstrout", &setSecStructOutput, OPTARG,
294 cmdLinePara[ctr++] = getCmdLineDataStruct("helixgap", &setHelixGap, INTARG, NULL);
295 cmdLinePara[ctr++] = getCmdLineDataStruct("strandgap", &setStrandGap, INTARG, NULL);
296 cmdLinePara[ctr++] = getCmdLineDataStruct("loopgap", &setLoopGap, INTARG, NULL);
297 cmdLinePara[ctr++] = getCmdLineDataStruct("terminalgap", &setTerminalGap, INTARG, NULL);
298 cmdLinePara[ctr++] = getCmdLineDataStruct("helixendin", &setHelixEndIn, INTARG, NULL);
299 cmdLinePara[ctr++] = getCmdLineDataStruct("helixendout", &setHelixEndOut, INTARG, NULL);
300 cmdLinePara[ctr++] = getCmdLineDataStruct("strandendin", &setStrandEndIn, INTARG, NULL);
301 cmdLinePara[ctr++] = getCmdLineDataStruct("strandendout",&setStrandEndOut, INTARG, NULL);
302 // NOTE these one was added to test the new LE scoring and iterations
303 cmdLinePara[ctr++] = getCmdLineDataStruct("numiter",&setNumIterations, INTARG, NULL);
304 cmdLinePara[ctr++] = getCmdLineDataStruct("clustering", &setTreeAlgorithm, OPTARG,
306 cmdLinePara[ctr++] = getCmdLineDataStruct("maxseqlen", &setMaxSeqLen, INTARG, NULL);
307 cmdLinePara[ctr++] = getCmdLineDataStruct("stats", &setStatsFile, FILARG, NULL);
308 cmdLinePara[ctr++] = getCmdLineDataStruct("pim", &setOutputPim, NOARG, NULL);
309 cmdLinePara[ctr++] = getCmdLineDataStruct("", NULL, -1, NULL);
310 // FIXME: final ctr index is hardcoded in CommandLineParser
312 parseParams(args, xmenus);
315 CommandLineParser::~CommandLineParser()
317 // Free up menory used here!
318 // NOTE any dynamically allocated memory (new) must be deleted.
321 delete bootLabelsArg;
325 delete seqNoRangeArg;
328 delete outputTreeArg;
329 delete outputSecStrArg;
333 delete clusterAlgorithm;
337 void CommandLineParser::parseParams(StringArray* args, bool xmenus)
340 if(logObject && DEBUGLOG)
342 logObject->logMsg("Parsing Command line Parameters!\n");
348 //static int cl_error_code = 0;
349 //char path[FILENAMELEN];
352 bool doAlign, doConvert, doAlignUseOldTree, doGuideTreeOnly, doTreeFromAlign,
353 doBootstrap, doProfileAlign, doSomething;
355 if (!xmenus && userParameters->getDisplayInfo())
357 cout << std::endl << std::endl << std::endl;
358 cout << " CLUSTAL " << userParameters->getRevisionLevel()
359 << " Multiple Sequence Alignments" << std::endl << std::endl << std::endl;
362 doAlign = doConvert = doAlignUseOldTree = doGuideTreeOnly = doTreeFromAlign = false;
363 doBootstrap = doProfileAlign = doSomething = false;
365 numparams = checkParam(args, params, paramArg);
372 //**********************************************************************
373 //*** Note: This part of the code is to print out the options with ****
374 //*** their expected value types/ranges ****
375 //**********************************************************************
379 userParameters->setHelpFlag(true);
381 // gui will display help
382 // but parse rest of args anyway and don't return
384 clustalObj->getHelp('9');
389 if(setFullHelp != -1)
391 userParameters->setFullHelpFlag(true);
393 // gui will handle this
394 // but parse rest of args anyway and don't return
396 clustalObj->getFullHelp();
403 userParameters->setDisplayInfo(false);
404 utilityObject->beQuiet(true);
406 userParameters->setDisplayInfo(true);
407 utilityObject->beQuiet(false);
411 // need to check maxseqlen before reading input file
412 if (setMaxSeqLen != -1)
415 if(logObject && DEBUGLOG)
417 logObject->logMsg(" Setting max allowed sequence length.");
421 if((*paramArg)[setMaxSeqLen].length() > 0)
423 if (sscanf((*paramArg)[setMaxSeqLen].c_str(),"%d", &temp) != 1)
425 reportBadOptionAndExit("maxseqlen", "integer");
430 userParameters->setMaxAllowedSeqLength(temp);
434 cerr << "Cannot use a negative value for maximum sequence length. Using default" << std::endl;
439 if (setStatsFile != -1)
441 if((*paramArg)[setStatsFile].length() > 0)
443 statsObject->setEnabled(true);
444 statsObject->setStatsFile((*paramArg)[setStatsFile]);
449 if (setOutputPim != -1)
451 userParameters->setOutputPim(true);
455 /*if(setDoIteration != -1)
457 userParameters->setDoRemoveFirstIteration(true);
460 if(setDoIteration != -1)
463 if(logObject && DEBUGLOG)
465 logObject->logMsg(" Setting iteration parameter.");
468 if((*paramArg)[setDoIteration].length() > 0)
470 temp = findMatch((*paramArg)[setDoIteration], iterationArg, 3);
473 userParameters->setDoRemoveFirstIteration(TREE);
477 userParameters->setDoRemoveFirstIteration(ALIGNMENT);
481 userParameters->setDoRemoveFirstIteration(NONE);
485 cerr << "Unknown option for iteration. Setting to NONE" << std::endl;
486 userParameters->setDoRemoveFirstIteration(NONE);
493 if(logObject && DEBUGLOG)
495 logObject->logMsg("Displaying options!\n");
499 cout << "clustalw option list:-" << std::endl;
501 for (i = 0; cmdLineVerb[i].str[0] != '\0'; i++)
503 cout << "\t\t" << default_commandsep << cmdLineVerb[i].str
504 << (*cmdLineType)[cmdLineVerb[i].type];
506 if (cmdLineVerb[i].type == OPTARG)
508 if (cmdLineVerb[i].arg != NULL)
510 cout << "=" << cmdLineVerb[i].arg->at(0);
511 for(j = 1; j < (int)cmdLineVerb[i].arg->size() - 1; j++)
513 cout << " OR " << cmdLineVerb[i].arg->at(j);
519 for (i = 0; cmdLineFile[i].str[0] != '\0'; i++)
521 cout<<"\t\t" << default_commandsep << cmdLineFile[i].str
522 << (*cmdLineType)[cmdLineFile[i].type];
524 if (cmdLineFile[i].type == OPTARG)
526 if (cmdLineFile[i].arg != NULL)
529 cout << "=" << cmdLineFile[i].arg->at(0);
530 for(j = 1; j < (int)cmdLineFile[i].arg->size() - 1; j++)
532 cout << " OR " << cmdLineFile[i].arg->at(j);
538 for (i = 0; cmdLinePara[i].str[0] != '\0'; i++)
540 cout <<"\t\t" << default_commandsep << cmdLinePara[i].str
541 << (*cmdLineType)[cmdLinePara[i].type];
543 if (cmdLinePara[i].type == OPTARG)
545 if (cmdLinePara[i].arg != NULL)
548 cout << "=" << cmdLinePara[i].arg->at(0);
549 for(j = 1; j < (int)cmdLinePara[i].arg->size() - 1; j++)
551 cout << " OR " << cmdLinePara[i].arg->at(j);
561 //*****************************************************************************
562 // Check to see if sequence type is explicitely stated..override ************
563 // the automatic checking (DNA or Protein). /type=d or /type=p *************
564 //****************************************************************************
569 if(((*paramArg)[setType].length()) > 0)
571 temp = findMatch((*paramArg)[setType], typeArg, 2);
574 userParameters->setDNAFlag(false);
575 userParameters->setExplicitDNAFlag(true);
576 msg = "Sequence type explicitly set to Protein";
577 cout << msg << std::endl;
581 msg = "Sequence type explicitly set to DNA";
582 cout << msg << std::endl;
583 userParameters->setDNAFlag(true);
584 userParameters->setExplicitDNAFlag(true);
588 msg = "Unknown sequence type " + (*paramArg)[setType];
589 cerr << std::endl << msg << endl;
592 if(logObject && DEBUGLOG)
594 logObject->logMsg(msg);
601 //***************************************************************************
602 // check to see if 1st parameter does not start with '/' i.e. look for an *
603 // input file as first parameter. The input file can also be specified *
604 // by /infile=fname. *
605 //***************************************************************************
606 // JULIE - moved to checkParam()
607 // if(paramstr[0] != '/')
609 // strcpy(seqName, params[0]);
613 //*************************************************
614 // Look for /infile=file.ext on the command line *
615 //*************************************************
619 if((*paramArg)[setInfile].length() <= 0)
621 exitWithErrorMsg("Bad sequence file name");
623 userParameters->setSeqName((*paramArg)[setInfile]);
626 if(logObject && DEBUGLOG)
628 string msg = "Sequence file name (seqName) has been set to ";
629 msg += userParameters->getSeqName();
630 logObject->logMsg(msg);
635 // NOTE keep an eye on this part to see if it works.
636 if(userParameters->getSeqName() != "")
638 // NOTE I will need to cheack if it has been successful before setting
639 // doSomething to true.
641 code = clustalObj->commandLineReadSeq(1);
653 // NOTE call the other function to set the parameter values!!
656 //*********************************************************
657 // Look for /profile1=file.ext AND /profile2=file2.ext *
658 // You must give both file names OR neither. *
659 //********************************************************
662 if(setProfile1 != -1)
664 if((*paramArg)[setProfile1].length() <= 0)
666 exitWithErrorMsg("Bad profile 1 file name");
669 clustalObj->profile1Input((*paramArg)[setProfile1]);
672 if(setProfile2 != -1)
674 if((*paramArg)[setProfile2].length() <= 0)
676 exitWithErrorMsg("Bad profile 2 file name");
678 if(userParameters->getProfile1Empty())
680 exitWithErrorMsg("Only 1 profile file (profile 2) specified.");
683 clustalObj->profile2Input((*paramArg)[setProfile2]);
684 doSomething = doProfileAlign = true;
687 //************************************************************************
688 // Look for /tree or /bootstrap or /align or /usetree ******************
689 //************************************************************************
693 userParameters->setInteractive(false);
696 if (setInteractive != -1)
698 userParameters->setInteractive(true);
700 cout << "interactive menu: overriding " << default_commandsep << "quiet" << std::endl;
701 userParameters->setDisplayInfo(true);
702 utilityObject->beQuiet(false);
706 if (userParameters->getInteractive())
720 if(userParameters->getEmpty())
722 exitWithErrorMsg("Cannot draw tree. No input alignment file");
726 doTreeFromAlign = true;
730 if(setBootstrap != -1)
732 if(userParameters->getEmpty())
734 exitWithErrorMsg("Cannot bootstrap tree. No input alignment file");
739 // Check if there is anything in the string!
740 if((*paramArg)[setBootstrap].length() > 0)
742 if (sscanf((*paramArg)[setBootstrap].c_str(), "%d", &temp) != 1)
744 reportBadOptionAndExit("bootstrap", "integer");
749 userParameters->setBootNumTrials(temp);
757 if(userParameters->getEmpty())
759 exitWithErrorMsg("Cannot align sequences. No input file");
769 if(userParameters->getEmpty())
771 exitWithErrorMsg("Cannot convert sequences. No input file");
781 if(userParameters->getEmpty())
783 exitWithErrorMsg("Cannot align sequences. No input file");
787 if((*paramArg)[setUseTree].length() == 0)
789 exitWithErrorMsg("Cannot align sequences. No tree file specified");
793 phylipTreeName = (*paramArg)[setUseTree];
795 userParameters->setUseTreeFile(true);
796 doAlignUseOldTree = true;
802 if(userParameters->getEmpty())
804 exitWithErrorMsg("Cannot align sequences. No input file");
808 if((*paramArg)[setNewTree].length() == 0)
810 exitWithErrorMsg("Cannot align sequences. No tree file specified");
814 phylipTreeName = (*paramArg)[setNewTree];
816 userParameters->setNewTreeFile(true);
817 doGuideTreeOnly = true;
821 if(setUseTree1 != -1)
823 if(userParameters->getProfile1Empty())
825 exitWithErrorMsg("Cannot align profiles. No input file");
827 else if(profileType == SEQUENCE)
829 reportInvalidOptionAndExit("usetree1");
833 if((*paramArg)[setUseTree1].length() == 0)
835 exitWithErrorMsg("Cannot align profiles. No tree file specified");
839 p1TreeName = (*paramArg)[setUseTree1];
841 userParameters->setUseTree1File(true);
842 doAlignUseOldTree = true;
846 if(setNewTree1 != -1)
848 if(userParameters->getProfile1Empty())
850 exitWithErrorMsg("Cannot align profiles. No input file");
852 else if(profileType == SEQUENCE)
854 reportInvalidOptionAndExit("newtree1");
858 if((*paramArg)[setNewTree1].length() == 0)
860 exitWithErrorMsg("Cannot align profiles. No tree file specified");
864 p1TreeName = (*paramArg)[setNewTree1];
866 userParameters->setNewTree1File(true);
870 if(setUseTree2 != -1)
872 if(userParameters->getProfile2Empty())
874 exitWithErrorMsg("Cannot align profiles. No input file");
876 else if(profileType == SEQUENCE)
878 reportInvalidOptionAndExit("usetree2");
882 if((*paramArg)[setUseTree2].length() == 0)
884 exitWithErrorMsg("Cannot align profiles. No tree file specified");
888 p2TreeName = (*paramArg)[setUseTree2];
890 userParameters->setUseTree2File(true);
891 doAlignUseOldTree = true;
895 if(setNewTree2 != -1)
897 if(userParameters->getProfile2Empty())
899 exitWithErrorMsg("Cannot align profiles. No input file");
901 else if(profileType == SEQUENCE)
903 reportInvalidOptionAndExit("newtree2");
907 if((*paramArg)[setNewTree2].length() == 0)
909 exitWithErrorMsg("Cannot align profiles. No tree file specified");
913 p2TreeName = (*paramArg)[setNewTree2];
915 userParameters->setNewTree2File(true);
920 if( (!doTreeFromAlign) && (!doBootstrap) && (!userParameters->getEmpty()) && (!doProfileAlign) &&
921 (!doAlignUseOldTree) && (!doGuideTreeOnly) && (!doConvert))
927 if(setQuickTree != -1)
929 userParameters->setQuickPairAlign(true);
933 if(userParameters->getDNAFlag())
935 userParameters->setDNAParams();
939 userParameters->setProtParams();
942 if(userParameters->getInteractive())
946 userParameters->setMenuFlag(true);
954 exitWithErrorMsg("No input file(s) specified");
960 //***************************************************************************
961 // Now do whatever has been requested ***************************************
962 //***************************************************************************
963 // NOTE This part is obviously not done yet! Functions not working in Clustal!!!!
965 if(logObject && DEBUGLOG)
967 logObject->logMsg("Now doing the requested task(s)");
974 if(logObject && DEBUGLOG)
976 logObject->logMsg(" Doing profile align");
979 if (profileType == PROFILE)
982 if(logObject && DEBUGLOG)
984 logObject->logMsg(" Calling Profile_align in clustal obj!");
987 clustalObj->profileAlign(&p1TreeName, &p2TreeName);
992 if(logObject && DEBUGLOG)
994 logObject->logMsg(" Calling sequencesAlignToProfile in clustal obj!");
997 clustalObj->sequencesAlignToProfile(&phylipTreeName);
1004 if(logObject && DEBUGLOG)
1006 logObject->logMsg(" Doing Alignment");
1009 clustalObj->align(&phylipTreeName);
1015 if(logObject && DEBUGLOG)
1017 logObject->logMsg(" Doing filetype conversion");
1020 clustalObj->outputNow();
1023 else if (doAlignUseOldTree)
1026 if(logObject && DEBUGLOG)
1028 logObject->logMsg(" Doing Alignment only");
1031 clustalObj->doAlignUseOldTree(&phylipTreeName);
1034 else if(doGuideTreeOnly)
1037 if(logObject && DEBUGLOG)
1039 logObject->logMsg(" Doing tree only");
1042 clustalObj->doGuideTreeOnly(&phylipTreeName);
1045 else if(doTreeFromAlign)
1048 if(logObject && DEBUGLOG)
1050 logObject->logMsg(" Doing tree");
1053 clustalObj->phylogeneticTree(&phylipTreeName, &clustalTreeName, &distTreeName,
1054 &nexusTreeName, pimName);
1057 else if(doBootstrap)
1060 if(logObject && DEBUGLOG)
1062 logObject->logMsg(" Doing Bootstrap");
1065 clustalObj->bootstrapTree(&phylipTreeName, &clustalTreeName, &nexusTreeName);
1074 int CommandLineParser::checkParam(StringArray* args, StringArray* params,
1075 StringArray* paramArg)
1077 int len, i, j, nameFirst, num;
1080 match.resize(MAXARGS);
1084 if(logObject && DEBUGLOG)
1086 logObject->logMsg("Checking Parameters!");
1090 if(args->size() == 0) // NOTE I think this will work better!
1092 cout << "The argument list is empty\n";
1096 // AW: first arg is an input file if it doesnt start with commandsep
1097 if (VALID_COMMAND_SEP.find((*args)[0][0], 0) == string::npos)
1100 params->push_back((*args)[0]); // Put the string at the back of this vector.
1101 paramArg->push_back(""); // Push a blank string onto the first element.
1103 else // It is not a file name
1105 params->push_back((*args)[0].substr(1));
1108 for (i = 1; i < (int)args->size(); i++)
1110 params->push_back(""); // Empty string!
1112 for(j = 0; j < (int)(*args)[i].length() - 1; j++)
1114 if(isprint((*args)[i][j + 1])) // Character printable?
1116 // We start at j + 1 because each option should begin with commandsep
1117 (*params)[i].append((*args)[i].substr(j + 1, 1));
1125 // params are now setup
1126 // extract paramArgs in next step
1129 if ((int)args->size() > MAXARGS)
1131 cerr << "Error: too many command line arguments\n";
1135 special case - first parameter is input fileName
1138 if(name1 == true) // If name of file is first argument
1140 userParameters->setSeqName((*params)[0]);
1141 /* Andreas Wilm (UCD) 2008-03-19:
1142 conversion nowadays unnecessary and makes trouble
1145 convert to lower case now
1148 if(logObject && DEBUGLOG)
1150 logObject->logMsg("Converting seqName to lower case.\n");
1152 string temp = ConvertStringToLower(userParameters->getSeqName());
1153 userParameters->setSeqName(temp);
1159 // NOTE if name first we should start at the 2nd element in paramArg
1160 // This loop is used to set up the paramArg vector!
1161 for (i = nameFirst; i < num; i++)
1164 paramArg->push_back(""); // Push a new empty string on.
1165 len = (*params)[i].length();
1166 for(j = 0; j < len; j++)
1168 if((*params)[i][j] == '=')
1171 (*paramArg)[i].assign((*params)[i].substr(j + 1, len - j -1));
1172 // Trim off the bit from the '=' to the end, and put all in lower case!
1173 (*params)[i].assign(ConvertStringToLower((*params)[i].substr(0, j)));
1177 // Andreas Wilm (UCD): 2008-03-19:
1178 // this convert nonarg params to lowercase (-QuIcKtReE etc)
1180 (*params)[i].assign(ConvertStringToLower((*params)[i]));
1184 if(paramArg->size() != params->size())
1186 cerr << "There is something wrong with arguments. Lengths different\n";
1191 for each parameter given on the command line, first search the list of recognised
1192 optional parameters....
1194 for (i = 0; i < num; i++)
1196 if ((i == 0) && (name1 == true))
1204 if (cmdLinePara[j].str[0] == '\0')
1206 // Think this means we have not found it!
1209 if (!(*params)[i].compare(cmdLinePara[j].str))
1211 match[i] = j; // Match has been found!
1212 *cmdLinePara[match[i]].flag = i;
1214 if ((cmdLinePara[match[i]].type != NOARG) && ((*paramArg)[i] == ""))
1216 cerr << "Error: parameter required for " << default_commandsep << (*params)[i] << endl;
1219 /* Andreas Wilm (UCD) 2008-03-19:
1220 * conversion nowadays unnecessary and breaks things
1223 * // convert parameters to lower case now, unless the parameter is a fileName
1225 * else if (cmdLinePara[match[i]].type != FILARG && (*paramArg)[i] != "")
1229 } else if (cmdLinePara[match[i]].type != FILARG && (*paramArg)[i] != "") {
1230 if ((*paramArg)[i] != "")
1232 // lowercase arg if not a filename to support mixed case
1233 (*paramArg)[i].assign(ConvertStringToLower((*paramArg)[i]));
1243 ....then the list of recognised input files,....
1245 for (i = 0; i < num; i++)
1247 if ((i == 0) && (name1 == true))
1258 if (cmdLineFile[j].str[0] == '\0')
1260 // Have not found a match!
1263 if (!(*params)[i].compare(cmdLineFile[j].str))
1266 *cmdLineFile[match[i]].flag = i;
1267 if ((cmdLineFile[match[i]].type != NOARG) &&
1268 ((*paramArg)[i] == ""))
1270 cerr << "Error: parameter required for " << default_commandsep << (*params)[i] << endl;
1280 ....and finally the recognised verbs.
1282 for (i = 0; i < num; i++)
1284 if ((i == 0) && (name1 == true))
1295 if (cmdLineVerb[j].str[0] == '\0')
1300 if (!(*params)[i].compare(cmdLineVerb[j].str))
1303 *cmdLineVerb[match[i]].flag = i;
1304 if ((cmdLineVerb[match[i]].type != NOARG) && ((*paramArg)[i] == ""))
1306 cerr << "Error: parameter required for " << default_commandsep << (*params)[i] << endl;
1316 check for any unrecognised parameters.
1318 for (i = 0; i < num; i++)
1322 cerr << "Error: unknown option " << default_commandsep << (*params)[i] << endl;
1329 void CommandLineParser::setOptionalParam()
1332 int _ktup, _windgap, _signif, _window = 0;
1339 if(logObject && DEBUGLOG)
1341 logObject->logMsg("Setting optional parameters.");
1344 //****************************************************************************
1345 //* look for parameters on command line e.g. gap penalties, k-tuple etc. *
1346 //****************************************************************************
1348 // Mark change 16-2-2007.
1350 if(setNumIterations != -1)
1353 if(logObject && DEBUGLOG)
1355 logObject->logMsg(" Setting num iterations parameter.");
1359 if((*paramArg)[setNumIterations].length() > 0)
1361 if (sscanf((*paramArg)[setNumIterations].c_str(),"%d", &temp) != 1)
1363 reportBadOptionAndExit("numiter", "int");
1369 userParameters->setNumIterations(temp);
1373 exitWithErrorMsg("Cannot use a negative value for number of iterations.");
1378 //** ? /score=percent or /score=absolute *
1381 if((*paramArg)[setScore].length() > 0)
1383 temp = findMatch((*paramArg)[setScore], scoreArg, 2);
1386 userParameters->setPercent(true);
1388 if(logObject && DEBUGLOG)
1390 logObject->logMsg(" Setting score parameter = percent");
1396 userParameters->setPercent(false);
1398 if(logObject && DEBUGLOG)
1400 logObject->logMsg(" Setting score parameter = absolute");
1406 cerr << "\nUnknown SCORE type: " << (*paramArg)[setScore] << endl;
1408 if(logObject && DEBUGLOG)
1410 logObject->logMsg(" problem setting score type!!!!!");
1416 // NOTE I decided to stay with sscanf for getting the int. Options in c++ no better.
1421 if(logObject && DEBUGLOG)
1423 logObject->logMsg(" Setting seed parameter.");
1427 if((*paramArg)[setSeed].length() > 0)
1429 if (sscanf((*paramArg)[setSeed].c_str(),"%d",&temp) != 1)
1431 reportBadOptionAndExit("seed", "integer");
1436 userParameters->setBootRanSeed(temp);
1438 cout<< "\ntemp = " << temp << "; seed = " << userParameters->getBootRanSeed()
1442 if(setTreeAlgorithm != -1)
1445 if(logObject && DEBUGLOG)
1447 logObject->logMsg(" Setting clustering algorithm parameter.");
1450 if((*paramArg)[setTreeAlgorithm].length() > 0)
1452 temp = findMatch((*paramArg)[setTreeAlgorithm], clusterAlgorithm, 2);
1455 userParameters->setClusterAlgorithm(NJ);
1459 userParameters->setClusterAlgorithm(UPGMA);
1463 cerr << "Unknown option for clustering algorithm. Using default\n";
1464 userParameters->setClusterAlgorithm(NJ);
1470 //** ? /output=PIR, GCG, GDE or PHYLIP *
1475 if(logObject && DEBUGLOG)
1477 logObject->logMsg(" Setting output parameter.");
1480 if((*paramArg)[setOutput].length() > 0)
1482 temp = findMatch((*paramArg)[setOutput], outputArg, 6);
1483 if (temp >= 0 && temp <= 5)
1485 userParameters->setOutputClustal(false);
1486 userParameters->setOutputGCG(false);
1487 userParameters->setOutputPhylip(false);
1488 userParameters->setOutputNbrf(false);
1489 userParameters->setOutputGde(false);
1490 userParameters->setOutputNexus(false);
1491 userParameters->setOutputFasta(false);
1496 userParameters->setOutputGCG(true);
1499 userParameters->setOutputGde(true);
1502 userParameters->setOutputNbrf(true);
1505 userParameters->setOutputPhylip(true);
1508 userParameters->setOutputNexus(true);
1511 userParameters->setOutputFasta(true);
1514 // FIXME AW: 1.83 behaves the same, but shouldnt
1516 exitWithErrorMsg("Unknown OUTPUT type: " + (*paramArg)[setOutput]);
1520 //** ? /outputtree=NJ or PHYLIP or DIST or NEXUS
1521 if(setOutputTree != -1)
1524 if(logObject && DEBUGLOG)
1526 logObject->logMsg(" Setting outputtree parameter.");
1529 if((*paramArg)[setOutputTree].length() > 0)
1531 temp = findMatch((*paramArg)[setOutputTree], outputTreeArg, 4);
1535 userParameters->setOutputTreeClustal(true);
1538 userParameters->setOutputTreePhylip(true);
1541 userParameters->setOutputTreeDistances(true);
1544 userParameters->setOutputTreeNexus(true);
1547 cerr << "\nUnknown OUTPUT TREE type: "
1548 << (*paramArg)[setOutputTree] << endl;
1553 //** ? /profile (sets type of second input file to profile)
1554 if(setProfile != -1)
1557 if(logObject && DEBUGLOG)
1559 logObject->logMsg(" Setting profileType = PROFILE.");
1562 profileType = PROFILE;
1565 //** ? /sequences (sets type of second input file to list of sequences)
1566 if(setSequences != -1)
1569 if(logObject && DEBUGLOG)
1571 logObject->logMsg(" Setting profileType = SEQUENCE.");
1574 profileType = SEQUENCE;
1582 if(logObject && DEBUGLOG)
1584 logObject->logMsg(" Setting ktup parameter.");
1588 if((*paramArg)[setKtuple].length() > 0)
1590 if (sscanf((*paramArg)[setKtuple].c_str(),"%d",&_ktup)!=1)
1592 reportBadOptionAndExit("ktuple", "integer");
1599 if(userParameters->getDNAFlag())
1603 userParameters->setKtup(_ktup);
1604 userParameters->setDNAKtup(_ktup);
1605 userParameters->setWindowGap(_ktup + 4);
1606 userParameters->setDNAWindowGap(_ktup + 4);
1608 // see comment in bug 185
1609 cerr << "WARNING: Ignoring invalid ktuple of " << _ktup << " (must be <=4)" << std::endl;
1616 userParameters->setKtup(_ktup);
1617 userParameters->setAAKtup(_ktup);
1618 userParameters->setWindowGap(_ktup + 3);
1619 userParameters->setAAWindowGap(_ktup + 3);
1620 // AW: why set setDNAWindowGap? we are in AA mode
1621 // userParameters->setDNAWindowGap(_ktup + 4);
1623 // see comment in bug 185
1624 cerr << "WARNING: Ignoring invalid ktuple of " << _ktup << " (must be <=2)" << std::endl;
1631 if(setPairGap != -1)
1634 if(logObject && DEBUGLOG)
1636 logObject->logMsg(" Setting pairgap parameter.");
1640 if((*paramArg)[setPairGap].length() > 0)
1642 if (sscanf((*paramArg)[setPairGap].c_str(),"%d",&_windgap)!=1)
1644 reportBadOptionAndExit("pairgap", "integer");
1649 if(userParameters->getDNAFlag())
1651 if(_windgap > userParameters->getKtup())
1653 userParameters->setWindowGap(_windgap);
1654 userParameters->setDNAWindowGap(_windgap);
1659 if(_windgap > userParameters->getKtup())
1661 userParameters->setWindowGap(_windgap);
1662 userParameters->setAAWindowGap(_windgap);
1670 if(setTopDiags != -1)
1673 if(logObject && DEBUGLOG)
1675 logObject->logMsg(" Setting topdiags parameter.");
1679 if((*paramArg)[setTopDiags].length() > 0)
1681 if (sscanf((*paramArg)[setTopDiags].c_str(),"%d",&_signif)!=1)
1683 reportBadOptionAndExit("topdiags", "integer");
1688 if(userParameters->getDNAFlag())
1690 if(_signif > userParameters->getKtup())
1692 userParameters->setSignif(_signif);
1693 userParameters->setDNASignif(_signif);
1698 if(_signif > userParameters->getKtup())
1700 userParameters->setSignif(_signif);
1701 userParameters->setAASignif(_signif);
1712 if(logObject && DEBUGLOG)
1714 logObject->logMsg(" Setting window parameter.");
1718 if((*paramArg)[setWindow].length() > 0)
1720 if (sscanf((*paramArg)[setWindow].c_str(),"%d",&_window)!=1)
1722 reportBadOptionAndExit("window", "integer");
1728 if(userParameters->getDNAFlag())
1730 if(_window > userParameters->getKtup())
1732 userParameters->setWindow(_window);
1733 userParameters->setDNAWindow(_window);
1738 if(_window > userParameters->getKtup())
1740 userParameters->setWindow(_window);
1741 userParameters->setAAWindow(_window);
1751 if(logObject && DEBUGLOG)
1753 logObject->logMsg(" Setting kimura=true");
1756 userParameters->setKimura(true);
1760 if(setTossGaps != -1)
1763 if(logObject && DEBUGLOG)
1765 logObject->logMsg(" Setting tossgaps=true");
1768 userParameters->setTossGaps(true);
1772 if(setNegative != -1)
1775 if(logObject && DEBUGLOG)
1777 logObject->logMsg(" Setting useNegMatrix=true");
1780 userParameters->setUseNegMatrix(true);
1784 if(setNoWeights!= -1)
1787 if(logObject && DEBUGLOG)
1789 logObject->logMsg(" Setting noweights=true");
1792 userParameters->setNoWeights(true);
1796 //** ? /pwmatrix=ID (user's file)
1797 if(setPWMatrix != -1)
1800 if(logObject && DEBUGLOG)
1802 logObject->logMsg(" Setting pwmatrix parameter.");
1805 temp = (*paramArg)[setPWMatrix].length();
1808 _matrixname = ConvertStringToLower((*paramArg)[setPWMatrix]);
1809 if (_matrixname.compare("blosum") == 0)
1811 subMatrix->setCurrentNameAndNum(_matrixname, 1, Protein, Pairwise);
1813 else if (_matrixname.compare("pam") == 0)
1815 subMatrix->setCurrentNameAndNum(_matrixname, 2, Protein, Pairwise);
1817 else if (_matrixname.compare("gonnet") == 0)
1819 subMatrix->setCurrentNameAndNum(_matrixname, 3, Protein, Pairwise);
1821 else if (_matrixname.compare("id") == 0)
1823 subMatrix->setCurrentNameAndNum(_matrixname, 4, Protein, Pairwise);
1827 char hackTempName[FILENAMELEN + 1];
1828 strcpy(hackTempName, (*paramArg)[setPWMatrix].c_str());
1830 if(subMatrix->getUserMatFromFile(hackTempName, Protein, Pairwise))
1832 subMatrix->setCurrentNameAndNum((*paramArg)[setPWMatrix], 5,
1834 pwUserMatrixName = (*paramArg)[setPWMatrix];
1843 //** ? /matrix=ID (user's file)
1847 if(logObject && DEBUGLOG)
1849 logObject->logMsg(" Setting matrix parameter.");
1852 temp = (*paramArg)[setMatrix].length();
1855 _matrixname = ConvertStringToLower((*paramArg)[setMatrix]);
1857 if (_matrixname.compare("blosum")==0)
1859 subMatrix->setCurrentNameAndNum(_matrixname, 1, Protein, MultipleAlign);
1861 else if (_matrixname.compare("pam")==0)
1863 subMatrix->setCurrentNameAndNum(_matrixname, 2, Protein, MultipleAlign);
1865 else if (_matrixname.compare("gonnet")==0)
1867 subMatrix->setCurrentNameAndNum(_matrixname, 3, Protein, MultipleAlign);
1869 else if (_matrixname.compare("id")==0)
1871 subMatrix->setCurrentNameAndNum(_matrixname, 4, Protein, MultipleAlign);
1875 char hackTempName[FILENAMELEN + 1];
1876 strcpy(hackTempName, (*paramArg)[setMatrix].c_str());
1878 if(subMatrix->getUserMatSeriesFromFile(hackTempName))
1880 subMatrix->setCurrentNameAndNum((*paramArg)[setMatrix], 4,
1881 Protein, MultipleAlign);
1882 userMatrixName = (*paramArg)[setMatrix];
1890 //** ? /pwdnamatrix=ID (user's file)
1891 if(setPWDNAMatrix != -1)
1894 if(logObject && DEBUGLOG)
1896 logObject->logMsg(" Setting pwdnamatrix parameter.");
1899 temp = (*paramArg)[setPWDNAMatrix].length();
1902 _matrixname = ConvertStringToLower((*paramArg)[setPWDNAMatrix]);
1904 if (_matrixname.compare("iub") == 0)
1906 subMatrix->setCurrentNameAndNum(_matrixname, 1, DNA, Pairwise);
1908 else if (_matrixname.compare("clustalw") == 0)
1910 subMatrix->setCurrentNameAndNum(_matrixname, 2, DNA, Pairwise);
1914 char hackTempName[FILENAMELEN + 1];
1915 strcpy(hackTempName, (*paramArg)[setPWDNAMatrix].c_str());
1917 if(subMatrix->getUserMatFromFile(hackTempName, DNA, Pairwise))
1919 subMatrix->setCurrentNameAndNum((*paramArg)[setPWDNAMatrix], 3,
1921 pwDNAUserMatrixName = (*paramArg)[setPWDNAMatrix];
1929 //** ? /dnamatrix=ID (user's file)
1930 if(setDNAMatrix != -1)
1933 if(logObject && DEBUGLOG)
1935 logObject->logMsg(" Setting dnamatrix parameter.");
1938 temp = (*paramArg)[setDNAMatrix].length();
1941 _matrixname = ConvertStringToLower((*paramArg)[setDNAMatrix]);
1943 if (_matrixname.compare("iub") == 0)
1945 subMatrix->setCurrentNameAndNum(_matrixname, 1, DNA, MultipleAlign);
1947 else if (_matrixname.compare("clustalw") == 0)
1949 subMatrix->setCurrentNameAndNum(_matrixname, 2, DNA, MultipleAlign);
1953 char hackTempName[FILENAMELEN + 1];
1954 strcpy(hackTempName, (*paramArg)[setDNAMatrix].c_str());
1956 if(subMatrix->getUserMatFromFile(hackTempName, DNA, MultipleAlign))
1958 subMatrix->setCurrentNameAndNum((*paramArg)[setDNAMatrix], 3,
1959 Protein, MultipleAlign);
1960 DNAUserMatrixName = (*paramArg)[setDNAMatrix];
1973 if(logObject && DEBUGLOG)
1975 logObject->logMsg(" Setting maxdiv parameter.");
1979 if((*paramArg)[setMaxDiv].length() > 0)
1981 if (sscanf((*paramArg)[setMaxDiv].c_str(),"%d",&temp)!=1)
1983 reportBadOptionAndExit("maxdiv", "integer");
1989 userParameters->setDivergenceCutoff(temp);
1994 if(setGapDist != -1)
1997 if(logObject && DEBUGLOG)
1999 logObject->logMsg(" Setting gapdist parameter.");
2004 if((*paramArg)[setGapDist].length() > 0)
2005 if (sscanf((*paramArg)[setGapDist].c_str(),"%d",&temp)!=1)
2007 reportBadOptionAndExit("gapdist", "integer");
2011 userParameters->setGapDist(temp);
2019 if((*paramArg)[setDebug].length() > 0)
2020 if (sscanf((*paramArg)[setDebug].c_str(),"%d",&temp)!=1)
2022 reportBadOptionAndExit("debug", "integer");
2026 userParameters->setDebug(temp);
2030 //** ? /outfile= (user's file)
2031 if(setOutfile != -1)
2034 if(logObject && DEBUGLOG)
2036 logObject->logMsg(" Setting outfile parameter.");
2039 if((*paramArg)[setOutfile].length() > 0)
2041 userParameters->setOutfileName((*paramArg)[setOutfile]);
2045 //*** ? /case= lower/upper
2049 if(logObject && DEBUGLOG)
2051 logObject->logMsg(" Setting case parameter.");
2054 if((*paramArg)[setCase].length() > 0)
2056 temp = findMatch((*paramArg)[setCase], caseArg, 2);
2059 userParameters->setLowercase(true);
2063 userParameters->setLowercase(false);
2067 cerr << "\nUnknown case " << (*paramArg)[setCase] << endl;
2072 //*** ? /seqnos=off/on
2076 if(logObject && DEBUGLOG)
2078 logObject->logMsg(" Setting seqnos parameter.");
2081 if((*paramArg)[setSeqNo].length() > 0)
2083 temp = findMatch((*paramArg)[setSeqNo], seqNoArg, 2);
2086 userParameters->setClSeqNumbers(false);
2090 userParameters->setClSeqNumbers(true);
2094 cerr << "\nUnknown SEQNO option " << (*paramArg)[setSeqNo] << endl;
2100 if(setSeqNoRange != -1)
2103 if(logObject && DEBUGLOG)
2105 logObject->logMsg(" Setting seqno range parameter.");
2108 if((*paramArg)[setSeqNoRange].length() > 0)
2110 temp = findMatch((*paramArg)[setSeqNoRange], seqNoRangeArg, 2);
2111 cout << "\n comparing "
2112 << "\nparamArg[setSeqNoRange]= " << (*paramArg)[setSeqNoRange]
2113 << "\n comparing \n ";
2117 userParameters->setSeqRange(false);
2121 userParameters->setSeqRange(true);
2125 cerr << "\nUnknown Sequence range option "
2126 << (*paramArg)[setSeqNoRange] << endl;
2135 if(logObject && DEBUGLOG)
2137 logObject->logMsg(" Setting range parameter.");
2141 if((*paramArg)[setRange].length() > 0)
2143 // NOTE I have made a big change here! Mark march 14th 2006. This was being done
2144 // in the Alignment output functions.
2149 if (sscanf((*paramArg)[setRange].c_str(), "%d%[ :,-]%d", &iFirstRes,
2150 &ignore, &iLastRes) != 3)
2152 cerr << "setRange: Syntax Error: Cannot set range, should be from:to \n";
2156 userParameters->setRangeFrom(iFirstRes);
2157 userParameters->setRangeTo(iLastRes);
2163 if(setGapOpen != -1)
2166 if(logObject && DEBUGLOG)
2168 logObject->logMsg(" Setting gapopen parameter.");
2172 if((*paramArg)[setGapOpen].length() > 0)
2174 if (sscanf((*paramArg)[setGapOpen].c_str(),"%f",&ftemp) != 1)
2176 reportBadOptionAndExit("gapopen", "real number");
2181 if( userParameters->getDNAFlag())
2183 userParameters->setGapOpen(ftemp);
2184 userParameters->setDNAGapOpen(ftemp);
2188 userParameters->setGapOpen(ftemp);
2189 userParameters->setProteinGapOpen(ftemp);
2196 if(setGapExtend != -1)
2199 if(logObject && DEBUGLOG)
2201 logObject->logMsg(" Setting gap extention parameter.");
2206 if((*paramArg)[setGapExtend].length() > 0)
2208 if (sscanf((*paramArg)[setGapExtend].c_str(),"%f",&ftemp) != 1)
2210 reportBadOptionAndExit("gapext", "real number");
2215 if(userParameters->getDNAFlag())
2217 userParameters->setGapExtend(ftemp);
2218 userParameters->setDNAGapExtend(ftemp);
2222 userParameters->setGapExtend(ftemp);
2223 userParameters->setProteinGapExtend(ftemp);
2229 //*** ? /transweight=n
2230 if(setTransWeight != -1)
2233 if(logObject && DEBUGLOG)
2235 logObject->logMsg(" Setting transweight parameter.");
2240 if((*paramArg)[setTransWeight].length() > 0)
2242 if (sscanf((*paramArg)[setTransWeight].c_str(), "%f", &ftemp) != 1)
2244 reportBadOptionAndExit("transweight", "real number");
2247 userParameters->setTransitionWeight(ftemp);
2250 //*** ? /pwgapopen=n
2251 if(setPWGapOpen != -1)
2254 if(logObject && DEBUGLOG)
2256 logObject->logMsg(" Setting pwgapopen parameter.");
2261 if((*paramArg)[setPWGapOpen].length() > 0)
2263 if (sscanf((*paramArg)[setPWGapOpen].c_str(), "%f", &ftemp) != 1)
2265 reportBadOptionAndExit("pwgapopen", "real number");
2270 if(userParameters->getDNAFlag())
2272 userParameters->setPWGapOpen(ftemp);
2273 userParameters->setDNAPWGapOpenPenalty(ftemp);
2277 userParameters->setPWGapOpen(ftemp);
2278 userParameters->setProteinPWGapOpenPenalty(ftemp);
2285 if(setPWGapExtend != -1)
2288 if(logObject && DEBUGLOG)
2290 logObject->logMsg(" Setting pwgapext parameter.");
2295 if((*paramArg)[setPWGapExtend].length() > 0)
2297 if (sscanf((*paramArg)[setPWGapExtend].c_str(), "%f", &ftemp) != 1)
2299 reportBadOptionAndExit("pwgapext", "real number");
2304 if(userParameters->getDNAFlag())
2306 userParameters->setPWGapExtend(ftemp);
2307 userParameters->setDNAPWGapExtendPenalty(ftemp);
2311 userParameters->setPWGapExtend(ftemp);
2312 userParameters->setProteinPWGapExtendPenalty(ftemp);
2320 if(setOutOrder != -1)
2323 if(logObject && DEBUGLOG)
2325 logObject->logMsg(" Setting outorder parameter.");
2329 if((*paramArg)[setOutOrder].length() > 0)
2331 temp = findMatch((*paramArg)[setOutOrder],outOrderArg,2);
2336 userParameters->setOutputOrder(INPUT);
2340 userParameters->setOutputOrder(ALIGNED);
2344 cerr << "\nUnknown OUTPUT ORDER type " << (*paramArg)[setOutOrder] << endl;
2348 //*** ? /bootlabels=n
2349 if(setBootLabels != -1)
2353 if(logObject && DEBUGLOG)
2355 logObject->logMsg(" Setting bootlabels parameter.");
2359 if((*paramArg)[setBootLabels].length() > 0)
2361 temp = findMatch((*paramArg)[setBootLabels], bootLabelsArg, 2);
2366 userParameters->setBootstrapFormat(BS_NODE_LABELS);
2370 userParameters->setBootstrapFormat(BS_BRANCH_LABELS);
2374 cerr << "\nUnknown bootlabels type " << (*paramArg)[setBootLabels] << endl;
2379 if(setUseEndGaps != -1)
2382 if(logObject && DEBUGLOG)
2384 logObject->logMsg(" Setting useendgaps=true");
2388 userParameters->setUseEndGaps(false);
2395 if(logObject && DEBUGLOG)
2397 logObject->logMsg(" Setting noPrefPenalties=true");
2401 userParameters->setNoPrefPenalties(true);
2408 if(logObject && DEBUGLOG)
2410 logObject->logMsg(" Setting nohgap=true");
2414 userParameters->setNoHydPenalties(true);
2421 if(logObject && DEBUGLOG)
2423 logObject->logMsg(" Setting novgap=false");
2427 userParameters->setNoVarPenalties(false);
2430 //*** ? /hgapresidues="string"
2431 // NOTE I have made some big changes here. It looks as if there was an error here!
2432 if(setHGapRes != -1)
2435 if(logObject && DEBUGLOG)
2437 logObject->logMsg(" Setting hgapresidues parameter.");
2441 userParameters->setHydResidues((*paramArg)[setHGapRes]);
2446 if(setSecStruct1 != -1)
2449 if(logObject && DEBUGLOG)
2451 logObject->logMsg(" Setting useSS1=false");
2455 userParameters->setUseSS1(false);
2459 if(setSecStruct2 != -1)
2462 if(logObject && DEBUGLOG)
2464 logObject->logMsg(" Setting useSS2=false");
2468 userParameters->setUseSS2(false);
2471 //*** ? /secstroutput
2472 if(setSecStructOutput != -1)
2475 if(logObject && DEBUGLOG)
2477 logObject->logMsg(" Setting secstroutput parameter.");
2481 if((*paramArg)[setSecStructOutput].length() > 0)
2483 temp = findMatch((*paramArg)[setSecStructOutput], outputSecStrArg, 4);
2484 if(temp >= 0 && temp <= 3)
2486 userParameters->setOutputStructPenalties(temp);
2490 cerr << "\nUnknown case " << (*paramArg)[setSecStructOutput] << endl;
2496 //*** ? /helixgap= n
2497 if(setHelixGap != -1)
2500 if(logObject && DEBUGLOG)
2502 logObject->logMsg(" Setting helixgap parameter.");
2507 if((*paramArg)[setHelixGap].length() > 0)
2509 if (sscanf((*paramArg)[setHelixGap].c_str(), "%d", &temp) != 1)
2511 reportBadOptionAndExit("helixgap", "integer");
2514 if (temp >= 1 && temp <= 9)
2516 userParameters->setHelixPenalty(temp);
2520 //*** ? /strandgap= n
2521 if(setStrandGap != -1)
2524 if(logObject && DEBUGLOG)
2526 logObject->logMsg(" Setting strandgap parameter.");
2531 if((*paramArg)[setStrandGap].length() > 0)
2533 if (sscanf((*paramArg)[setStrandGap].c_str(), "%d", &temp) != 1)
2535 reportBadOptionAndExit("strandgap", "integer");
2538 if (temp >= 1 && temp <= 9)
2540 userParameters->setStrandPenalty(temp);
2545 if(setLoopGap != -1)
2548 if(logObject && DEBUGLOG)
2550 logObject->logMsg(" Setting loopgap parameter.");
2555 if((*paramArg)[setLoopGap].length() > 0)
2557 if (sscanf((*paramArg)[setLoopGap].c_str(), "%d", &temp) != 1)
2559 reportBadOptionAndExit("loopgap", "integer");
2562 if (temp >= 1 && temp <= 9)
2564 userParameters->setLoopPenalty(temp);
2568 //*** ? /terminalgap= n
2569 if(setTerminalGap != -1)
2572 if(logObject && DEBUGLOG)
2574 logObject->logMsg(" Setting terminalgap parameter.");
2578 if((*paramArg)[setTerminalGap].length() > 0)
2580 if (sscanf((*paramArg)[setTerminalGap].c_str(), "%d", &temp) != 1)
2582 reportBadOptionAndExit("terminalgap", "integer");
2586 if (temp >= 1 && temp <= 9)
2588 userParameters->setHelixEndPenalty(temp);
2589 userParameters->setStrandEndPenalty(temp);
2593 //*** ? /helixendin= n
2594 if(setHelixEndIn != -1)
2597 if(logObject && DEBUGLOG)
2599 logObject->logMsg(" Setting helixendin parameter.");
2604 if((*paramArg)[setHelixEndIn].length() > 0)
2606 if (sscanf((*paramArg)[setHelixEndIn].c_str(), "%d", &temp) != 1)
2608 reportBadOptionAndExit("helixendin", "integer");
2612 if (temp >= 0 && temp <= 3)
2614 userParameters->setHelixEndMinus(temp);
2618 //*** ? /helixendout= n
2619 if(setHelixEndOut != -1)
2622 if(logObject && DEBUGLOG)
2624 logObject->logMsg(" Setting helixendout parameter.");
2629 if((*paramArg)[setHelixEndOut].length() > 0)
2631 if (sscanf((*paramArg)[setHelixEndOut].c_str(), "%d", &temp) != 1)
2633 reportBadOptionAndExit("helixendout", "integer");
2637 if (temp >= 0 && temp <= 3)
2639 userParameters->setHelixEndPlus(temp);
2643 //*** ? /strandendin= n
2644 if(setStrandEndIn != -1)
2647 if(logObject && DEBUGLOG)
2649 logObject->logMsg(" Setting strandendin parameter.");
2654 if((*paramArg)[setStrandEndIn].length() > 0)
2656 if (sscanf((*paramArg)[setStrandEndIn].c_str(), "%d", &temp) != 1)
2658 reportBadOptionAndExit("strandendin", "integer");
2661 if (temp >= 0 && temp <= 3)
2663 userParameters->setStrandEndMinus(temp);
2667 //*** ? /strandendout= n
2668 if(setStrandEndOut != -1)
2671 if(logObject && DEBUGLOG)
2673 logObject->logMsg(" Setting strandendout parameter.");
2678 if((*paramArg)[setStrandEndOut].length() > 0)
2680 if (sscanf((*paramArg)[setStrandEndOut].c_str(), "%d", &temp) != 1)
2682 reportBadOptionAndExit("strandendout", "integer");
2685 if (temp >= 0 && temp <= 3)
2687 userParameters->setStrandEndPlus(temp);
2692 int CommandLineParser::findMatch(string probe, StringArray* list, int n)
2697 len = probe.length();
2698 for (i = 0; i < len; i++)
2701 for (j = 0; j < n; j++)
2703 if (probe[i] == (*list)[j][i])
2723 * The function getCmdLineDataStruct is used to return a struct with the values
2724 * specified. It returns it by value. I cant return by reference or else the object will
2727 CmdLineData CommandLineParser::getCmdLineDataStruct(const char *str, int *flag, int type,
2730 CmdLineData tempStruct = {str, flag, type, arg};
2734 void CommandLineParser::printCmdLineData(const CmdLineData& temp)
2736 std::cout << "The str is: " << temp.str << std::endl;
2737 std::cout << "The int* is: " << *(temp.flag) << std::endl;
2738 std::cout << "The type is: " << temp.type << std::endl;
2739 std::cout << "The StringArray is: " << std::endl;
2741 if(temp.arg == NULL)
2743 std::cout << " NULL" << std::endl;
2747 cout << "The number of elements is " << temp.arg->size() << std::endl;
2748 for(int i = 0; i < (int)temp.arg->size(); i++)
2750 cout << "The " << i << "th element is: " << temp.arg->at(i) << endl;
2756 * Helper function to change string to lower case.
2759 string CommandLineParser::ConvertStringToLower(string strToConvert)
2761 for(unsigned int i=0;i<strToConvert.length();i++)
2763 strToConvert[i] = tolower(strToConvert[i]);
2765 return strToConvert;
2771 void CommandLineParser::exitWithErrorMsg(string msg)
2773 cerr << "ERROR: " << msg << std::endl;
2777 void CommandLineParser::reportBadOptionAndExit(string option, string expectedType)
2780 msg = "Bad option for ";
2781 msg += default_commandsep;// has to be added separately
2782 msg += option + ": expected " + expectedType;
2783 exitWithErrorMsg(msg);
2786 void CommandLineParser::reportInvalidOptionAndExit(string option)
2788 string msg = "Invalid option ";
2789 msg += default_commandsep;// has to be added separately
2791 exitWithErrorMsg(msg);