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 == "phylipfile" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";}
98 if (key == "columnfile" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column";}
99 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
100 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
101 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
102 if (key == "namefile" ) { namefile = value; }
103 if (key == "orderfile" ) { orderfile = value; }
104 if (key == "groupfile" ) { groupfile = value; }
105 if (key == "cutoff" ) { cutoff = value; }
106 if (key == "precision" ) { precision = value; }
107 if (key == "iters" ) { iters = value; }
108 if (key == "jumble" ) { jumble = value; }
109 if (key == "freq" ) { freq = value; }
110 if (key == "method" ) { method = value; }
111 if (key == "fileroot" ) { fileroot = value; }
113 if (key == "single") {//stores estimators in a vector
114 singleEstimators.clear(); //clears out old values
115 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
116 splitAtDash(value, singleEstimators);
118 if (key == "rarefaction") {//stores estimators in a vector
119 rareEstimators.clear(); //clears out old values
120 if (value == "default") { value = "rarefraction"; }
121 splitAtDash(value, rareEstimators);
123 if (key == "shared") {//stores estimators in a vector
124 sharedEstimators.clear(); //clears out old values
125 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
126 splitAtDash(value, sharedEstimators);
128 if (key == "summary") { //stores summaries to be used in a vector
129 summaryEstimators.clear();
130 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
131 splitAtDash(value, summaryEstimators);
133 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
134 sharedSummaryEstimators.clear();
135 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
136 splitAtDash(value, sharedSummaryEstimators);
138 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
139 sharedRareEstimators.clear();
140 if (value == "default") { value = "sharedobserved"; }
141 splitAtDash(value, sharedRareEstimators);
143 if (key == "line") {//stores lines to be used in a vector
146 splitAtDash(value, lines);
149 if (key == "label") {//stores lines to be used in a vector
152 splitAtDash(value, labels);
157 //saves the last parameter
159 splitAtEquals(key, value);
160 if (key == "phylipfile" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
161 if (key == "columnfile" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
162 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
163 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
164 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
165 if (key == "namefile" ) { namefile = value; }
166 if (key == "orderfile" ) { orderfile = value; }
167 if (key == "groupfile" ) { groupfile = value; }
168 if (key == "cutoff" ) { cutoff = value; }
169 if (key == "precision" ) { precision = value; }
170 if (key == "iters" ) { iters = value; }
171 if (key == "jumble" ) { jumble = value; }
172 if (key == "freq" ) { freq = value; }
173 if (key == "method" ) { method = value; }
174 if (key == "fileroot" ) { fileroot = value; }
176 if (key == "single") {//stores estimators in a vector
177 singleEstimators.clear(); //clears out old values
178 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
179 splitAtDash(value, singleEstimators);
181 if (key == "rarefaction") {//stores estimators in a vector
182 rareEstimators.clear(); //clears out old values
183 if (value == "default") { value = "rarefraction"; }
184 splitAtDash(value, rareEstimators);
186 if (key == "shared") {//stores estimators in a vector
187 sharedEstimators.clear(); //clears out old values
188 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
189 splitAtDash(value, sharedEstimators);
191 if (key == "summary") { //stores summaries to be used in a vector
192 summaryEstimators.clear();
193 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
194 splitAtDash(value, summaryEstimators);
196 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
197 sharedSummaryEstimators.clear();
198 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
199 splitAtDash(value, sharedSummaryEstimators);
201 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
202 sharedRareEstimators.clear();
203 if (value == "default") { value = "sharedobserved"; }
204 splitAtDash(value, sharedRareEstimators);
207 if (key == "line") {//stores lines to be used in a vector
210 splitAtDash(value, lines);
213 if (key == "label") {//stores lines to be used in a vector
216 splitAtDash(value, labels);
223 if (commandString == "collect.single") {
224 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
226 if (commandString == "rarefaction.single") {
227 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
229 if (commandString == "collect.shared") {
230 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
232 if (commandString == "summary.single") {
233 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
235 if (commandString == "summary.shared") {
236 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
238 if (commandString == "rarefaction.shared") {
239 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
244 catch(exception& e) {
245 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
249 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
254 /*******************************************************/
256 /******************************************************/
257 void GlobalData::setReadFormat(string command){
259 if (command == "read.dist") {
261 }else if (command == "read.otu") {
263 }else if (command == "read.shared") {
266 }else if (command == "parselist") { format = "list"; }
268 catch(exception& e) {
269 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setReadFormat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
273 cout << "An unknown error has occurred in the GlobalData class function setReadFormat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
278 /*******************************************************/
280 /******************************************************/
281 // These functions give you the option parameters of the commands
282 string GlobalData::getPhylipFile() { return phylipfile; }
283 string GlobalData::getColumnFile() { return columnfile; }
284 string GlobalData::getListFile() { return listfile; }
285 string GlobalData::getRabundFile() { return rabundfile; }
286 string GlobalData::getSabundFile() { return sabundfile; }
287 string GlobalData::getNameFile() { return namefile; }
288 string GlobalData::getGroupFile() { return groupfile; }
289 string GlobalData::getOrderFile() { return orderfile; }
290 string GlobalData::getCutOff() { return cutoff; }
291 string GlobalData::getFormat() { return format; }
292 string GlobalData::getPrecision() { return precision; }
293 string GlobalData::getMethod() { return method; }
294 string GlobalData::getFileRoot() { return fileroot; }
295 string GlobalData::getIters() { return iters; }
296 string GlobalData::getJumble() { return jumble; }
297 string GlobalData::getFreq() { return freq; }
298 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
299 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
300 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
301 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
302 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
303 //void GlobalData::setGroupFile(string file) { groupfile = file; }
304 void GlobalData::setNameFile(string file) { namefile = file; }
305 void GlobalData::setFormat(string Format) { format = Format; }
308 /*******************************************************/
310 /******************************************************/
312 GlobalData::GlobalData() {
313 //option definitions should go here...
317 /*******************************************************/
319 /******************************************************/
321 void GlobalData::clear() {
322 //option definitions should go here...
341 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
342 rarefaction = "rarefaction";
343 shared = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
344 sharedsummary = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
345 summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
346 sharedrarefaction = "sharedobserved";
348 /*******************************************************/
350 /******************************************************/
352 GlobalData::~GlobalData() {
354 if(gListVector != NULL) { delete gListVector; }
355 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
356 if(gorder != NULL) { delete gorder; }
358 /*******************************************************/
360 /******************************************************/
361 //This function parses the estimator options and puts them in a vector
362 void GlobalData::splitAtDash(string& estim, vector<string>& container) {
366 while (estim.find_first_of('-') != -1) {
367 individual = estim.substr(0,estim.find_first_of('-'));
368 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
369 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
370 container.push_back(individual);
374 container.push_back(estim);
376 catch(exception& e) {
377 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
381 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
386 /*******************************************************/
388 /******************************************************/
389 //This function parses the label options and puts them in a set
390 void GlobalData::splitAtDash(string& estim, set<string>& container) {
394 while (estim.find_first_of('-') != -1) {
395 individual = estim.substr(0,estim.find_first_of('-'));
396 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
397 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
398 container.insert(individual);
402 container.insert(estim);
404 catch(exception& e) {
405 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
409 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
414 /*******************************************************/
416 /******************************************************/
417 //This function parses the line options and puts them in a set
418 void GlobalData::splitAtDash(string& estim, set<int>& container) {
423 while (estim.find_first_of('-') != -1) {
424 individual = estim.substr(0,estim.find_first_of('-'));
425 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
426 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
427 convert(individual, lineNum); //convert the string to int
428 container.insert(lineNum);
432 convert(estim, lineNum); //convert the string to int
433 container.insert(lineNum);
435 catch(exception& e) {
436 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
440 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
445 /*******************************************************/
447 /******************************************************/
449 //This function splits up the various option parameters
450 void GlobalData::splitAtComma(string& prefix, string& suffix){
452 prefix = suffix.substr(0,suffix.find_first_of(','));
453 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
454 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
457 catch(exception& e) {
458 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
462 cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
467 /*******************************************************/
469 /******************************************************/
470 //This function separates the key value from the option value i.e. distfile = "96_..."
471 void GlobalData::splitAtEquals(string& key, string& value){
473 if(value.find_first_of('=') != -1){
474 key = value.substr(0,value.find_first_of('='));
475 if ((value.find_first_of('=')+1) <= value.length()) {
476 value = value.substr(value.find_first_of('=')+1, value.length());
483 catch(exception& e) {
484 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
488 cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
493 /*******************************************************/
495 /******************************************************/