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 == "phylipfile" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
101 if (key == "columnfile" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
102 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
103 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
104 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
105 if (key == "fastafile" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
106 if (key == "treefile" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
107 if (key == "namefile" ) { namefile = value; }
108 if (key == "orderfile" ) { orderfile = value; }
109 if (key == "groupfile" ) { 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
151 splitAtDash(value, lines);
154 if (key == "label") {//stores lines to be used in a vector
157 splitAtDash(value, labels);
162 //saves the last parameter
164 splitAtEquals(key, value);
165 if (key == "phylipfile" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
166 if (key == "columnfile" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
167 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
168 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
169 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
170 if (key == "fastafile" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
171 if (key == "treefile" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
172 if (key == "namefile" ) { namefile = value; }
173 if (key == "orderfile" ) { orderfile = value; }
174 if (key == "groupfile" ) { groupfile = value; }
175 if (key == "cutoff" ) { cutoff = value; }
176 if (key == "precision" ) { precision = value; }
177 if (key == "iters" ) { iters = value; }
178 if (key == "jumble" ) { jumble = value; }
179 if (key == "freq" ) { freq = value; }
180 if (key == "method" ) { method = value; }
181 if (key == "fileroot" ) { fileroot = value; }
183 if (key == "single") {//stores estimators in a vector
184 singleEstimators.clear(); //clears out old values
185 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
186 splitAtDash(value, singleEstimators);
188 if (key == "rarefaction") {//stores estimators in a vector
189 rareEstimators.clear(); //clears out old values
190 if (value == "default") { value = "rarefraction"; }
191 splitAtDash(value, rareEstimators);
193 if (key == "shared") {//stores estimators in a vector
194 sharedEstimators.clear(); //clears out old values
195 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
196 splitAtDash(value, sharedEstimators);
198 if (key == "summary") { //stores summaries to be used in a vector
199 summaryEstimators.clear();
200 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
201 splitAtDash(value, summaryEstimators);
203 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
204 sharedSummaryEstimators.clear();
205 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
206 splitAtDash(value, sharedSummaryEstimators);
208 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
209 sharedRareEstimators.clear();
210 if (value == "default") { value = "sharedobserved"; }
211 splitAtDash(value, sharedRareEstimators);
214 if (key == "line") {//stores lines to be used in a vector
217 splitAtDash(value, lines);
220 if (key == "label") {//stores lines to be used in a vector
223 splitAtDash(value, labels);
228 //set format for shared
229 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
232 if (commandName == "collect.single") {
233 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
235 if (commandName == "rarefaction.single") {
236 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
238 if (commandName == "collect.shared") {
239 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
241 if (commandName == "summary.single") {
242 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
244 if (commandName == "summary.shared") {
245 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
247 if (commandName == "rarefaction.shared") {
248 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
252 //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
253 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
254 if (listfile != "") { format = "list"; }
255 else if (sabundfile != "") { format = "sabund"; }
256 else if (rabundfile != "") { format = "rabund"; }
260 catch(exception& e) {
261 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
265 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
270 /*******************************************************/
272 /******************************************************/
273 // These functions give you the option parameters of the commands
274 string GlobalData::getPhylipFile() { return phylipfile; }
275 string GlobalData::getColumnFile() { return columnfile; }
276 string GlobalData::getListFile() { return listfile; }
277 string GlobalData::getRabundFile() { return rabundfile; }
278 string GlobalData::getSabundFile() { return sabundfile; }
279 string GlobalData::getNameFile() { return namefile; }
280 string GlobalData::getGroupFile() { return groupfile; }
281 string GlobalData::getOrderFile() { return orderfile; }
282 string GlobalData::getTreeFile() { return treefile; }
283 string GlobalData::getFastaFile() { return fastafile; }
284 string GlobalData::getCutOff() { return cutoff; }
285 string GlobalData::getFormat() { return format; }
286 string GlobalData::getPrecision() { return precision; }
287 string GlobalData::getMethod() { return method; }
288 string GlobalData::getFileRoot() { return fileroot; }
289 string GlobalData::getIters() { return iters; }
290 string GlobalData::getJumble() { return jumble; }
291 string GlobalData::getFreq() { return freq; }
292 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
293 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
294 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
295 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
296 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
297 //void GlobalData::setGroupFile(string file) { groupfile = file; }
298 void GlobalData::setNameFile(string file) { namefile = file; }
299 void GlobalData::setFormat(string Format) { format = Format; }
302 /*******************************************************/
304 /******************************************************/
306 GlobalData::GlobalData() {
307 //option definitions should go here...
311 /*******************************************************/
313 /******************************************************/
315 void GlobalData::clear() {
316 //option definitions should go here...
337 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
338 rarefaction = "rarefaction";
339 shared = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
340 sharedsummary = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
341 summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
342 sharedrarefaction = "sharedobserved";
344 /*******************************************************/
346 /******************************************************/
348 GlobalData::~GlobalData() {
350 if(gListVector != NULL) { delete gListVector; }
351 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
352 if(gorder != NULL) { delete gorder; }
354 /*******************************************************/
356 /******************************************************/
357 //This function parses the estimator options and puts them in a vector
358 void GlobalData::splitAtDash(string& estim, vector<string>& container) {
362 while (estim.find_first_of('-') != -1) {
363 individual = estim.substr(0,estim.find_first_of('-'));
364 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
365 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
366 container.push_back(individual);
370 container.push_back(estim);
372 catch(exception& e) {
373 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
377 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
382 /*******************************************************/
384 /******************************************************/
385 //This function parses the label options and puts them in a set
386 void GlobalData::splitAtDash(string& estim, set<string>& container) {
390 while (estim.find_first_of('-') != -1) {
391 individual = estim.substr(0,estim.find_first_of('-'));
392 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
393 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
394 container.insert(individual);
398 container.insert(estim);
400 catch(exception& e) {
401 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
405 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
410 /*******************************************************/
412 /******************************************************/
413 //This function parses the line options and puts them in a set
414 void GlobalData::splitAtDash(string& estim, set<int>& container) {
419 while (estim.find_first_of('-') != -1) {
420 individual = estim.substr(0,estim.find_first_of('-'));
421 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
422 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
423 convert(individual, lineNum); //convert the string to int
424 container.insert(lineNum);
428 convert(estim, lineNum); //convert the string to int
429 container.insert(lineNum);
431 catch(exception& e) {
432 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
436 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
441 /*******************************************************/
443 /******************************************************/
445 //This function splits up the various option parameters
446 void GlobalData::splitAtComma(string& prefix, string& suffix){
448 prefix = suffix.substr(0,suffix.find_first_of(','));
449 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
450 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
453 catch(exception& e) {
454 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
458 cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
463 /*******************************************************/
465 /******************************************************/
466 //This function separates the key value from the option value i.e. distfile = "96_..."
467 void GlobalData::splitAtEquals(string& key, string& value){
469 if(value.find_first_of('=') != -1){
470 key = value.substr(0,value.find_first_of('='));
471 if ((value.find_first_of('=')+1) <= value.length()) {
472 value = value.substr(value.find_first_of('=')+1, value.length());
479 catch(exception& e) {
480 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
484 cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
489 /*******************************************************/
491 /******************************************************/