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