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 values
73 //clears out data from previous read
74 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree") || (commandName == "read.shared")) {
80 if (commandName =="help") {
81 helpRequest = optionText;
85 //reads in parameters and values
86 if((optionText != "") && (commandName != "help")){
87 while((optionText.find_first_of(',') != -1)) { //while there are parameters
88 splitAtComma(value, optionText);
89 splitAtEquals(key, value);
91 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
92 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
93 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
94 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
95 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
96 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
97 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
98 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
99 if (key == "name" ) { namefile = value; }
100 if (key == "order" ) { orderfile = value; }
101 if (key == "group" ) { groupfile = value; }
102 if (key == "cutoff" ) { cutoff = value; }
103 if (key == "precision" ) { precision = value; }
104 if (key == "iters" ) { iters = value; }
105 if (key == "jumble" ) { jumble = value; }
106 if (key == "freq" ) { freq = value; }
107 if (key == "method" ) { method = value; }
108 if (key == "fileroot" ) { fileroot = value; }
109 if (key == "randomtree" ) { randomtree = value; }
110 if (key == "groups" ) { groups = value; }
111 if (key == "calc") { calc = value; }
113 if (key == "line") {//stores lines to be used in a set
117 splitAtDash(value, lines);
120 if (key == "label") {//stores labels to be used in a set
124 splitAtDash(value, labels);
127 if (key == "groups") {//stores groups to be used in a vector
130 splitAtDash(value, Groups);
134 //saves the last parameter
136 splitAtEquals(key, value);
137 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
138 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
139 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
140 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
141 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
142 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
143 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
144 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
145 if (key == "name" ) { namefile = value; }
146 if (key == "order" ) { orderfile = value; }
147 if (key == "group" ) { groupfile = value; }
148 if (key == "cutoff" ) { cutoff = value; }
149 if (key == "precision" ) { precision = value; }
150 if (key == "iters" ) { iters = value; }
151 if (key == "jumble" ) { jumble = value; }
152 if (key == "freq" ) { freq = value; }
153 if (key == "method" ) { method = value; }
154 if (key == "fileroot" ) { fileroot = value; }
155 if (key == "randomtree" ) { randomtree = value; }
156 if (key == "groups" ) { groups = value; }
157 if (key == "calc") { calc = value; }
160 if (key == "line") {//stores lines to be used in a vector
164 splitAtDash(value, lines);
167 if (key == "label") {//stores lines to be used in a vector
171 splitAtDash(value, labels);
174 if (key == "groups") {//stores groups to be used in a vector
177 splitAtDash(value, Groups);
181 //set format for shared
182 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
184 //input defaults for calculators
185 if (commandName == "collect.single") {
186 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
188 splitAtDash(calc, Estimators);
190 if (commandName == "rarefaction.single") {
191 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
193 splitAtDash(calc, Estimators);
195 if (commandName == "collect.shared") {
196 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
198 splitAtDash(calc, Estimators);
200 if (commandName == "summary.single") {
201 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
203 splitAtDash(calc, Estimators);
205 if (commandName == "summary.shared") {
206 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
208 splitAtDash(calc, Estimators);
210 if (commandName == "rarefaction.shared") {
211 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
213 splitAtDash(calc, Estimators);
216 //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
217 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
218 if (listfile != "") { format = "list"; }
219 else if (sabundfile != "") { format = "sabund"; }
220 else if (rabundfile != "") { format = "rabund"; }
223 catch(exception& e) {
224 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
228 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
232 /*******************************************************/
234 /******************************************************/
235 // These functions give you the option parameters of the commands
236 string GlobalData::getPhylipFile() { return phylipfile; }
237 string GlobalData::getColumnFile() { return columnfile; }
238 string GlobalData::getListFile() { return listfile; }
239 string GlobalData::getRabundFile() { return rabundfile; }
240 string GlobalData::getSabundFile() { return sabundfile; }
241 string GlobalData::getNameFile() { return namefile; }
242 string GlobalData::getGroupFile() { return groupfile; }
243 string GlobalData::getOrderFile() { return orderfile; }
244 string GlobalData::getTreeFile() { return treefile; }
245 string GlobalData::getSharedFile() { return sharedfile; }
246 string GlobalData::getFastaFile() { return fastafile; }
247 string GlobalData::getCutOff() { return cutoff; }
248 string GlobalData::getFormat() { return format; }
249 string GlobalData::getPrecision() { return precision; }
250 string GlobalData::getMethod() { return method; }
251 string GlobalData::getFileRoot() { return fileroot; }
252 string GlobalData::getIters() { return iters; }
253 string GlobalData::getJumble() { return jumble; }
254 string GlobalData::getFreq() { return freq; }
255 string GlobalData::getRandomTree() { return randomtree; }
256 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
257 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
258 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
259 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
260 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
261 void GlobalData::setNameFile(string file) { namefile = file; }
262 void GlobalData::setFormat(string Format) { format = Format; }
263 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
264 void GlobalData::setCalc(string Calc) { calc = Calc; }
266 /*******************************************************/
268 /******************************************************/
269 GlobalData::GlobalData() {
270 //option definitions should go here...
274 /*******************************************************/
276 /******************************************************/
277 void GlobalData::clear() {
278 //option definitions should go here...
297 jumble = "1"; //0 means don't jumble, 1 means jumble.
298 randomtree = "0"; //0 means user will enter some user trees, 1 means they just want the random tree distribution.
304 /*******************************************************/
306 /******************************************************/
307 void GlobalData::reset() {
314 jumble = "1"; //0 means don't jumble, 1 means jumble.
315 randomtree = "0"; //0 means user will enter some user trees, 1 means they just want the random tree distribution.
320 /*******************************************************/
322 /******************************************************/
323 GlobalData::~GlobalData() {
325 if(gListVector != NULL) { delete gListVector; }
326 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
327 if(gorder != NULL) { delete gorder; }
329 /*******************************************************/
331 /******************************************************/