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; }
118 if (key == "single") {//stores estimators in a vector
119 singleEstimators.clear(); //clears out old values
120 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
121 splitAtDash(value, singleEstimators);
123 if (key == "rarefaction") {//stores estimators in a vector
124 rareEstimators.clear(); //clears out old values
125 if (value == "default") { value = "rarefraction"; }
126 splitAtDash(value, rareEstimators);
128 if (key == "shared") {//stores estimators in a vector
129 sharedEstimators.clear(); //clears out old values
130 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
131 splitAtDash(value, sharedEstimators);
133 if (key == "summary") { //stores summaries to be used in a vector
134 summaryEstimators.clear();
135 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
136 splitAtDash(value, summaryEstimators);
138 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
139 sharedSummaryEstimators.clear();
140 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
141 splitAtDash(value, sharedSummaryEstimators);
143 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
144 sharedRareEstimators.clear();
145 if (value == "default") { value = "sharedobserved"; }
146 splitAtDash(value, sharedRareEstimators);
148 if (key == "line") {//stores lines to be used in a vector
152 splitAtDash(value, lines);
155 if (key == "label") {//stores lines to be used in a vector
159 splitAtDash(value, labels);
164 //saves the last parameter
166 splitAtEquals(key, value);
167 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
168 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
169 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
170 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
171 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
172 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
173 if (key == "treefile" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
174 if (key == "name" ) { namefile = value; }
175 if (key == "order" ) { orderfile = value; }
176 if (key == "group" ) { groupfile = value; }
177 if (key == "cutoff" ) { cutoff = value; }
178 if (key == "precision" ) { precision = value; }
179 if (key == "iters" ) { iters = value; }
180 if (key == "jumble" ) { jumble = value; }
181 if (key == "freq" ) { freq = value; }
182 if (key == "method" ) { method = value; }
183 if (key == "fileroot" ) { fileroot = value; }
185 if (key == "single") {//stores estimators in a vector
186 singleEstimators.clear(); //clears out old values
187 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
188 splitAtDash(value, singleEstimators);
190 if (key == "rarefaction") {//stores estimators in a vector
191 rareEstimators.clear(); //clears out old values
192 if (value == "default") { value = "rarefraction"; }
193 splitAtDash(value, rareEstimators);
195 if (key == "shared") {//stores estimators in a vector
196 sharedEstimators.clear(); //clears out old values
197 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
198 splitAtDash(value, sharedEstimators);
200 if (key == "summary") { //stores summaries to be used in a vector
201 summaryEstimators.clear();
202 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
203 splitAtDash(value, summaryEstimators);
205 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
206 sharedSummaryEstimators.clear();
207 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
208 splitAtDash(value, sharedSummaryEstimators);
210 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
211 sharedRareEstimators.clear();
212 if (value == "default") { value = "sharedobserved"; }
213 splitAtDash(value, sharedRareEstimators);
216 if (key == "line") {//stores lines to be used in a vector
220 splitAtDash(value, lines);
223 if (key == "label") {//stores lines to be used in a vector
227 splitAtDash(value, labels);
232 //set format for shared
233 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
236 if (commandName == "collect.single") {
237 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
239 if (commandName == "rarefaction.single") {
240 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
242 if (commandName == "collect.shared") {
243 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
245 if (commandName == "summary.single") {
246 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
248 if (commandName == "summary.shared") {
249 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
251 if (commandName == "rarefaction.shared") {
252 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
256 //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
257 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
258 if (listfile != "") { format = "list"; }
259 else if (sabundfile != "") { format = "sabund"; }
260 else if (rabundfile != "") { format = "rabund"; }
264 catch(exception& e) {
265 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
269 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
274 /*******************************************************/
276 /******************************************************/
277 // These functions give you the option parameters of the commands
278 string GlobalData::getPhylipFile() { return phylipfile; }
279 string GlobalData::getColumnFile() { return columnfile; }
280 string GlobalData::getListFile() { return listfile; }
281 string GlobalData::getRabundFile() { return rabundfile; }
282 string GlobalData::getSabundFile() { return sabundfile; }
283 string GlobalData::getNameFile() { return namefile; }
284 string GlobalData::getGroupFile() { return groupfile; }
285 string GlobalData::getOrderFile() { return orderfile; }
286 string GlobalData::getTreeFile() { return treefile; }
287 string GlobalData::getFastaFile() { return fastafile; }
288 string GlobalData::getCutOff() { return cutoff; }
289 string GlobalData::getFormat() { return format; }
290 string GlobalData::getPrecision() { return precision; }
291 string GlobalData::getMethod() { return method; }
292 string GlobalData::getFileRoot() { return fileroot; }
293 string GlobalData::getIters() { return iters; }
294 string GlobalData::getJumble() { return jumble; }
295 string GlobalData::getFreq() { return freq; }
296 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
297 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
298 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
299 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
300 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
301 //void GlobalData::setGroupFile(string file) { groupfile = file; }
302 void GlobalData::setNameFile(string file) { namefile = file; }
303 void GlobalData::setFormat(string Format) { format = Format; }
306 /*******************************************************/
308 /******************************************************/
310 GlobalData::GlobalData() {
311 //option definitions should go here...
315 /*******************************************************/
317 /******************************************************/
319 void GlobalData::clear() {
320 //option definitions should go here...
341 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
342 rarefaction = "sobs";
343 shared = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
344 sharedsummary = "sharedSobs-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 /******************************************************/