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