10 #include "globaldata.hpp"
11 #include "sparsematrix.hpp"
13 #include "rabundvector.hpp"
14 #include "sabundvector.hpp"
15 #include "listvector.hpp"
19 /*******************************************************/
21 /******************************************************/
22 GlobalData* GlobalData::getInstance() {
23 if( _uniqueInstance == 0 ) {
24 _uniqueInstance = new GlobalData();
26 return _uniqueInstance;
28 /*******************************************************/
30 /******************************************************/
32 ListVector* GlobalData::getListVector() { return gListVector; }
33 /*******************************************************/
35 /******************************************************/
36 void GlobalData::setListVector(ListVector* lv){
38 if(gListVector != NULL){ delete gListVector; }
39 gListVector = new ListVector(*lv);
42 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
46 cout << "An unknown error has occurred in the GlobalData class function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51 /*******************************************************/
53 /******************************************************/
55 SparseMatrix* GlobalData::getSparseMatrix() { return gSparseMatrix; }
56 /*******************************************************/
58 /******************************************************/
59 void GlobalData::setSparseMatrix(SparseMatrix* sm){
61 if(gSparseMatrix != NULL){ delete gSparseMatrix; }
62 gSparseMatrix = new SparseMatrix(*sm);
65 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
69 cout << "An unknown error has occurred in the GlobalData class function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
74 /*******************************************************/
76 /******************************************************/
77 //This function parses through the option string of the command to remove its parameters
78 void GlobalData::parseGlobalData(string commandString, string optionText){
81 commandName = commandString; //save command name to be used by other classes
83 //clears out data from previous read
84 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) {
89 if (commandName =="help") {
90 helpRequest = optionText;
94 //reads in parameters and values
95 if((optionText != "") && (commandName != "help")){
96 while((optionText.find_first_of(',') != -1)) { //while there are parameters
97 splitAtComma(value, optionText);
98 splitAtEquals(key, value);
100 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
101 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
102 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
103 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
104 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
105 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
106 if (key == "treefile" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
107 if (key == "name" ) { namefile = value; }
108 if (key == "order" ) { orderfile = value; }
109 if (key == "group" ) { groupfile = value; }
110 if (key == "cutoff" ) { cutoff = value; }
111 if (key == "precision" ) { precision = value; }
112 if (key == "iters" ) { iters = value; }
113 if (key == "jumble" ) { jumble = value; }
114 if (key == "freq" ) { freq = value; }
115 if (key == "method" ) { method = value; }
116 if (key == "fileroot" ) { fileroot = value; }
117 if (key == "randomtree" ) { randomtree = value; }
118 if (key == "groups" ) { groups = value; }
120 if (key == "single") {//stores estimators in a vector
121 singleEstimators.clear(); //clears out old values
122 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
123 splitAtDash(value, singleEstimators);
125 if (key == "rarefaction") {//stores estimators in a vector
126 rareEstimators.clear(); //clears out old values
127 if (value == "default") { value = "rarefraction"; }
128 splitAtDash(value, rareEstimators);
130 if (key == "shared") {//stores estimators in a vector
131 sharedEstimators.clear(); //clears out old values
132 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
133 splitAtDash(value, sharedEstimators);
135 if (key == "summary") { //stores summaries to be used in a vector
136 summaryEstimators.clear();
137 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
138 splitAtDash(value, summaryEstimators);
140 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
141 sharedSummaryEstimators.clear();
142 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
143 splitAtDash(value, sharedSummaryEstimators);
145 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
146 sharedRareEstimators.clear();
147 if (value == "default") { value = "sharedobserved"; }
148 splitAtDash(value, sharedRareEstimators);
150 if (key == "line") {//stores lines to be used in a set
154 splitAtDash(value, lines);
157 if (key == "label") {//stores lines to be used in a set
161 splitAtDash(value, labels);
164 if (key == "groups") {//stores lines to be used in a vector
167 splitAtDash(value, Groups);
172 //saves the last parameter
174 splitAtEquals(key, value);
175 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
176 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
177 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
178 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
179 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
180 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
181 if (key == "treefile" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
182 if (key == "name" ) { namefile = value; }
183 if (key == "order" ) { orderfile = value; }
184 if (key == "group" ) { groupfile = value; }
185 if (key == "cutoff" ) { cutoff = value; }
186 if (key == "precision" ) { precision = value; }
187 if (key == "iters" ) { iters = value; }
188 if (key == "jumble" ) { jumble = value; }
189 if (key == "freq" ) { freq = value; }
190 if (key == "method" ) { method = value; }
191 if (key == "fileroot" ) { fileroot = value; }
192 if (key == "randomtree" ) { randomtree = value; }
194 if (key == "single") {//stores estimators in a vector
195 singleEstimators.clear(); //clears out old values
196 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
197 splitAtDash(value, singleEstimators);
199 if (key == "rarefaction") {//stores estimators in a vector
200 rareEstimators.clear(); //clears out old values
201 if (value == "default") { value = "rarefraction"; }
202 splitAtDash(value, rareEstimators);
204 if (key == "shared") {//stores estimators in a vector
205 sharedEstimators.clear(); //clears out old values
206 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
207 splitAtDash(value, sharedEstimators);
209 if (key == "summary") { //stores summaries to be used in a vector
210 summaryEstimators.clear();
211 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
212 splitAtDash(value, summaryEstimators);
214 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
215 sharedSummaryEstimators.clear();
216 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
217 splitAtDash(value, sharedSummaryEstimators);
219 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
220 sharedRareEstimators.clear();
221 if (value == "default") { value = "sharedobserved"; }
222 splitAtDash(value, sharedRareEstimators);
225 if (key == "line") {//stores lines to be used in a vector
229 splitAtDash(value, lines);
232 if (key == "label") {//stores lines to be used in a vector
236 splitAtDash(value, labels);
241 //set format for shared
242 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
245 if (commandName == "collect.single") {
246 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
248 if (commandName == "rarefaction.single") {
249 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
251 if (commandName == "collect.shared") {
252 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
254 if (commandName == "summary.single") {
255 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
257 if (commandName == "summary.shared") {
258 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
260 if (commandName == "rarefaction.shared") {
261 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
265 //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
266 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
267 if (listfile != "") { format = "list"; }
268 else if (sabundfile != "") { format = "sabund"; }
269 else if (rabundfile != "") { format = "rabund"; }
273 catch(exception& e) {
274 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
278 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
283 /*******************************************************/
285 /******************************************************/
286 // These functions give you the option parameters of the commands
287 string GlobalData::getPhylipFile() { return phylipfile; }
288 string GlobalData::getColumnFile() { return columnfile; }
289 string GlobalData::getListFile() { return listfile; }
290 string GlobalData::getRabundFile() { return rabundfile; }
291 string GlobalData::getSabundFile() { return sabundfile; }
292 string GlobalData::getNameFile() { return namefile; }
293 string GlobalData::getGroupFile() { return groupfile; }
294 string GlobalData::getOrderFile() { return orderfile; }
295 string GlobalData::getTreeFile() { return treefile; }
296 string GlobalData::getFastaFile() { return fastafile; }
297 string GlobalData::getCutOff() { return cutoff; }
298 string GlobalData::getFormat() { return format; }
299 string GlobalData::getPrecision() { return precision; }
300 string GlobalData::getMethod() { return method; }
301 string GlobalData::getFileRoot() { return fileroot; }
302 string GlobalData::getIters() { return iters; }
303 string GlobalData::getJumble() { return jumble; }
304 string GlobalData::getFreq() { return freq; }
305 string GlobalData::getRandomTree() { return randomtree; }
306 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
307 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
308 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
309 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
310 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
311 //void GlobalData::setGroupFile(string file) { groupfile = file; }
312 void GlobalData::setNameFile(string file) { namefile = file; }
313 void GlobalData::setFormat(string Format) { format = Format; }
314 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
317 /*******************************************************/
319 /******************************************************/
321 GlobalData::GlobalData() {
322 //option definitions should go here...
326 /*******************************************************/
328 /******************************************************/
330 void GlobalData::clear() {
331 //option definitions should go here...
348 jumble = "1"; //0 means don't jumble, 1 means jumble.
349 randomtree = "0"; //0 means user will enter some user trees, 1 means they just want the random tree distribution.
353 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
354 rarefaction = "sobs";
355 shared = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
356 sharedsummary = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
357 summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
358 sharedrarefaction = "sharedobserved";
360 /*******************************************************/
362 /******************************************************/
364 GlobalData::~GlobalData() {
366 if(gListVector != NULL) { delete gListVector; }
367 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
368 if(gorder != NULL) { delete gorder; }
370 /*******************************************************/
372 /******************************************************/
373 //This function parses the estimator options and puts them in a vector
374 void GlobalData::splitAtDash(string& estim, vector<string>& container) {
378 while (estim.find_first_of('-') != -1) {
379 individual = estim.substr(0,estim.find_first_of('-'));
380 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
381 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
382 container.push_back(individual);
386 container.push_back(estim);
388 catch(exception& e) {
389 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
393 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
398 /*******************************************************/
400 /******************************************************/
401 //This function parses the label options and puts them in a set
402 void GlobalData::splitAtDash(string& estim, set<string>& container) {
406 while (estim.find_first_of('-') != -1) {
407 individual = estim.substr(0,estim.find_first_of('-'));
408 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
409 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
410 container.insert(individual);
414 container.insert(estim);
416 catch(exception& e) {
417 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
421 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
426 /*******************************************************/
428 /******************************************************/
429 //This function parses the line options and puts them in a set
430 void GlobalData::splitAtDash(string& estim, set<int>& container) {
435 while (estim.find_first_of('-') != -1) {
436 individual = estim.substr(0,estim.find_first_of('-'));
437 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
438 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
439 convert(individual, lineNum); //convert the string to int
440 container.insert(lineNum);
444 convert(estim, lineNum); //convert the string to int
445 container.insert(lineNum);
447 catch(exception& e) {
448 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
452 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
457 /*******************************************************/
459 /******************************************************/
461 //This function splits up the various option parameters
462 void GlobalData::splitAtComma(string& prefix, string& suffix){
464 prefix = suffix.substr(0,suffix.find_first_of(','));
465 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
466 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
469 catch(exception& e) {
470 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
474 cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
479 /*******************************************************/
481 /******************************************************/
482 //This function separates the key value from the option value i.e. distfile = "96_..."
483 void GlobalData::splitAtEquals(string& key, string& value){
485 if(value.find_first_of('=') != -1){
486 key = value.substr(0,value.find_first_of('='));
487 if ((value.find_first_of('=')+1) <= value.length()) {
488 value = value.substr(value.find_first_of('=')+1, value.length());
495 catch(exception& e) {
496 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
500 cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
505 /*******************************************************/
507 /******************************************************/