]> git.donarmstrong.com Git - mothur.git/blob - optionparser.cpp
added set.current and get.current commands and modified existing commands to update...
[mothur.git] / optionparser.cpp
1 /*
2  *  optionparser.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 6/8/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "optionparser.h"
11
12 /***********************************************************************/
13
14 OptionParser::OptionParser(string option) {
15         try {
16                 m = MothurOut::getInstance();
17                 if (option != "") {
18                         
19                         string key, value;              
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;
25                         }
26                         
27                         //in case there is no comma and to get last parameter after comma
28                         m->splitAtEquals(key, option);
29                         parameters[key] = option;
30                 }
31         }
32         catch(exception& e) {
33                 m->errorOut(e, "OptionParser", "OptionParser");
34                 exit(1);
35         }
36 }
37
38 /***********************************************************************/
39
40 map<string, string> OptionParser::getParameters() {     
41         try {
42                 
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
45                 
46                 map<string, string>::iterator it;
47                 for (it = parameters.begin(); it != parameters.end();) {
48                         
49                         if (it->second == "current") {
50                                 
51                                 //look for file types
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();
90                                 }else {
91                                         m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine();
92                                 }
93                                 
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++);
97                                 }else {
98                                         m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine();
99                                         it++;
100                                 }
101                         }else{ it++; }
102                 }
103         
104                 return parameters;      
105         }
106         catch(exception& e) {
107                 m->errorOut(e, "OptionParser", "getParameters");
108                 exit(1);
109         }
110 }
111
112 /***********************************************************************/