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 == "tree" ) { 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 labels to be used in a set
161 splitAtDash(value, labels);
164 if (key == "groups") {//stores groups 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 == "tree" ) { 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; }
193 if (key == "groups" ) { groups = value; }
196 if (key == "single") {//stores estimators in a vector
197 singleEstimators.clear(); //clears out old values
198 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
199 splitAtDash(value, singleEstimators);
201 if (key == "rarefaction") {//stores estimators in a vector
202 rareEstimators.clear(); //clears out old values
203 if (value == "default") { value = "rarefraction"; }
204 splitAtDash(value, rareEstimators);
206 if (key == "shared") {//stores estimators in a vector
207 sharedEstimators.clear(); //clears out old values
208 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
209 splitAtDash(value, sharedEstimators);
211 if (key == "summary") { //stores summaries to be used in a vector
212 summaryEstimators.clear();
213 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
214 splitAtDash(value, summaryEstimators);
216 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
217 sharedSummaryEstimators.clear();
218 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
219 splitAtDash(value, sharedSummaryEstimators);
221 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
222 sharedRareEstimators.clear();
223 if (value == "default") { value = "sharedobserved"; }
224 splitAtDash(value, sharedRareEstimators);
227 if (key == "line") {//stores lines to be used in a vector
231 splitAtDash(value, lines);
234 if (key == "label") {//stores lines to be used in a vector
238 splitAtDash(value, labels);
241 if (key == "groups") {//stores groups to be used in a vector
244 splitAtDash(value, Groups);
249 //set format for shared
250 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
253 if (commandName == "collect.single") {
254 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
256 if (commandName == "rarefaction.single") {
257 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
259 if (commandName == "collect.shared") {
260 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
262 if (commandName == "summary.single") {
263 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
265 if (commandName == "summary.shared") {
266 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
268 if (commandName == "rarefaction.shared") {
269 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
273 //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
274 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
275 if (listfile != "") { format = "list"; }
276 else if (sabundfile != "") { format = "sabund"; }
277 else if (rabundfile != "") { format = "rabund"; }
281 catch(exception& e) {
282 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
286 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
291 /*******************************************************/
293 /******************************************************/
294 // These functions give you the option parameters of the commands
295 string GlobalData::getPhylipFile() { return phylipfile; }
296 string GlobalData::getColumnFile() { return columnfile; }
297 string GlobalData::getListFile() { return listfile; }
298 string GlobalData::getRabundFile() { return rabundfile; }
299 string GlobalData::getSabundFile() { return sabundfile; }
300 string GlobalData::getNameFile() { return namefile; }
301 string GlobalData::getGroupFile() { return groupfile; }
302 string GlobalData::getOrderFile() { return orderfile; }
303 string GlobalData::getTreeFile() { return treefile; }
304 string GlobalData::getFastaFile() { return fastafile; }
305 string GlobalData::getCutOff() { return cutoff; }
306 string GlobalData::getFormat() { return format; }
307 string GlobalData::getPrecision() { return precision; }
308 string GlobalData::getMethod() { return method; }
309 string GlobalData::getFileRoot() { return fileroot; }
310 string GlobalData::getIters() { return iters; }
311 string GlobalData::getJumble() { return jumble; }
312 string GlobalData::getFreq() { return freq; }
313 string GlobalData::getRandomTree() { return randomtree; }
314 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
315 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
316 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
317 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
318 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
319 //void GlobalData::setGroupFile(string file) { groupfile = file; }
320 void GlobalData::setNameFile(string file) { namefile = file; }
321 void GlobalData::setFormat(string Format) { format = Format; }
322 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
325 /*******************************************************/
327 /******************************************************/
329 GlobalData::GlobalData() {
330 //option definitions should go here...
334 /*******************************************************/
336 /******************************************************/
338 void GlobalData::clear() {
339 //option definitions should go here...
357 jumble = "1"; //0 means don't jumble, 1 means jumble.
358 randomtree = "0"; //0 means user will enter some user trees, 1 means they just want the random tree distribution.
362 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
363 rarefaction = "sobs";
364 shared = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
365 sharedsummary = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
366 summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
367 sharedrarefaction = "sharedobserved";
369 /*******************************************************/
371 /******************************************************/
373 GlobalData::~GlobalData() {
375 if(gListVector != NULL) { delete gListVector; }
376 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
377 if(gorder != NULL) { delete gorder; }
379 /*******************************************************/
381 /******************************************************/
382 //This function parses the estimator options and puts them in a vector
383 void GlobalData::splitAtDash(string& estim, vector<string>& container) {
387 while (estim.find_first_of('-') != -1) {
388 individual = estim.substr(0,estim.find_first_of('-'));
389 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
390 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
391 container.push_back(individual);
395 container.push_back(estim);
397 catch(exception& e) {
398 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
402 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
407 /*******************************************************/
409 /******************************************************/
410 //This function parses the label options and puts them in a set
411 void GlobalData::splitAtDash(string& estim, set<string>& container) {
415 while (estim.find_first_of('-') != -1) {
416 individual = estim.substr(0,estim.find_first_of('-'));
417 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
418 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
419 container.insert(individual);
423 container.insert(estim);
425 catch(exception& e) {
426 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
430 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
435 /*******************************************************/
437 /******************************************************/
438 //This function parses the line options and puts them in a set
439 void GlobalData::splitAtDash(string& estim, set<int>& container) {
444 while (estim.find_first_of('-') != -1) {
445 individual = estim.substr(0,estim.find_first_of('-'));
446 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
447 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
448 convert(individual, lineNum); //convert the string to int
449 container.insert(lineNum);
453 convert(estim, lineNum); //convert the string to int
454 container.insert(lineNum);
456 catch(exception& e) {
457 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
461 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
466 /*******************************************************/
468 /******************************************************/
470 //This function splits up the various option parameters
471 void GlobalData::splitAtComma(string& prefix, string& suffix){
473 prefix = suffix.substr(0,suffix.find_first_of(','));
474 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
475 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
478 catch(exception& e) {
479 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
483 cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
488 /*******************************************************/
490 /******************************************************/
491 //This function separates the key value from the option value i.e. dist=96_...
492 void GlobalData::splitAtEquals(string& key, string& value){
494 if(value.find_first_of('=') != -1){
495 key = value.substr(0,value.find_first_of('='));
496 if ((value.find_first_of('=')+1) <= value.length()) {
497 value = value.substr(value.find_first_of('=')+1, value.length());
504 catch(exception& e) {
505 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
509 cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
514 /*******************************************************/
516 /******************************************************/