1 #include "globaldata.hpp"
2 #include "sparsematrix.hpp"
4 #include "rabundvector.hpp"
5 #include "sabundvector.hpp"
6 #include "listvector.hpp"
8 /*******************************************************/
10 /******************************************************/
11 GlobalData* GlobalData::getInstance() {
12 if( _uniqueInstance == 0 ) {
13 _uniqueInstance = new GlobalData();
15 return _uniqueInstance;
17 /*******************************************************/
19 /******************************************************/
21 ListVector* GlobalData::getListVector() { return gListVector; }
22 /*******************************************************/
24 /******************************************************/
25 void GlobalData::setListVector(ListVector* lv){
27 if(gListVector != NULL){ delete gListVector; }
28 gListVector = new ListVector(*lv);
31 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
35 cout << "An unknown error has occurred in the GlobalData class function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
39 /*******************************************************/
41 /******************************************************/
43 SparseMatrix* GlobalData::getSparseMatrix() { return gSparseMatrix; }
44 /*******************************************************/
46 /******************************************************/
47 void GlobalData::setSparseMatrix(SparseMatrix* sm){
49 if(gSparseMatrix != NULL){ delete gSparseMatrix; }
50 gSparseMatrix = new SparseMatrix(*sm);
53 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57 cout << "An unknown error has occurred in the GlobalData class function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
61 /*******************************************************/
63 /******************************************************/
64 //This function parses through the option string of the command to remove its parameters
65 void GlobalData::parseGlobalData(string commandString, string optionText){
68 commandName = commandString; //save command name to be used by other classes
70 //set all non filename paramters to default
73 //clears out data from previous read
74 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree") || (commandName == "read.shared")) {
78 labels.clear(); lines.clear(); groups.clear();
83 if (commandName =="help") {
84 helpRequest = optionText;
88 //reads in parameters and values
89 if((optionText != "") && (commandName != "help")){
90 while((optionText.find_first_of(',') != -1)) { //while there are parameters
91 splitAtComma(value, optionText);
92 splitAtEquals(key, value);
94 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
95 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
96 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
97 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
98 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
99 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
100 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
101 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
102 if (key == "name" ) { namefile = value; }
103 if (key == "order" ) { orderfile = value; }
104 if (key == "group" ) { groupfile = value; }
105 if (key == "cutoff" ) { cutoff = value; }
106 if (key == "precision" ) { precision = value; }
107 if (key == "iters" ) { iters = value; }
108 if (key == "jumble" ) { jumble = value; }
109 if (key == "freq" ) { freq = value; }
110 if (key == "method" ) { method = value; }
111 if (key == "fileroot" ) { fileroot = value; }
112 if (key == "random" ) { randomtree = value; }
113 if (key == "groups" ) { groups = value; }
114 if (key == "calc") { calc = value; }
116 if (key == "line") {//stores lines to be used in a set
120 splitAtDash(value, lines);
123 if (key == "label") {//stores labels to be used in a set
127 splitAtDash(value, labels);
130 if (key == "groups") {//stores groups to be used in a vector
133 splitAtDash(value, Groups);
137 //saves the last parameter
139 splitAtEquals(key, value);
140 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
141 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
142 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
143 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
144 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
145 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
146 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
147 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
148 if (key == "name" ) { namefile = value; }
149 if (key == "order" ) { orderfile = value; }
150 if (key == "group" ) { groupfile = value; }
151 if (key == "cutoff" ) { cutoff = value; }
152 if (key == "precision" ) { precision = value; }
153 if (key == "iters" ) { iters = value; }
154 if (key == "jumble" ) { jumble = value; }
155 if (key == "freq" ) { freq = value; }
156 if (key == "method" ) { method = value; }
157 if (key == "fileroot" ) { fileroot = value; }
158 if (key == "random" ) { randomtree = value; }
159 if (key == "groups" ) { groups = value; }
160 if (key == "calc") { calc = value; }
163 if (key == "line") {//stores lines to be used in a vector
167 splitAtDash(value, lines);
170 if (key == "label") {//stores lines to be used in a vector
174 splitAtDash(value, labels);
177 if (key == "groups") {//stores groups to be used in a vector
180 splitAtDash(value, Groups);
184 //set format for shared
185 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
187 //input defaults for calculators
188 if (commandName == "collect.single") {
189 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
191 splitAtDash(calc, Estimators);
193 if (commandName == "rarefaction.single") {
194 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
196 splitAtDash(calc, Estimators);
198 if (commandName == "collect.shared") {
199 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
201 splitAtDash(calc, Estimators);
203 if (commandName == "summary.single") {
204 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
206 splitAtDash(calc, Estimators);
208 if (commandName == "summary.shared") {
209 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
211 splitAtDash(calc, Estimators);
213 if (commandName == "rarefaction.shared") {
214 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
216 splitAtDash(calc, Estimators);
219 //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
220 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
221 if (listfile != "") { format = "list"; }
222 else if (sabundfile != "") { format = "sabund"; }
223 else if (rabundfile != "") { format = "rabund"; }
226 catch(exception& e) {
227 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
231 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
235 /*******************************************************/
237 /******************************************************/
238 // These functions give you the option parameters of the commands
239 string GlobalData::getPhylipFile() { return phylipfile; }
240 string GlobalData::getColumnFile() { return columnfile; }
241 string GlobalData::getListFile() { return listfile; }
242 string GlobalData::getRabundFile() { return rabundfile; }
243 string GlobalData::getSabundFile() { return sabundfile; }
244 string GlobalData::getNameFile() { return namefile; }
245 string GlobalData::getGroupFile() { return groupfile; }
246 string GlobalData::getOrderFile() { return orderfile; }
247 string GlobalData::getTreeFile() { return treefile; }
248 string GlobalData::getSharedFile() { return sharedfile; }
249 string GlobalData::getFastaFile() { return fastafile; }
250 string GlobalData::getCutOff() { return cutoff; }
251 string GlobalData::getFormat() { return format; }
252 string GlobalData::getPrecision() { return precision; }
253 string GlobalData::getMethod() { return method; }
254 string GlobalData::getFileRoot() { return fileroot; }
255 string GlobalData::getIters() { return iters; }
256 string GlobalData::getJumble() { return jumble; }
257 string GlobalData::getFreq() { return freq; }
258 string GlobalData::getRandomTree() { return randomtree; }
259 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
260 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
261 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
262 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
263 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
264 void GlobalData::setNameFile(string file) { namefile = file; }
265 void GlobalData::setFormat(string Format) { format = Format; }
266 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
267 void GlobalData::setCalc(string Calc) { calc = Calc; }
269 /*******************************************************/
271 /******************************************************/
272 GlobalData::GlobalData() {
273 //option definitions should go here...
277 /*******************************************************/
279 /******************************************************/
280 void GlobalData::clear() {
281 //option definitions should go here...
300 jumble = "1"; //0 means don't jumble, 1 means jumble.
301 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
307 /*******************************************************/
309 /******************************************************/
310 void GlobalData::reset() {
317 jumble = "1"; //0 means don't jumble, 1 means jumble.
318 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
323 /*******************************************************/
325 /******************************************************/
326 GlobalData::~GlobalData() {
328 if(gListVector != NULL) { delete gListVector; }
329 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
330 if(gorder != NULL) { delete gorder; }
332 /*******************************************************/
334 /******************************************************/