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);
225 //set format for shared
226 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
229 if (commandString == "collect.single") {
230 if (singleEstimators.size() == 0) { splitAtDash(single, singleEstimators); }
232 if (commandString == "rarefaction.single") {
233 if (rareEstimators.size() == 0) { splitAtDash(rarefaction, rareEstimators); }
235 if (commandString == "collect.shared") {
236 if (sharedEstimators.size() == 0) { splitAtDash(shared, sharedEstimators); }
238 if (commandString == "summary.single") {
239 if (summaryEstimators.size() == 0) { splitAtDash(summary, summaryEstimators); }
241 if (commandString == "summary.shared") {
242 if (sharedSummaryEstimators.size() == 0) { splitAtDash(sharedsummary, sharedSummaryEstimators); }
244 if (commandString == "rarefaction.shared") {
245 if (sharedRareEstimators.size() == 0) { splitAtDash(sharedrarefaction, sharedRareEstimators); }
250 catch(exception& e) {
251 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
255 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
260 /*******************************************************/
262 /******************************************************/
263 // These functions give you the option parameters of the commands
264 string GlobalData::getPhylipFile() { return phylipfile; }
265 string GlobalData::getColumnFile() { return columnfile; }
266 string GlobalData::getListFile() { return listfile; }
267 string GlobalData::getRabundFile() { return rabundfile; }
268 string GlobalData::getSabundFile() { return sabundfile; }
269 string GlobalData::getNameFile() { return namefile; }
270 string GlobalData::getGroupFile() { return groupfile; }
271 string GlobalData::getOrderFile() { return orderfile; }
272 string GlobalData::getFastaFile() { return fastafile; }
273 string GlobalData::getCutOff() { return cutoff; }
274 string GlobalData::getFormat() { return format; }
275 string GlobalData::getPrecision() { return precision; }
276 string GlobalData::getMethod() { return method; }
277 string GlobalData::getFileRoot() { return fileroot; }
278 string GlobalData::getIters() { return iters; }
279 string GlobalData::getJumble() { return jumble; }
280 string GlobalData::getFreq() { return freq; }
281 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
282 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
283 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
284 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
285 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
286 //void GlobalData::setGroupFile(string file) { groupfile = file; }
287 void GlobalData::setNameFile(string file) { namefile = file; }
288 void GlobalData::setFormat(string Format) { format = Format; }
291 /*******************************************************/
293 /******************************************************/
295 GlobalData::GlobalData() {
296 //option definitions should go here...
300 /*******************************************************/
302 /******************************************************/
304 void GlobalData::clear() {
305 //option definitions should go here...
325 single = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-rarefraction";
326 rarefaction = "rarefaction";
327 shared = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
328 sharedsummary = "sharedSobs-sharedChao-sharedAce-sharedJabund-sharedSorensonAbund-sharedJclass-sharedSorClass-sharedJest-sharedSorEst-SharedThetaYC-SharedThetaN";
329 summary = "summary-chao-ace-jack-bootstrap-shannon-npshannon-simpson";
330 sharedrarefaction = "sharedobserved";
332 /*******************************************************/
334 /******************************************************/
336 GlobalData::~GlobalData() {
338 if(gListVector != NULL) { delete gListVector; }
339 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
340 if(gorder != NULL) { delete gorder; }
342 /*******************************************************/
344 /******************************************************/
345 //This function parses the estimator options and puts them in a vector
346 void GlobalData::splitAtDash(string& estim, vector<string>& container) {
350 while (estim.find_first_of('-') != -1) {
351 individual = estim.substr(0,estim.find_first_of('-'));
352 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
353 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
354 container.push_back(individual);
358 container.push_back(estim);
360 catch(exception& e) {
361 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
365 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
370 /*******************************************************/
372 /******************************************************/
373 //This function parses the label options and puts them in a set
374 void GlobalData::splitAtDash(string& estim, set<string>& container) {
378 while (estim.find_first_of('-') != -1) {
379 individual = estim.substr(0,estim.find_first_of('-'));
380 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
381 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
382 container.insert(individual);
386 container.insert(estim);
388 catch(exception& e) {
389 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
393 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
398 /*******************************************************/
400 /******************************************************/
401 //This function parses the line options and puts them in a set
402 void GlobalData::splitAtDash(string& estim, set<int>& container) {
407 while (estim.find_first_of('-') != -1) {
408 individual = estim.substr(0,estim.find_first_of('-'));
409 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
410 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
411 convert(individual, lineNum); //convert the string to int
412 container.insert(lineNum);
416 convert(estim, lineNum); //convert the string to int
417 container.insert(lineNum);
419 catch(exception& e) {
420 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
424 cout << "An unknown error has occurred in the GlobalData class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
429 /*******************************************************/
431 /******************************************************/
433 //This function splits up the various option parameters
434 void GlobalData::splitAtComma(string& prefix, string& suffix){
436 prefix = suffix.substr(0,suffix.find_first_of(','));
437 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
438 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
441 catch(exception& e) {
442 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
446 cout << "An unknown error has occurred in the GlobalData class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
451 /*******************************************************/
453 /******************************************************/
454 //This function separates the key value from the option value i.e. distfile = "96_..."
455 void GlobalData::splitAtEquals(string& key, string& value){
457 if(value.find_first_of('=') != -1){
458 key = value.substr(0,value.find_first_of('='));
459 if ((value.find_first_of('=')+1) <= value.length()) {
460 value = value.substr(value.find_first_of('=')+1, value.length());
467 catch(exception& e) {
468 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
472 cout << "An unknown error has occurred in the GlobalData class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
477 /*******************************************************/
479 /******************************************************/