5 * Created by Sarah Westcott on 6/8/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "optionparser.h"
12 /***********************************************************************/
14 OptionParser::OptionParser(string option) {
16 m = MothurOut::getInstance();
20 //reads in parameters and values
21 while((option.find_first_of(',') != -1)) { //while there are parameters
22 m->splitAtComma(value, option);
23 m->splitAtEquals(key, value);
24 parameters[key] = value;
27 //in case there is no comma and to get last parameter after comma
28 m->splitAtEquals(key, option);
29 parameters[key] = option;
33 m->errorOut(e, "OptionParser", "OptionParser");
38 /***********************************************************************/
40 map<string, string> OptionParser::getParameters() {
43 //loop through parameters and look for "current" so you can return the appropriate file
44 //doing it here to avoid code duplication in each of the commands
46 map<string, string>::iterator it;
47 for (it = parameters.begin(); it != parameters.end();) {
49 if (it->second == "current") {
52 if ((it->first == "fasta") || (it->first == "candidate")) {
53 it->second = m->getFastaFile();
54 }else if (it->first == "qfile") {
55 it->second = m->getQualFile();
56 }else if (it->first == "phylip") {
57 it->second = m->getPhylipFile();
58 }else if (it->first == "column") {
59 it->second = m->getColumnFile();
60 }else if (it->first == "list") {
61 it->second = m->getListFile();
62 }else if (it->first == "rabund") {
63 it->second = m->getRabundFile();
64 }else if (it->first == "sabund") {
65 it->second = m->getSabundFile();
66 }else if (it->first == "name") {
67 it->second = m->getNameFile();
68 }else if (it->first == "group") {
69 it->second = m->getGroupFile();
70 }else if (it->first == "order") {
71 it->second = m->getOrderFile();
72 }else if (it->first == "ordergroup") {
73 it->second = m->getOrderGroupFile();
74 }else if (it->first == "tree") {
75 it->second = m->getTreeFile();
76 }else if (it->first == "shared") {
77 it->second = m->getSharedFile();
78 }else if (it->first == "relabund") {
79 it->second = m->getRelAbundFile();
80 }else if (it->first == "design") {
81 it->second = m->getDesignFile();
82 }else if (it->first == "sff") {
83 it->second = m->getSFFFile();
84 }else if (it->first == "oligos") {
85 it->second = m->getOligosFile();
86 }else if (it->first == "accnos") {
87 it->second = m->getAccnosFile();
88 }else if (it->first == "taxonomy") {
89 it->second = m->getTaxonomyFile();
91 m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine();
94 if (it->second == "") { //no file was saved for that type, warn and remove from parameters
95 m->mothurOut("[WARNING]: no file was saved for " + it->first + " parameter."); m->mothurOutEndLine();
96 parameters.erase(it++);
98 m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine();
106 catch(exception& e) {
107 m->errorOut(e, "OptionParser", "getParameters");
112 /***********************************************************************/