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();
82 if (commandName =="help") {
83 helpRequest = optionText;
87 //reads in parameters and values
88 if((optionText != "") && (commandName != "help")){
89 while((optionText.find_first_of(',') != -1)) { //while there are parameters
90 splitAtComma(value, optionText);
91 splitAtEquals(key, value);
93 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
94 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
95 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
96 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
97 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
98 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
99 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
100 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
101 if (key == "name" ) { namefile = value; }
102 if (key == "order" ) { orderfile = value; }
103 if (key == "group" ) { groupfile = value; }
104 if (key == "cutoff" ) { cutoff = value; }
105 if (key == "precision" ) { precision = value; }
106 if (key == "iters" ) { iters = value; }
107 if (key == "jumble" ) { jumble = value; }
108 if (key == "freq" ) { freq = value; }
109 if (key == "method" ) { method = value; }
110 if (key == "fileroot" ) { fileroot = value; }
111 if (key == "abund" ) { abund = value; }
112 if (key == "random" ) { randomtree = value; }
113 if (key == "groups" ) { groups = value; }
114 if (key == "calc") { calc = value; }
117 if (key == "line") {//stores lines to be used in a set
121 splitAtDash(value, lines);
124 if (key == "label") {//stores labels to be used in a set
128 splitAtDash(value, labels);
132 if (key == "groups") {//stores groups to be used in a vector
135 splitAtDash(value, Groups);
140 //saves the last parameter
142 splitAtEquals(key, value);
143 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
144 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
145 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
146 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
147 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
148 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
149 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
150 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
151 if (key == "name" ) { namefile = value; }
152 if (key == "order" ) { orderfile = value; }
153 if (key == "group" ) { groupfile = value; }
154 if (key == "cutoff" ) { cutoff = value; }
155 if (key == "precision" ) { precision = value; }
156 if (key == "iters" ) { iters = value; }
157 if (key == "jumble" ) { jumble = value; }
158 if (key == "freq" ) { freq = value; }
159 if (key == "method" ) { method = value; }
160 if (key == "fileroot" ) { fileroot = value; }
161 if (key == "abund" ) { abund = value; }
162 if (key == "random" ) { randomtree = value; }
163 if (key == "groups" ) { groups = value; }
164 if (key == "calc") { calc = value; }
167 if (key == "line") {//stores lines to be used in a vector
171 splitAtDash(value, lines);
174 if (key == "label") {//stores lines to be used in a vector
178 splitAtDash(value, labels);
181 if (key == "groups") {//stores groups to be used in a vector
184 splitAtDash(value, Groups);
188 //set format for shared
189 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
191 //input defaults for calculators
192 if (commandName == "collect.single") {
193 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
195 splitAtDash(calc, Estimators);
197 if (commandName == "rarefaction.single") {
198 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
200 splitAtDash(calc, Estimators);
202 if (commandName == "collect.shared") {
203 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
205 splitAtDash(calc, Estimators);
207 if (commandName == "summary.single") {
208 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
210 splitAtDash(calc, Estimators);
212 if (commandName == "summary.shared") {
213 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
215 splitAtDash(calc, Estimators);
217 if (commandName == "rarefaction.shared") {
218 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
220 splitAtDash(calc, Estimators);
223 //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
224 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
225 if (listfile != "") { format = "list"; }
226 else if (sabundfile != "") { format = "sabund"; }
227 else if (rabundfile != "") { format = "rabund"; }
230 catch(exception& e) {
231 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
235 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
239 /*******************************************************/
241 /******************************************************/
242 // These functions give you the option parameters of the commands
243 string GlobalData::getPhylipFile() { return phylipfile; }
244 string GlobalData::getColumnFile() { return columnfile; }
245 string GlobalData::getListFile() { return listfile; }
246 string GlobalData::getRabundFile() { return rabundfile; }
247 string GlobalData::getSabundFile() { return sabundfile; }
248 string GlobalData::getNameFile() { return namefile; }
249 string GlobalData::getGroupFile() { return groupfile; }
250 string GlobalData::getOrderFile() { return orderfile; }
251 string GlobalData::getTreeFile() { return treefile; }
252 string GlobalData::getSharedFile() { return sharedfile; }
253 string GlobalData::getFastaFile() { return fastafile; }
254 string GlobalData::getCutOff() { return cutoff; }
255 string GlobalData::getFormat() { return format; }
256 string GlobalData::getPrecision() { return precision; }
257 string GlobalData::getMethod() { return method; }
258 string GlobalData::getFileRoot() { return fileroot; }
259 string GlobalData::getIters() { return iters; }
260 string GlobalData::getJumble() { return jumble; }
261 string GlobalData::getFreq() { return freq; }
262 string GlobalData::getAbund() { return abund; }
263 string GlobalData::getRandomTree() { return randomtree; }
264 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
265 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
266 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
267 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
268 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
269 void GlobalData::setNameFile(string file) { namefile = file; }
270 void GlobalData::setFormat(string Format) { format = Format; }
271 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
272 void GlobalData::setCalc(string Calc) { calc = Calc; }
274 /*******************************************************/
276 /******************************************************/
277 GlobalData::GlobalData() {
278 //option definitions should go here...
282 /*******************************************************/
284 /******************************************************/
285 void GlobalData::clear() {
286 //option definitions should go here...
305 jumble = "1"; //0 means don't jumble, 1 means jumble.
306 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
313 //*******************************************************/
315 /******************************************************/
316 void GlobalData::reset() {
323 jumble = "1"; //0 means don't jumble, 1 means jumble.
324 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
330 /*******************************************************/
332 /******************************************************/
333 GlobalData::~GlobalData() {
335 if(gListVector != NULL) { delete gListVector; }
336 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
337 if(gorder != NULL) { delete gorder; }
339 /*******************************************************/