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
83 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.list")) {
88 if (commandName =="help") {
89 helpRequest = optionText;
93 //reads in parameters and values
94 if((optionText != "") && (commandName != "help")){
95 while((optionText.find_first_of(',') != -1)) { //while there are parameters
96 splitAtComma(value, optionText);
97 splitAtEquals(key, value);
99 if (key == "phylipfile" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";}
100 if (key == "columnfile" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column";}
101 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
102 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
103 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
104 if (key == "fastafile" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
105 if (key == "namefile" ) { namefile = value; }
106 if (key == "orderfile" ) { orderfile = value; }
107 if (key == "groupfile" ) { groupfile = value; }
108 if (key == "cutoff" ) { cutoff = value; }
109 if (key == "precision" ) { precision = value; }
110 if (key == "iters" ) { iters = value; }
111 if (key == "jumble" ) { jumble = value; }
112 if (key == "freq" ) { freq = value; }
113 if (key == "method" ) { method = value; }
114 if (key == "fileroot" ) { fileroot = value; }
116 if (key == "single") {//stores estimators in a vector
117 singleEstimators.clear(); //clears out old values
118 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
119 splitAtDash(value, singleEstimators);
121 if (key == "rarefaction") {//stores estimators in a vector
122 rareEstimators.clear(); //clears out old values
123 if (value == "default") { value = "rarefraction"; }
124 splitAtDash(value, rareEstimators);
126 if (key == "shared") {//stores estimators in a vector
127 sharedEstimators.clear(); //clears out old values
128 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
129 splitAtDash(value, sharedEstimators);
131 if (key == "summary") { //stores summaries to be used in a vector
132 summaryEstimators.clear();
133 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
134 splitAtDash(value, summaryEstimators);
136 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
137 sharedSummaryEstimators.clear();
138 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
139 splitAtDash(value, sharedSummaryEstimators);
141 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
142 sharedRareEstimators.clear();
143 if (value == "default") { value = "sharedobserved"; }
144 splitAtDash(value, sharedRareEstimators);
146 if (key == "line") {//stores lines to be used in a vector
149 splitAtDash(value, lines);
152 if (key == "label") {//stores lines to be used in a vector
155 splitAtDash(value, labels);
160 //saves the last parameter
162 splitAtEquals(key, value);
163 if (key == "phylipfile" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
164 if (key == "columnfile" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
165 if (key == "listfile" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
166 if (key == "rabundfile" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
167 if (key == "sabundfile" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
168 if (key == "fastafile" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
169 if (key == "namefile" ) { namefile = value; }
170 if (key == "orderfile" ) { orderfile = value; }
171 if (key == "groupfile" ) { groupfile = value; }
172 if (key == "cutoff" ) { cutoff = value; }
173 if (key == "precision" ) { precision = value; }
174 if (key == "iters" ) { iters = value; }
175 if (key == "jumble" ) { jumble = value; }
176 if (key == "freq" ) { freq = value; }
177 if (key == "method" ) { method = value; }
178 if (key == "fileroot" ) { fileroot = value; }
180 if (key == "single") {//stores estimators in a vector
181 singleEstimators.clear(); //clears out old values
182 if (value == "default") { value = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction"; }
183 splitAtDash(value, singleEstimators);
185 if (key == "rarefaction") {//stores estimators in a vector
186 rareEstimators.clear(); //clears out old values
187 if (value == "default") { value = "rarefraction"; }
188 splitAtDash(value, rareEstimators);
190 if (key == "shared") {//stores estimators in a vector
191 sharedEstimators.clear(); //clears out old values
192 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
193 splitAtDash(value, sharedEstimators);
195 if (key == "summary") { //stores summaries to be used in a vector
196 summaryEstimators.clear();
197 if (value == "default") { value = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
198 splitAtDash(value, summaryEstimators);
200 if (key == "sharedsummary") { //stores sharedSummaries to be used in a vector
201 sharedSummaryEstimators.clear();
202 if (value == "default") { value = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN"; }
203 splitAtDash(value, sharedSummaryEstimators);
205 if (key == "sharedrarefaction") { //stores sharedrarefaction to be used in a vector
206 sharedRareEstimators.clear();
207 if (value == "default") { value = "sharedobserved"; }
208 splitAtDash(value, sharedRareEstimators);
211 if (key == "line") {//stores lines to be used in a vector
214 splitAtDash(value, lines);
217 if (key == "label") {//stores lines to be used in a vector
220 splitAtDash(value, labels);
227 if (commandString == "collect.single") {
228 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
230 if (commandString == "rarefaction.single") {
231 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
233 if (commandString == "collect.shared") {
234 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
236 if (commandString == "summary.single") {
237 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
239 if (commandString == "summary.shared") {
240 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
242 if (commandString == "rarefaction.shared") {
243 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
248 catch(exception& e) {
249 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
253 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
258 /*******************************************************/
260 /******************************************************/
261 // These functions give you the option parameters of the commands
262 string GlobalData::getPhylipFile() { return phylipfile; }
263 string GlobalData::getColumnFile() { return columnfile; }
264 string GlobalData::getListFile() { return listfile; }
265 string GlobalData::getRabundFile() { return rabundfile; }
266 string GlobalData::getSabundFile() { return sabundfile; }
267 string GlobalData::getNameFile() { return namefile; }
268 string GlobalData::getGroupFile() { return groupfile; }
269 string GlobalData::getOrderFile() { return orderfile; }
270 string GlobalData::getFastaFile() { return fastafile; }
271 string GlobalData::getCutOff() { return cutoff; }
272 string GlobalData::getFormat() { return format; }
273 string GlobalData::getPrecision() { return precision; }
274 string GlobalData::getMethod() { return method; }
275 string GlobalData::getFileRoot() { return fileroot; }
276 string GlobalData::getIters() { return iters; }
277 string GlobalData::getJumble() { return jumble; }
278 string GlobalData::getFreq() { return freq; }
279 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
280 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
281 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
282 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
283 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
284 //void GlobalData::setGroupFile(string file) { groupfile = file; }
285 void GlobalData::setNameFile(string file) { namefile = file; }
286 void GlobalData::setFormat(string Format) { format = Format; }
289 /*******************************************************/
291 /******************************************************/
293 GlobalData::GlobalData() {
294 //option definitions should go here...
298 /*******************************************************/
300 /******************************************************/
302 void GlobalData::clear() {
303 //option definitions should go here...
323 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
324 rarefaction = "rarefaction";
325 shared = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
326 sharedsummary = "sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
327 summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
328 sharedrarefaction = "sharedobserved";
330 /*******************************************************/
332 /******************************************************/
334 GlobalData::~GlobalData() {
336 if(gListVector != NULL) { delete gListVector; }
337 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
338 if(gorder != NULL) { delete gorder; }
340 /*******************************************************/
342 /******************************************************/
343 //This function parses the estimator options and puts them in a vector
344 void GlobalData::splitAtDash(string& estim, vector<string>& container) {
348 while (estim.find_first_of('-') != -1) {
349 individual = estim.substr(0,estim.find_first_of('-'));
350 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
351 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
352 container.push_back(individual);
356 container.push_back(estim);
358 catch(exception& e) {
359 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
363 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
368 /*******************************************************/
370 /******************************************************/
371 //This function parses the label options and puts them in a set
372 void GlobalData::splitAtDash(string& estim, set<string>& container) {
376 while (estim.find_first_of('-') != -1) {
377 individual = estim.substr(0,estim.find_first_of('-'));
378 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
379 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
380 container.insert(individual);
384 container.insert(estim);
386 catch(exception& e) {
387 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
391 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
396 /*******************************************************/
398 /******************************************************/
399 //This function parses the line options and puts them in a set
400 void GlobalData::splitAtDash(string& estim, set<int>& container) {
405 while (estim.find_first_of('-') != -1) {
406 individual = estim.substr(0,estim.find_first_of('-'));
407 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
408 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
409 convert(individual, lineNum); //convert the string to int
410 container.insert(lineNum);
414 convert(estim, lineNum); //convert the string to int
415 container.insert(lineNum);
417 catch(exception& e) {
418 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
422 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
427 /*******************************************************/
429 /******************************************************/
431 //This function splits up the various option parameters
432 void GlobalData::splitAtComma(string& prefix, string& suffix){
434 prefix = suffix.substr(0,suffix.find_first_of(','));
435 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
436 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
439 catch(exception& e) {
440 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
444 cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
449 /*******************************************************/
451 /******************************************************/
452 //This function separates the key value from the option value i.e. distfile = "96_..."
453 void GlobalData::splitAtEquals(string& key, string& value){
455 if(value.find_first_of('=') != -1){
456 key = value.substr(0,value.find_first_of('='));
457 if ((value.find_first_of('=')+1) <= value.length()) {
458 value = value.substr(value.find_first_of('=')+1, value.length());
465 catch(exception& e) {
466 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
470 cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
475 /*******************************************************/
477 /******************************************************/