]> git.donarmstrong.com Git - mothur.git/blob - globaldata.cpp
Added get.line 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 == "groups" )           { groups = value;       }
114                                 if (key == "calc")                      { calc = value;         }
115
116                                 
117                                 if (key == "line") {//stores lines to be used in a set
118                                         lines.clear();
119                                         line = value;
120                                         label = "";
121                                         splitAtDash(value, lines);
122                                         allLines = 0;
123                                 }
124                                 if (key == "label") {//stores labels to be used in a set
125                                         labels.clear();
126                                         label = value;
127                                         line = "";
128                                         splitAtDash(value, labels);
129                                         allLines = 0;
130                                 }
131
132                                 if (key == "groups") {//stores groups to be used in a vector
133                                         Groups.clear();
134                                         groups = value;
135                                         splitAtDash(value, Groups);
136                                 }
137
138                         }
139                         
140                         //saves the last parameter
141                         value = optionText;
142                         splitAtEquals(key, value);
143                         if (key == "phylip" )   { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";       }
144                         if (key == "column" )   { columnfile = value; inputFileName = value; fileroot = value; format = "column";       }
145                         if (key == "list" )             { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
146                         if (key == "rabund" )   { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
147                         if (key == "sabund" )   { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       }
148                         if (key == "fasta" )    { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         }
149                         if (key == "tree" )             { treefile = value; inputFileName = value; fileroot = value; format = "tree";           } 
150                         if (key == "shared" )   { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile";   } 
151                         if (key == "name" )             { namefile = value;             }
152                         if (key == "order" )    { orderfile = value;    }
153                         if (key == "group" )    { groupfile = value;    }
154                         if (key == "cutoff" )           { cutoff = value;               }
155                         if (key == "precision" )        { precision = value;    }
156                         if (key == "iters" )            { iters = value;                }
157                         if (key == "jumble" )           { jumble = value;               }
158                         if (key == "freq" )                     { freq = value;                 }
159                         if (key == "method" )           { method = value;               }
160                         if (key == "fileroot" )         { fileroot = value;             }
161                         if (key == "abund" )        { abund = value;        }
162                         if (key == "random" )           { randomtree = value;   }
163                         if (key == "groups" )           { groups = value;       }
164                         if (key == "calc")                      { calc = value;         }
165
166
167                         if (key == "line") {//stores lines to be used in a vector
168                                 lines.clear();
169                                 line = value;
170                                 label = "";
171                                 splitAtDash(value, lines);
172                                 allLines = 0;
173                         }
174                         if (key == "label") {//stores lines to be used in a vector
175                                 labels.clear();
176                                 label = value;
177                                 line = "";
178                                 splitAtDash(value, labels);
179                                 allLines = 0;
180                         }
181                         if (key == "groups") {//stores groups to be used in a vector
182                                         Groups.clear();
183                                         groups = value;
184                                         splitAtDash(value, Groups);
185                         }
186                 }
187                 
188                 //set format for shared
189                 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
190                                 
191                 //input defaults for calculators
192                 if (commandName == "collect.single") {
193                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
194                         Estimators.clear();
195                         splitAtDash(calc, Estimators); 
196                 }
197                 if (commandName == "rarefaction.single") {
198                         if ((calc == "default") || (calc == "")) { calc = "sobs"; }
199                         Estimators.clear();
200                         splitAtDash(calc, Estimators); 
201                 }
202                 if (commandName == "collect.shared") {
203                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
204                         Estimators.clear();
205                         splitAtDash(calc, Estimators); 
206                 }
207                 if (commandName == "summary.single") {
208                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
209                         Estimators.clear();
210                         splitAtDash(calc, Estimators); 
211                 }
212                 if (commandName == "summary.shared") {
213                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
214                         Estimators.clear();
215                         splitAtDash(calc, Estimators); 
216                 }
217                 if (commandName == "rarefaction.shared") {
218                         if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
219                         Estimators.clear();
220                         splitAtDash(calc, Estimators); 
221                 }
222
223                 //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
224                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
225                         if (listfile != "") { format = "list"; }
226                         else if (sabundfile != "") { format = "sabund"; }
227                         else if (rabundfile != "") { format = "rabund"; }
228                 }
229         }
230         catch(exception& e) {
231                 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
232                 exit(1);
233         }
234         catch(...) {
235                 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
236                 exit(1);
237         }
238 }
239 /*******************************************************/
240
241 /******************************************************/
242 // These functions give you the option parameters of the commands
243 string GlobalData::getPhylipFile()              {       return phylipfile;      }
244 string GlobalData::getColumnFile()              {       return columnfile;      }
245 string GlobalData::getListFile()                {       return listfile;        }
246 string GlobalData::getRabundFile()              {       return rabundfile;      }
247 string GlobalData::getSabundFile()              {       return sabundfile;      }
248 string GlobalData::getNameFile()                {       return namefile;        }
249 string GlobalData::getGroupFile()               {       return groupfile;       }
250 string GlobalData::getOrderFile()               {       return orderfile;       }
251 string GlobalData::getTreeFile()                {       return treefile;        }
252 string GlobalData::getSharedFile()              {       return sharedfile;      }
253 string GlobalData::getFastaFile()               {       return fastafile;       }
254 string GlobalData::getCutOff()                  {       return cutoff;          }
255 string GlobalData::getFormat()                  {       return format;          }
256 string GlobalData::getPrecision()               {       return precision;       }
257 string GlobalData::getMethod()                  {       return method;          }
258 string GlobalData::getFileRoot()                {       return fileroot;        }
259 string GlobalData::getIters()                   {       return iters;           }
260 string GlobalData::getJumble()                  {       return jumble;          }
261 string GlobalData::getFreq()                    {       return freq;            }
262 string GlobalData::getAbund()           {   return abund;       }
263 string GlobalData::getRandomTree()              {       return randomtree;      }
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::setCalc(string Calc)                   {       calc = Calc;    }
273
274 /*******************************************************/
275
276 /******************************************************/
277 GlobalData::GlobalData() {
278         //option definitions should go here...
279         helpRequest = "";
280         clear();
281 }
282 /*******************************************************/
283
284 /******************************************************/
285 void GlobalData::clear() {
286         //option definitions should go here...
287         phylipfile              =       "";
288         columnfile              =       "";
289         listfile                =       "";
290         rabundfile              =       "";
291         sabundfile              =       "";
292         namefile                =       "";
293         groupfile               =       ""; 
294         orderfile               =       "";
295         fastafile               =   "";
296         treefile                =       "";
297         sharedfile              =       "";
298         cutoff                  =       "10.00";
299         format                  =       "";
300         precision               =       "100";
301         iters                   =       "1000"; 
302         line                    =   "";
303         label                   =       "";
304         groups                  =       "";
305         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
306         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
307         freq                    =       "100";
308         method                  =       "furthest";
309         fileroot                =       "";
310         abund           =   "10";
311 }
312
313 //*******************************************************/
314
315 /******************************************************/
316 void GlobalData::reset() {
317         cutoff                  =       "10.00";
318         precision               =       "100";
319         iters                   =       "1000"; 
320         line                    =   "";
321         label                   =       "";
322         groups                  =       "";
323         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
324         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
325         freq                    =       "100";
326         method                  =       "furthest";
327         calc                    =       "";
328         abund = "10";
329 }
330 /*******************************************************/
331
332 /******************************************************/
333 GlobalData::~GlobalData() {
334         _uniqueInstance = 0;
335         if(gListVector != NULL)         {       delete gListVector;             }
336         if(gSparseMatrix != NULL)       {       delete gSparseMatrix;   }
337         if(gorder != NULL)                      {       delete gorder;          }
338 }
339 /*******************************************************/