]> git.donarmstrong.com Git - mothur.git/blob - globaldata.cpp
64a7c93ac0a7c5067cf102250d3efd9cf8ab7380
[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                 if (commandName == "libshuff") {
43                         iters = "10000";
44                         cutoff = "1.0";
45                 }
46                 
47                 string key, value;              
48                 //reads in parameters and values
49                 if((optionText != "") && (commandName != "help")){
50                         while((optionText.find_first_of(',') != -1)) {  //while there are parameters
51                                 splitAtComma(value, optionText);
52                                 splitAtEquals(key, value);
53                                 
54                                 if (key == "phylip" )   { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";       }
55                                 if (key == "column" )   { columnfile = value; inputFileName = value; fileroot = value; format = "column";       }
56                                 if (key == "list" )             { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
57                                 if (key == "rabund" )   { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
58                                 if (key == "sabund" )   { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       } 
59                                 if (key == "fasta" )    { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         } 
60                                 if (key == "tree" )             { treefile = value; inputFileName = value; fileroot = value; format = "tree";           }
61                                 if (key == "shared" )   { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile";   }
62                                 if (key == "name" )             { namefile = value;             }
63                                 if (key == "order" )    { orderfile = value;    }
64                                 if (key == "group" )    { groupfile = value;    }
65                                 if (key == "cutoff" )           { cutoff = value;               }
66                                 if (key == "precision" )        { precision = value;    }
67                                 if (key == "iters" )            { iters = value;                }
68                                 if (key == "jumble" )           { jumble = value;               }
69                                 if (key == "freq" )                     { freq = value;                 }
70                                 if (key == "method" )           { method = value;               }
71                                 if (key == "fileroot" )         { fileroot = value;             }
72                                 if (key == "abund" )        { abund = value;        }
73                                 if (key == "random" )           { randomtree = value;   }
74                                 if (key == "calc")                      { calc = value;                 }
75                                 if (key == "step")                      { step = value;                 }
76                                 if (key == "form")                      { form = value;                 }
77                                 if (key == "sorted")            { sorted = value;               }
78                                 
79
80                                 
81                                 if (key == "line") {//stores lines to be used in a set
82                                         lines.clear();
83                                         labels.clear();
84                                         line = value;
85                                         label = "";
86                                         splitAtDash(value, lines);
87                                         allLines = 0;
88                                 }
89                                 if (key == "label") {//stores labels to be used in a set
90                                         labels.clear();
91                                         lines.clear();
92                                         label = value;
93                                         line = "";
94                                         splitAtDash(value, labels);
95                                         allLines = 0;
96                                 }
97
98                                 if (key == "groups") {//stores groups to be used in a vector
99                                         Groups.clear();
100                                         groups = value;
101                                         splitAtDash(value, Groups);
102                                 }
103
104                         }
105                         
106                         //saves the last parameter
107                         value = optionText;
108                         splitAtEquals(key, value);
109                         if (key == "phylip" )   { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";       }
110                         if (key == "column" )   { columnfile = value; inputFileName = value; fileroot = value; format = "column";       }
111                         if (key == "list" )             { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
112                         if (key == "rabund" )   { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
113                         if (key == "sabund" )   { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       }
114                         if (key == "fasta" )    { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         }
115                         if (key == "tree" )             { treefile = value; inputFileName = value; fileroot = value; format = "tree";           } 
116                         if (key == "shared" )   { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile";   } 
117                         if (key == "name" )             { namefile = value;             }
118                         if (key == "order" )    { orderfile = value;    }
119                         if (key == "group" )    { groupfile = value;    }
120                         if (key == "cutoff" )           { cutoff = value;               }
121                         if (key == "precision" )        { precision = value;    }
122                         if (key == "iters" )            { iters = value;                }
123                         if (key == "jumble" )           { jumble = value;               }
124                         if (key == "freq" )                     { freq = value;                 }
125                         if (key == "method" )           { method = value;               }
126                         if (key == "fileroot" )         { fileroot = value;             }
127                         if (key == "abund" )        { abund = value;        }
128                         if (key == "random" )           { randomtree = value;   }
129                         if (key == "calc")                      { calc = value;                 }
130                         if (key == "step")                      { step = value;                 }
131                         if (key == "form")                      { form = value;                 }
132                         if (key == "sorted")            { sorted = value;               }
133
134                         if (key == "line") {//stores lines to be used in a vector
135                                 lines.clear();
136                                 labels.clear();
137                                 line = value;
138                                 label = "";
139                                 if (line != "all") {  splitAtDash(value, lines);  allLines = 0;  }
140                                 else { allLines = 1;  }
141                         }
142                         if (key == "label") {//stores lines to be used in a vector
143                                 labels.clear();
144                                 lines.clear();
145                                 label = value;
146                                 line = "";
147                                 if (label != "all") {  splitAtDash(value, labels);  allLines = 0;  }
148                                 else { allLines = 1;  }
149                         }
150                         
151                         if (key == "groups") {//stores groups to be used in a vector
152                                         Groups.clear();
153                                         groups = value;
154                                         splitAtDash(value, Groups);
155                         }
156                 }
157                 
158                 //set format for shared
159                 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
160                 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
161                                 
162                 //input defaults for calculators
163                 if (commandName == "collect.single") {
164                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-qstat-logsd-bergerparker-bstick"; }
165                         Estimators.clear();
166                         splitAtDash(calc, Estimators); 
167                 }
168                 if (commandName == "rarefaction.single") {
169                         if ((calc == "default") || (calc == "")) { calc = "sobs"; }
170                         Estimators.clear();
171                         splitAtDash(calc, Estimators); 
172                 }
173                 if (commandName == "collect.shared") {
174                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
175                         Estimators.clear();
176                         splitAtDash(calc, Estimators); 
177                 }
178                 if (commandName == "summary.single") {
179                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-logsd-qstat-bergerparker-bstick"; }
180                         Estimators.clear();
181                         splitAtDash(calc, Estimators); 
182                 }
183                 if (commandName == "summary.shared") {
184                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
185                         Estimators.clear();
186                         splitAtDash(calc, Estimators); 
187                 }
188                 if (commandName == "rarefaction.shared") {
189                         if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
190                         Estimators.clear();
191                         splitAtDash(calc, Estimators); 
192                 }
193
194                 //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
195                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
196                         if (listfile != "") { format = "list"; }
197                         else if (sabundfile != "") { format = "sabund"; }
198                         else if (rabundfile != "") { format = "rabund"; }
199                 }
200         }
201         catch(exception& e) {
202                 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
203                 exit(1);
204         }
205         catch(...) {
206                 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
207                 exit(1);
208         }
209 }
210 /*******************************************************/
211
212 /******************************************************/
213 // These functions give you the option parameters of the commands
214 string GlobalData::getPhylipFile()              {       return phylipfile;      }
215 string GlobalData::getColumnFile()              {       return columnfile;      }
216 string GlobalData::getListFile()                {       return listfile;        }
217 string GlobalData::getRabundFile()              {       return rabundfile;      }
218 string GlobalData::getSabundFile()              {       return sabundfile;      }
219 string GlobalData::getNameFile()                {       return namefile;        }
220 string GlobalData::getGroupFile()               {       return groupfile;       }
221 string GlobalData::getOrderFile()               {       return orderfile;       }
222 string GlobalData::getTreeFile()                {       return treefile;        }
223 string GlobalData::getSharedFile()              {       return sharedfile;      }
224 string GlobalData::getFastaFile()               {       return fastafile;       }
225 string GlobalData::getCutOff()                  {       return cutoff;          }
226 string GlobalData::getFormat()                  {       return format;          }
227 string GlobalData::getPrecision()               {       return precision;       }
228 string GlobalData::getMethod()                  {       return method;          }
229 string GlobalData::getFileRoot()                {       return fileroot;        }
230 string GlobalData::getIters()                   {       return iters;           }
231 string GlobalData::getJumble()                  {       return jumble;          }
232 string GlobalData::getFreq()                    {       return freq;            }
233 string GlobalData::getAbund()           {   return abund;       }
234 string GlobalData::getRandomTree()              {       return randomtree;      }
235 string GlobalData::getGroups()                  {       return groups;          }
236 string GlobalData::getStep()                    {       return step;            }
237 string GlobalData::getForm()                    {       return form;            }
238 string GlobalData::getSorted()                  {       return sorted;          }
239 void GlobalData::setListFile(string file)       {       listfile = file;        inputFileName = file;}
240 void GlobalData::setRabundFile(string file)     {       rabundfile = file;      inputFileName = file;}
241 void GlobalData::setSabundFile(string file)     {       sabundfile = file;      inputFileName = file;}
242 void GlobalData::setPhylipFile(string file)     {       phylipfile = file;    inputFileName = file;}
243 void GlobalData::setColumnFile(string file)     {       columnfile = file;    inputFileName = file;}
244 void GlobalData::setNameFile(string file)               {       namefile = file;                }
245 void GlobalData::setFormat(string Format)               {       format = Format;                }
246 void GlobalData::setRandomTree(string Random)   {       randomtree = Random;    }
247 void GlobalData::setGroups(string g)                    {       groups = g;                             }
248 void GlobalData::setCalc(string Calc)                   {       calc = Calc;                    }
249
250 /*******************************************************/
251
252 /******************************************************/
253 GlobalData::GlobalData() {
254         //option definitions should go here...
255         helpRequest = "";
256         clear();
257 }
258 /*******************************************************/
259
260 /******************************************************/
261 void GlobalData::clear() {
262         //option definitions should go here...
263         phylipfile              =       "";
264         columnfile              =       "";
265         listfile                =       "";
266         rabundfile              =       "";
267         sabundfile              =       "";
268         namefile                =       "";
269         groupfile               =       ""; 
270         orderfile               =       "";
271         fastafile               =   "";
272         treefile                =       "";
273         sharedfile              =       "";
274         cutoff                  =       "10.00";
275         format                  =       "";
276         precision               =       "100";
277         iters                   =       "1000"; 
278         line                    =   "";
279         label                   =       "";
280         groups                  =       "";
281         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
282         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
283         freq                    =       "100";
284         method                  =       "furthest";
285         fileroot                =       "";
286         abund           =   "10";
287         step                    =       "0.01";
288         form                    =       "integral";
289         sorted                  =       "1";  //0 means don't sort, 1 means sort.
290 }
291
292 //*******************************************************/
293
294 /******************************************************/
295 void GlobalData::reset() {
296         cutoff                  =       "10.00";
297         precision               =       "100";
298         iters                   =       "1000"; 
299         groups                  =       "";
300         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
301         sorted                  =       "1";  //0 means don't sort, 1 means sort.
302         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
303         freq                    =       "100";
304         method                  =       "furthest";
305         calc                    =       "";
306         abund                   =   "10";
307         step                    =       "0.01";
308         form                    =       "integral";
309 }
310 /*******************************************************/
311
312 /******************************************************/
313 GlobalData::~GlobalData() {
314         _uniqueInstance = 0;
315         if(gListVector != NULL)         {       delete gListVector;             }
316         if(gSparseMatrix != NULL)       {       delete gSparseMatrix;   }
317         if(gorder != NULL)                      {       delete gorder;          }
318 }
319 /*******************************************************/