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 if ((key == "candidate") || (key == "query")) { key = "fasta"; }
25 if (key == "template") { key = "reference"; }
26 parameters[key] = value;
29 //in case there is no comma and to get last parameter after comma
30 m->splitAtEquals(key, option);
31 if ((key == "candidate") || (key == "query")) { key = "fasta"; }
32 if (key == "template") { key = "reference"; }
33 parameters[key] = option;
37 m->errorOut(e, "OptionParser", "OptionParser");
41 /***********************************************************************/
43 OptionParser::OptionParser(string option, map<string, string>& copy) {
45 m = MothurOut::getInstance();
49 //reads in parameters and values
50 while((option.find_first_of(',') != -1)) { //while there are parameters
51 m->splitAtComma(value, option);
52 m->splitAtEquals(key, value);
53 if ((key == "candidate") || (key == "query")) { key = "fasta"; }
54 if (key == "template") { key = "reference"; }
55 parameters[key] = value;
58 //in case there is no comma and to get last parameter after comma
59 m->splitAtEquals(key, option);
60 if ((key == "candidate") || (key == "query")) { key = "fasta"; }
61 if (key == "template") { key = "reference"; }
62 parameters[key] = option;
68 m->errorOut(e, "OptionParser", "OptionParser");
72 /***********************************************************************/
74 map<string, string> OptionParser::getParameters() {
77 //loop through parameters and look for "current" so you can return the appropriate file
78 //doing it here to avoid code duplication in each of the commands
81 map<string, string>::iterator it;
82 for (it = parameters.begin(); it != parameters.end();) {
84 if (it->second == "current") {
87 if (it->first == "fasta") {
88 it->second = m->getFastaFile();
89 }else if (it->first == "qfile") {
90 it->second = m->getQualFile();
91 }else if (it->first == "phylip") {
92 it->second = m->getPhylipFile();
93 }else if (it->first == "column") {
94 it->second = m->getColumnFile();
95 }else if (it->first == "list") {
96 it->second = m->getListFile();
97 }else if (it->first == "rabund") {
98 it->second = m->getRabundFile();
99 }else if (it->first == "sabund") {
100 it->second = m->getSabundFile();
101 }else if (it->first == "name") {
102 it->second = m->getNameFile();
103 }else if (it->first == "group") {
104 it->second = m->getGroupFile();
105 }else if (it->first == "order") {
106 it->second = m->getOrderFile();
107 }else if (it->first == "ordergroup") {
108 it->second = m->getOrderGroupFile();
109 }else if (it->first == "tree") {
110 it->second = m->getTreeFile();
111 }else if (it->first == "shared") {
112 it->second = m->getSharedFile();
113 }else if (it->first == "relabund") {
114 it->second = m->getRelAbundFile();
115 }else if (it->first == "design") {
116 it->second = m->getDesignFile();
117 }else if (it->first == "sff") {
118 it->second = m->getSFFFile();
119 }else if (it->first == "flow") {
120 it->second = m->getFlowFile();
121 }else if (it->first == "oligos") {
122 it->second = m->getOligosFile();
123 }else if (it->first == "accnos") {
124 it->second = m->getAccnosFile();
125 }else if (it->first == "taxonomy") {
126 it->second = m->getTaxonomyFile();
127 }else if (it->first == "biom") {
128 it->second = m->getBiomFile();
129 }else if (it->first == "count") {
130 it->second = m->getCountTableFile();
131 }else if (it->first == "summary") {
132 it->second = m->getSummaryFile();
134 m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine();
137 if (it->second == "") { //no file was saved for that type, warn and remove from parameters
138 m->mothurOut("[WARNING]: no file was saved for " + it->first + " parameter."); m->mothurOutEndLine();
139 parameters.erase(it++);
141 m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine();
149 catch(exception& e) {
150 m->errorOut(e, "OptionParser", "getParameters");
155 /***********************************************************************/
156 //pass a vector of filenames that may match the current namefile.
157 //this function will look at each one, if the rootnames match, mothur will warn
158 //the user that they may have neglected to provide a namefile.
159 //stops when it finds a match.
160 bool OptionParser::getNameFile(vector<string> files) {
162 string namefile = m->getNameFile();
165 if ((namefile != "")&&(!m->mothurCalling)) {
166 string temp = m->getRootName(m->getSimpleName(namefile));
167 vector<string> rootName;
168 m->splitAtChar(temp, rootName, '.');
170 for (int i = 0; i < files.size(); i++) {
171 temp = m->getRootName(m->getSimpleName(files[i]));
173 m->splitAtChar(temp, root, '.');
175 int smallest = rootName.size();
176 if (root.size() < smallest) { smallest = root.size(); }
179 for(int j = 0; j < smallest; j++) {
180 if (root[j] == rootName[j]) { numMatches++; }
184 if ((numMatches >= (smallest-2)) && (root[0] == rootName[0])) {
185 m->mothurOut("[WARNING]: This command can take a namefile and you did not provide one. The current namefile is " + namefile + " which seems to match " + files[i] + ".");
186 m->mothurOutEndLine();
198 catch(exception& e) {
199 m->errorOut(e, "OptionParser", "getNameFile");
205 /***********************************************************************/