10 #include "globaldata.hpp"
11 #include "sparsematrix.hpp"
12 #include "rabundvector.hpp"
13 #include "sabundvector.hpp"
14 #include "listvector.hpp"
18 /*******************************************************/
20 /******************************************************/
21 GlobalData* GlobalData::getInstance() {
22 if( _uniqueInstance == 0 ) {
23 _uniqueInstance = new GlobalData();
25 return _uniqueInstance;
27 /*******************************************************/
29 /******************************************************/
31 ListVector* GlobalData::getListVector() { return gListVector; }
32 /*******************************************************/
34 /******************************************************/
35 void GlobalData::setListVector(ListVector* lv){
37 if(gListVector != NULL){ delete gListVector; }
38 gListVector = new ListVector(*lv);
41 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
45 cout << "An unknown error has occurred in the GlobalData class function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
50 /*******************************************************/
52 /******************************************************/
54 SparseMatrix* GlobalData::getSparseMatrix() { return gSparseMatrix; }
55 /*******************************************************/
57 /******************************************************/
58 void GlobalData::setSparseMatrix(SparseMatrix* sm){
60 if(gSparseMatrix != NULL){ delete gSparseMatrix; }
61 gSparseMatrix = new SparseMatrix(*sm);
64 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 cout << "An unknown error has occurred in the GlobalData class function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73 /*******************************************************/
75 /******************************************************/
76 //This function parses through the option string of the command to remove its parameters
77 void GlobalData::parseGlobalData(string commandString, string optionText){
80 commandName = commandString; //save command name to be used by other classes
82 //clears out data from previous read and sets format
83 setReadFormat(commandName);
86 if (commandName =="help") {
87 helpRequest = optionText;
91 //reads in parameters and values
92 if((optionText != "") && (commandName != "help")){
93 while((optionText.find_first_of(',') != -1)) { //while there are parameters
94 splitAtComma(value, optionText);
95 splitAtEquals(key, value);
97 if (key == "distfile" ) { distfile = value; inputFileName = value; fileroot = value;}
98 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value;}
99 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value;}
100 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value;}
101 if (key == "namefile" ) { namefile = value; }
102 if (key == "orderfile" ) { orderfile = value; }
103 if (key == "groupfile" ) { 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; }
112 if (key == "single") {//stores estimators in a vector
113 singleEstimators.clear(); //clears out old values
114 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
115 splitAtDash(value, singleEstimators);
117 if (key == "rarefaction") {//stores estimators in a vector
118 rareEstimators.clear(); //clears out old values
119 if (value == "default") { value = "rarefraction"; }
120 splitAtDash(value, rareEstimators);
122 if (key == "shared") {//stores estimators in a vector
123 sharedEstimators.clear(); //clears out old values
124 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
125 splitAtDash(value, sharedEstimators);
127 if (key == "summary") { //stores summaries to be used in a vector
128 summaryEstimators.clear();
129 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
130 splitAtDash(value, summaryEstimators);
132 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
133 sharedSummaryEstimators.clear();
134 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
135 splitAtDash(value, sharedSummaryEstimators);
137 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
138 sharedRareEstimators.clear();
139 if (value == "default") { value = "sharedobserved"; }
140 splitAtDash(value, sharedRareEstimators);
142 if (key == "line") {//stores lines to be used in a vector
145 splitAtDash(value, lines);
148 if (key == "label") {//stores lines to be used in a vector
151 splitAtDash(value, labels);
156 //saves the last parameter
158 splitAtEquals(key, value);
159 if (key == "distfile" ) { distfile = value; inputFileName = value; fileroot = value; }
160 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value; }
161 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value; }
162 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value; }
163 if (key == "namefile" ) { namefile = value; }
164 if (key == "orderfile" ) { orderfile = value; }
165 if (key == "groupfile" ) { groupfile = value; }
166 if (key == "cutoff" ) { cutoff = value; }
167 if (key == "precision" ) { precision = value; }
168 if (key == "iters" ) { iters = value; }
169 if (key == "jumble" ) { jumble = value; }
170 if (key == "freq" ) { freq = value; }
171 if (key == "method" ) { method = value; }
172 if (key == "fileroot" ) { fileroot = value; }
174 if (key == "single") {//stores estimators in a vector
175 singleEstimators.clear(); //clears out old values
176 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
177 splitAtDash(value, singleEstimators);
179 if (key == "rarefaction") {//stores estimators in a vector
180 rareEstimators.clear(); //clears out old values
181 if (value == "default") { value = "rarefraction"; }
182 splitAtDash(value, rareEstimators);
184 if (key == "shared") {//stores estimators in a vector
185 sharedEstimators.clear(); //clears out old values
186 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
187 splitAtDash(value, sharedEstimators);
189 if (key == "summary") { //stores summaries to be used in a vector
190 summaryEstimators.clear();
191 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
192 splitAtDash(value, summaryEstimators);
194 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
195 sharedSummaryEstimators.clear();
196 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
197 splitAtDash(value, sharedSummaryEstimators);
199 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
200 sharedRareEstimators.clear();
201 if (value == "default") { value = "sharedobserved"; }
202 splitAtDash(value, sharedRareEstimators);
205 if (key == "line") {//stores lines to be used in a vector
208 splitAtDash(value, lines);
211 if (key == "label") {//stores lines to be used in a vector
214 splitAtDash(value, labels);
221 if (commandString == "collect.single") {
222 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
224 if (commandString == "rarefaction.single") {
225 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
227 if (commandString == "collect.shared") {
228 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
230 if (commandString == "summary.single") {
231 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
233 if (commandString == "summary.shared") {
234 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
236 if (commandString == "rarefaction.shared") {
237 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
242 catch(exception& e) {
243 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
247 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
252 /*******************************************************/
254 /******************************************************/
255 void GlobalData::setReadFormat(string command){
257 if (command == "read.phylip") {
260 }else if (command == "read.column") {
263 }else if (command == "read.list") {
266 }else if (command == "read.rabund") {
269 }else if (command == "read.sabund") {
272 }else if (command == "read.shared") {
275 }else if (command == "parselist") { format = "list"; }
277 catch(exception& e) {
278 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setReadFormat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
282 cout << "An unknown error has occurred in the GlobalData class function setReadFormat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
287 /*******************************************************/
289 /******************************************************/
290 // These functions give you the option parameters of the commands
291 string GlobalData::getDistFile() { return distfile; }
292 string GlobalData::getListFile() { return listfile; }
293 string GlobalData::getRabundFile() { return rabundfile; }
294 string GlobalData::getSabundFile() { return sabundfile; }
295 string GlobalData::getNameFile() { return namefile; }
296 string GlobalData::getGroupFile() { return groupfile; }
297 string GlobalData::getOrderFile() { return orderfile; }
298 string GlobalData::getCutOff() { return cutoff; }
299 string GlobalData::getFormat() { return format; }
300 string GlobalData::getPrecision() { return precision; }
301 string GlobalData::getMethod() { return method; }
302 string GlobalData::getFileRoot() { return fileroot; }
303 string GlobalData::getIters() { return iters; }
304 string GlobalData::getJumble() { return jumble; }
305 string GlobalData::getFreq() { return freq; }
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::setDistFile(string file) { distfile = file; inputFileName = file;}
310 void GlobalData::setNameFile(string file) { namefile = file; }
311 void GlobalData::setFormat(string Format) { format = Format; }
314 /*******************************************************/
316 /******************************************************/
318 GlobalData::GlobalData() {
319 //option definitions should go here...
323 /*******************************************************/
325 /******************************************************/
327 void GlobalData::clear() {
328 //option definitions should go here...
330 listfile = "";///users/westcott/desktop/s.list
334 groupfile = ""; ///users/westcott/desktop/s.names
346 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
347 rarefaction = "rarefaction";
348 shared = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
349 sharedsummary = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
350 summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
351 sharedrarefaction = "sharedobserved";
353 /*******************************************************/
355 /******************************************************/
357 GlobalData::~GlobalData() {
359 if(gListVector != NULL) { delete gListVector; }
360 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
361 if(gorder != NULL) { delete gorder; }
363 /*******************************************************/
365 /******************************************************/
366 //This function parses the estimator options and puts them in a vector
367 void GlobalData::splitAtDash(string& estim, vector<string>& container) {
371 while (estim.find_first_of('-') != -1) {
372 individual = estim.substr(0,estim.find_first_of('-'));
373 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
374 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
375 container.push_back(individual);
379 container.push_back(estim);
381 catch(exception& e) {
382 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
386 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
391 /*******************************************************/
393 /******************************************************/
394 //This function parses the label options and puts them in a set
395 void GlobalData::splitAtDash(string& estim, set<string>& container) {
399 while (estim.find_first_of('-') != -1) {
400 individual = estim.substr(0,estim.find_first_of('-'));
401 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
402 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
403 container.insert(individual);
407 container.insert(estim);
409 catch(exception& e) {
410 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
414 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
419 /*******************************************************/
421 /******************************************************/
422 //This function parses the line options and puts them in a set
423 void GlobalData::splitAtDash(string& estim, set<int>& container) {
428 while (estim.find_first_of('-') != -1) {
429 individual = estim.substr(0,estim.find_first_of('-'));
430 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
431 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
432 convert(individual, lineNum); //convert the string to int
433 container.insert(lineNum);
437 convert(estim, lineNum); //convert the string to int
438 container.insert(lineNum);
440 catch(exception& e) {
441 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
445 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
450 /*******************************************************/
452 /******************************************************/
454 //This function splits up the various option parameters
455 void GlobalData::splitAtComma(string& prefix, string& suffix){
457 prefix = suffix.substr(0,suffix.find_first_of(','));
458 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
459 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
462 catch(exception& e) {
463 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
467 cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
472 /*******************************************************/
474 /******************************************************/
475 //This function separates the key value from the option value i.e. distfile = "96_..."
476 void GlobalData::splitAtEquals(string& key, string& value){
478 if(value.find_first_of('=') != -1){
479 key = value.substr(0,value.find_first_of('='));
480 if ((value.find_first_of('=')+1) <= value.length()) {
481 value = value.substr(value.find_first_of('=')+1, value.length());
488 catch(exception& e) {
489 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
493 cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
498 /*******************************************************/
500 /******************************************************/