]> git.donarmstrong.com Git - mothur.git/blob - optionparser.cpp
removed read.dist, read.otu, read.tree and globaldata. added current to defaults...
[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                                 if ((key == "candidate") || (key == "query")) { key = "fasta"; }
25                                 if (key == "template") { key = "reference"; }
26                                 parameters[key] = value;
27                         }
28                         
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;
34                 }
35         }
36         catch(exception& e) {
37                 m->errorOut(e, "OptionParser", "OptionParser");
38                 exit(1);
39         }
40 }
41
42 /***********************************************************************/
43
44 map<string, string> OptionParser::getParameters() {     
45         try {
46                 
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
49                 
50                 map<string, string>::iterator it;
51                 for (it = parameters.begin(); it != parameters.end();) {
52                         
53                         if (it->second == "current") {
54                                 
55                                 //look for file types
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 {
95                                         m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine();
96                                 }
97                                 
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++);
101                                 }else {
102                                         m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine();
103                                         it++;
104                                 }
105                         }else{ it++; }
106                 }
107         
108                 return parameters;      
109         }
110         catch(exception& e) {
111                 m->errorOut(e, "OptionParser", "getParameters");
112                 exit(1);
113         }
114 }
115
116 /***********************************************************************/