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");
42 /***********************************************************************/
44 map<string, string> OptionParser::getParameters() {
47 //loop through parameters and look for "current" so you can return the appropriate file
48 //doing it here to avoid code duplication in each of the commands
50 map<string, string>::iterator it;
51 for (it = parameters.begin(); it != parameters.end();) {
53 if (it->second == "current") {
56 if (it->first == "fasta") {
57 it->second = m->getFastaFile();
58 }else if (it->first == "qfile") {
59 it->second = m->getQualFile();
60 }else if (it->first == "phylip") {
61 it->second = m->getPhylipFile();
62 }else if (it->first == "column") {
63 it->second = m->getColumnFile();
64 }else if (it->first == "list") {
65 it->second = m->getListFile();
66 }else if (it->first == "rabund") {
67 it->second = m->getRabundFile();
68 }else if (it->first == "sabund") {
69 it->second = m->getSabundFile();
70 }else if (it->first == "name") {
71 it->second = m->getNameFile();
72 }else if (it->first == "group") {
73 it->second = m->getGroupFile();
74 }else if (it->first == "order") {
75 it->second = m->getOrderFile();
76 }else if (it->first == "ordergroup") {
77 it->second = m->getOrderGroupFile();
78 }else if (it->first == "tree") {
79 it->second = m->getTreeFile();
80 }else if (it->first == "shared") {
81 it->second = m->getSharedFile();
82 }else if (it->first == "relabund") {
83 it->second = m->getRelAbundFile();
84 }else if (it->first == "design") {
85 it->second = m->getDesignFile();
86 }else if (it->first == "sff") {
87 it->second = m->getSFFFile();
88 }else if (it->first == "oligos") {
89 it->second = m->getOligosFile();
90 }else if (it->first == "accnos") {
91 it->second = m->getAccnosFile();
92 }else if (it->first == "taxonomy") {
93 it->second = m->getTaxonomyFile();
95 m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine();
98 if (it->second == "") { //no file was saved for that type, warn and remove from parameters
99 m->mothurOut("[WARNING]: no file was saved for " + it->first + " parameter."); m->mothurOutEndLine();
100 parameters.erase(it++);
102 m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine();
110 catch(exception& e) {
111 m->errorOut(e, "OptionParser", "getParameters");
116 /***********************************************************************/
117 //pass a vector of filenames that may match the current namefile.
118 //this function will look at each one, if the rootnames match, mothur will warn
119 //the user that they may have neglected to provide a namefile.
120 //stops when it finds a match.
121 bool OptionParser::getNameFile(vector<string> files) {
123 string namefile = m->getNameFile();
126 if (namefile != "") {
127 string temp = m->getRootName(m->getSimpleName(namefile));
128 vector<string> rootName;
129 m->splitAtChar(temp, rootName, '.');
131 for (int i = 0; i < files.size(); i++) {
132 temp = m->getRootName(m->getSimpleName(files[i]));
134 m->splitAtChar(temp, root, '.');
136 int smallest = rootName.size();
137 if (root.size() < smallest) { smallest = root.size(); }
140 for(int j = 0; j < smallest; j++) {
141 if (root[j] == rootName[j]) { numMatches++; }
145 if ((numMatches >= (smallest-2)) && (root[0] == rootName[0])) {
146 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] + ".");
147 m->mothurOutEndLine();
159 catch(exception& e) {
160 m->errorOut(e, "OptionParser", "getNameFile");
166 /***********************************************************************/