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