]> git.donarmstrong.com Git - mothur.git/blob - globaldata.cpp
17b4908515179211b792a6d06801d2dc878a7bca
[mothur.git] / globaldata.cpp
1 #include "globaldata.hpp"
2 #include "sparsematrix.hpp"
3 #include "tree.h"
4 #include "rabundvector.hpp"
5 #include "sabundvector.hpp"
6 #include "listvector.hpp"
7
8 /*******************************************************/
9
10 /******************************************************/
11 GlobalData* GlobalData::getInstance() {
12         if( _uniqueInstance == 0 ) {
13                 _uniqueInstance = new GlobalData();
14         }
15         return _uniqueInstance;
16 }
17 /*******************************************************/
18
19 /******************************************************/
20 //This function parses through the option string of the command to remove its parameters
21 void GlobalData::parseGlobalData(string commandString, string optionText){
22         try {
23                 commandName = commandString; //save command name to be used by other classes
24                 
25                 //set all non filename paramters to default
26                 reset();
27                 
28                 //clears out data from previous read
29                 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) { 
30                         clear();
31                         gGroupmap = NULL;
32                         gTree.clear();
33                         labels.clear(); lines.clear(); groups.clear();
34                         allLines = 1;
35                 }
36                 
37                 //saves help request
38                 if (commandName =="help") {
39                         helpRequest = optionText;
40                 }
41                 
42                 string key, value;              
43                 //reads in parameters and values
44                 if((optionText != "") && (commandName != "help")){
45                         while((optionText.find_first_of(',') != -1)) {  //while there are parameters
46                                 splitAtComma(value, optionText);
47                                 splitAtEquals(key, value);
48                                 
49                                 if (key == "phylip" )   { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";       }
50                                 if (key == "column" )   { columnfile = value; inputFileName = value; fileroot = value; format = "column";       }
51                                 if (key == "list" )             { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
52                                 if (key == "rabund" )   { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
53                                 if (key == "sabund" )   { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       } 
54                                 if (key == "fasta" )    { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         } 
55                                 if (key == "tree" )             { treefile = value; inputFileName = value; fileroot = value; format = "tree";           }
56                                 if (key == "shared" )   { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile";   }
57                                 if (key == "name" )             { namefile = value;             }
58                                 if (key == "order" )    { orderfile = value;    }
59                                 if (key == "group" )    { groupfile = value;    }
60                                 if (key == "cutoff" )           { cutoff = value;               }
61                                 if (key == "precision" )        { precision = value;    }
62                                 if (key == "iters" )            { iters = value;                }
63                                 if (key == "jumble" )           { jumble = value;               }
64                                 if (key == "freq" )                     { freq = value;                 }
65                                 if (key == "method" )           { method = value;               }
66                                 if (key == "fileroot" )         { fileroot = value;             }
67                                 if (key == "abund" )        { abund = value;        }
68                                 if (key == "random" )           { randomtree = value;   }
69                                 if (key == "calc")                      { calc = value;         }
70
71                                 
72                                 if (key == "line") {//stores lines to be used in a set
73                                         lines.clear();
74                                         line = value;
75                                         label = "";
76                                         splitAtDash(value, lines);
77                                         allLines = 0;
78                                 }
79                                 if (key == "label") {//stores labels to be used in a set
80                                         labels.clear();
81                                         label = value;
82                                         line = "";
83                                         splitAtDash(value, labels);
84                                         allLines = 0;
85                                 }
86
87                                 if (key == "groups") {//stores groups to be used in a vector
88                                         Groups.clear();
89                                         groups = value;
90                                         splitAtDash(value, Groups);
91                                 }
92
93                         }
94                         
95                         //saves the last parameter
96                         value = optionText;
97                         splitAtEquals(key, value);
98                         if (key == "phylip" )   { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";       }
99                         if (key == "column" )   { columnfile = value; inputFileName = value; fileroot = value; format = "column";       }
100                         if (key == "list" )             { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
101                         if (key == "rabund" )   { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
102                         if (key == "sabund" )   { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       }
103                         if (key == "fasta" )    { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         }
104                         if (key == "tree" )             { treefile = value; inputFileName = value; fileroot = value; format = "tree";           } 
105                         if (key == "shared" )   { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile";   } 
106                         if (key == "name" )             { namefile = value;             }
107                         if (key == "order" )    { orderfile = value;    }
108                         if (key == "group" )    { groupfile = value;    }
109                         if (key == "cutoff" )           { cutoff = value;               }
110                         if (key == "precision" )        { precision = value;    }
111                         if (key == "iters" )            { iters = value;                }
112                         if (key == "jumble" )           { jumble = value;               }
113                         if (key == "freq" )                     { freq = value;                 }
114                         if (key == "method" )           { method = value;               }
115                         if (key == "fileroot" )         { fileroot = value;             }
116                         if (key == "abund" )        { abund = value;        }
117                         if (key == "random" )           { randomtree = value;   }
118                         if (key == "calc")                      { calc = value;         }
119
120
121                         if (key == "line") {//stores lines to be used in a vector
122                                 lines.clear();
123                                 line = value;
124                                 label = "";
125                                 if (line != "all") {  splitAtDash(value, lines);  allLines = 0;  }
126                                 else { allLines = 1;  }
127                         }
128                         if (key == "label") {//stores lines to be used in a vector
129                                 labels.clear();
130                                 label = value;
131                                 line = "";
132                                 if (label != "all") {  splitAtDash(value, labels);  allLines = 0;  }
133                                 else { allLines = 1;  }
134                         }
135                         
136                         if (key == "groups") {//stores groups to be used in a vector
137                                         Groups.clear();
138                                         groups = value;
139                                         splitAtDash(value, Groups);
140                         }
141                 }
142                 
143                 //set format for shared
144                 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
145                 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
146                                 
147                 //input defaults for calculators
148                 if (commandName == "collect.single") {
149                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
150                         Estimators.clear();
151                         splitAtDash(calc, Estimators); 
152                 }
153                 if (commandName == "rarefaction.single") {
154                         if ((calc == "default") || (calc == "")) { calc = "sobs"; }
155                         Estimators.clear();
156                         splitAtDash(calc, Estimators); 
157                 }
158                 if (commandName == "collect.shared") {
159                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
160                         Estimators.clear();
161                         splitAtDash(calc, Estimators); 
162                 }
163                 if (commandName == "summary.single") {
164                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
165                         Estimators.clear();
166                         splitAtDash(calc, Estimators); 
167                 }
168                 if (commandName == "summary.shared") {
169                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
170                         Estimators.clear();
171                         splitAtDash(calc, Estimators); 
172                 }
173                 if (commandName == "rarefaction.shared") {
174                         if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
175                         Estimators.clear();
176                         splitAtDash(calc, Estimators); 
177                 }
178
179                 //if you have done a read.otu with a groupfile but don't want to use it anymore because you want to do single commands
180                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
181                         if (listfile != "") { format = "list"; }
182                         else if (sabundfile != "") { format = "sabund"; }
183                         else if (rabundfile != "") { format = "rabund"; }
184                 }
185         }
186         catch(exception& e) {
187                 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
188                 exit(1);
189         }
190         catch(...) {
191                 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
192                 exit(1);
193         }
194 }
195 /*******************************************************/
196
197 /******************************************************/
198 // These functions give you the option parameters of the commands
199 string GlobalData::getPhylipFile()              {       return phylipfile;      }
200 string GlobalData::getColumnFile()              {       return columnfile;      }
201 string GlobalData::getListFile()                {       return listfile;        }
202 string GlobalData::getRabundFile()              {       return rabundfile;      }
203 string GlobalData::getSabundFile()              {       return sabundfile;      }
204 string GlobalData::getNameFile()                {       return namefile;        }
205 string GlobalData::getGroupFile()               {       return groupfile;       }
206 string GlobalData::getOrderFile()               {       return orderfile;       }
207 string GlobalData::getTreeFile()                {       return treefile;        }
208 string GlobalData::getSharedFile()              {       return sharedfile;      }
209 string GlobalData::getFastaFile()               {       return fastafile;       }
210 string GlobalData::getCutOff()                  {       return cutoff;          }
211 string GlobalData::getFormat()                  {       return format;          }
212 string GlobalData::getPrecision()               {       return precision;       }
213 string GlobalData::getMethod()                  {       return method;          }
214 string GlobalData::getFileRoot()                {       return fileroot;        }
215 string GlobalData::getIters()                   {       return iters;           }
216 string GlobalData::getJumble()                  {       return jumble;          }
217 string GlobalData::getFreq()                    {       return freq;            }
218 string GlobalData::getAbund()           {   return abund;       }
219 string GlobalData::getRandomTree()              {       return randomtree;      }
220 string GlobalData::getGroups()                  {       return groups;          }
221 void GlobalData::setListFile(string file)       {       listfile = file;        inputFileName = file;}
222 void GlobalData::setRabundFile(string file)     {       rabundfile = file;      inputFileName = file;}
223 void GlobalData::setSabundFile(string file)     {       sabundfile = file;      inputFileName = file;}
224 void GlobalData::setPhylipFile(string file)     {       phylipfile = file;    inputFileName = file;}
225 void GlobalData::setColumnFile(string file)     {       columnfile = file;    inputFileName = file;}
226 void GlobalData::setNameFile(string file)               {       namefile = file;                }
227 void GlobalData::setFormat(string Format)               {       format = Format;                }
228 void GlobalData::setRandomTree(string Random)   {       randomtree = Random;    }
229 void GlobalData::setGroups(string g)                    {       groups = g;                             }
230 void GlobalData::setCalc(string Calc)                   {       calc = Calc;                    }
231
232 /*******************************************************/
233
234 /******************************************************/
235 GlobalData::GlobalData() {
236         //option definitions should go here...
237         helpRequest = "";
238         clear();
239 }
240 /*******************************************************/
241
242 /******************************************************/
243 void GlobalData::clear() {
244         //option definitions should go here...
245         phylipfile              =       "";
246         columnfile              =       "";
247         listfile                =       "";
248         rabundfile              =       "";
249         sabundfile              =       "";
250         namefile                =       "";
251         groupfile               =       ""; 
252         orderfile               =       "";
253         fastafile               =   "";
254         treefile                =       "";
255         sharedfile              =       "";
256         cutoff                  =       "10.00";
257         format                  =       "";
258         precision               =       "100";
259         iters                   =       "1000"; 
260         line                    =   "";
261         label                   =       "";
262         groups                  =       "";
263         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
264         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
265         freq                    =       "100";
266         method                  =       "furthest";
267         fileroot                =       "";
268         abund           =   "10";
269 }
270
271 //*******************************************************/
272
273 /******************************************************/
274 void GlobalData::reset() {
275         cutoff                  =       "10.00";
276         precision               =       "100";
277         iters                   =       "1000"; 
278         groups                  =       "";
279         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
280         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
281         freq                    =       "100";
282         method                  =       "furthest";
283         calc                    =       "";
284         abund = "10";
285 }
286 /*******************************************************/
287
288 /******************************************************/
289 GlobalData::~GlobalData() {
290         _uniqueInstance = 0;
291         if(gListVector != NULL)         {       delete gListVector;             }
292         if(gSparseMatrix != NULL)       {       delete gSparseMatrix;   }
293         if(gorder != NULL)                      {       delete gorder;          }
294 }
295 /*******************************************************/