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();
94 }else if (it->first == "biom") {
95 it->second = m->getBiomFile();
97 m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine();
100 if (it->second == "") { //no file was saved for that type, warn and remove from parameters
101 m->mothurOut("[WARNING]: no file was saved for " + it->first + " parameter."); m->mothurOutEndLine();
102 parameters.erase(it++);
104 m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine();
112 catch(exception& e) {
113 m->errorOut(e, "OptionParser", "getParameters");
118 /***********************************************************************/
119 //pass a vector of filenames that may match the current namefile.
120 //this function will look at each one, if the rootnames match, mothur will warn
121 //the user that they may have neglected to provide a namefile.
122 //stops when it finds a match.
123 bool OptionParser::getNameFile(vector<string> files) {
125 string namefile = m->getNameFile();
128 if ((namefile != "")&&(!m->mothurCalling)) {
129 string temp = m->getRootName(m->getSimpleName(namefile));
130 vector<string> rootName;
131 m->splitAtChar(temp, rootName, '.');
133 for (int i = 0; i < files.size(); i++) {
134 temp = m->getRootName(m->getSimpleName(files[i]));
136 m->splitAtChar(temp, root, '.');
138 int smallest = rootName.size();
139 if (root.size() < smallest) { smallest = root.size(); }
142 for(int j = 0; j < smallest; j++) {
143 if (root[j] == rootName[j]) { numMatches++; }
147 if ((numMatches >= (smallest-2)) && (root[0] == rootName[0])) {
148 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] + ".");
149 m->mothurOutEndLine();
161 catch(exception& e) {
162 m->errorOut(e, "OptionParser", "getNameFile");
168 /***********************************************************************/