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 /******************************************************/
20 //This function parses through the option string of the command to remove its parameters
21 void GlobalData::parseGlobalData(string commandString, string optionText){
23 commandName = commandString; //save command name to be used by other classes
25 //set all non filename paramters to default
28 //clears out data from previous read
29 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) {
33 labels.clear(); lines.clear(); groups.clear();
38 if (commandName =="help") {
39 helpRequest = optionText;
42 if (commandName == "libshuff") {
48 //reads in parameters and values
49 if((optionText != "") && (commandName != "help")){
50 while((optionText.find_first_of(',') != -1)) { //while there are parameters
51 splitAtComma(value, optionText);
52 splitAtEquals(key, value);
54 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
55 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
56 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
57 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
58 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
59 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
60 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
61 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
62 if (key == "name" ) { namefile = value; }
63 if (key == "order" ) { orderfile = value; }
64 if (key == "group" ) { groupfile = value; }
65 if (key == "cutoff" ) { cutoff = value; }
66 if (key == "precision" ) { precision = value; }
67 if (key == "iters" ) { iters = value; }
68 if (key == "jumble" ) { jumble = value; }
69 if (key == "freq" ) { freq = value; }
70 if (key == "method" ) { method = value; }
71 if (key == "fileroot" ) { fileroot = value; }
72 if (key == "abund" ) { abund = value; }
73 if (key == "random" ) { randomtree = value; }
74 if (key == "calc") { calc = value; }
75 if (key == "step") { step = value; }
76 if (key == "form") { form = value; }
80 if (key == "line") {//stores lines to be used in a set
85 splitAtDash(value, lines);
88 if (key == "label") {//stores labels to be used in a set
93 splitAtDash(value, labels);
97 if (key == "groups") {//stores groups to be used in a vector
100 splitAtDash(value, Groups);
105 //saves the last parameter
107 splitAtEquals(key, value);
108 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
109 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
110 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
111 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
112 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
113 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
114 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
115 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
116 if (key == "name" ) { namefile = value; }
117 if (key == "order" ) { orderfile = value; }
118 if (key == "group" ) { groupfile = value; }
119 if (key == "cutoff" ) { cutoff = value; }
120 if (key == "precision" ) { precision = value; }
121 if (key == "iters" ) { iters = value; }
122 if (key == "jumble" ) { jumble = value; }
123 if (key == "freq" ) { freq = value; }
124 if (key == "method" ) { method = value; }
125 if (key == "fileroot" ) { fileroot = value; }
126 if (key == "abund" ) { abund = value; }
127 if (key == "random" ) { randomtree = value; }
128 if (key == "calc") { calc = value; }
129 if (key == "step") { step = value; }
130 if (key == "form") { form = value; }
132 if (key == "line") {//stores lines to be used in a vector
137 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
138 else { allLines = 1; }
140 if (key == "label") {//stores lines to be used in a vector
145 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
146 else { allLines = 1; }
149 if (key == "groups") {//stores groups to be used in a vector
152 splitAtDash(value, Groups);
156 //set format for shared
157 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
158 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
160 //input defaults for calculators
161 if (commandName == "collect.single") {
162 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-qstat-logsd-bergerparker-bstick"; }
164 splitAtDash(calc, Estimators);
166 if (commandName == "rarefaction.single") {
167 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
169 splitAtDash(calc, Estimators);
171 if (commandName == "collect.shared") {
172 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
174 splitAtDash(calc, Estimators);
176 if (commandName == "summary.single") {
177 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-logsd-qstat-bergerparker-bstick"; }
179 splitAtDash(calc, Estimators);
181 if (commandName == "summary.shared") {
182 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
184 splitAtDash(calc, Estimators);
186 if (commandName == "rarefaction.shared") {
187 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
189 splitAtDash(calc, Estimators);
192 //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
193 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
194 if (listfile != "") { format = "list"; }
195 else if (sabundfile != "") { format = "sabund"; }
196 else if (rabundfile != "") { format = "rabund"; }
199 catch(exception& e) {
200 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
204 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
208 /*******************************************************/
210 /******************************************************/
211 // These functions give you the option parameters of the commands
212 string GlobalData::getPhylipFile() { return phylipfile; }
213 string GlobalData::getColumnFile() { return columnfile; }
214 string GlobalData::getListFile() { return listfile; }
215 string GlobalData::getRabundFile() { return rabundfile; }
216 string GlobalData::getSabundFile() { return sabundfile; }
217 string GlobalData::getNameFile() { return namefile; }
218 string GlobalData::getGroupFile() { return groupfile; }
219 string GlobalData::getOrderFile() { return orderfile; }
220 string GlobalData::getTreeFile() { return treefile; }
221 string GlobalData::getSharedFile() { return sharedfile; }
222 string GlobalData::getFastaFile() { return fastafile; }
223 string GlobalData::getCutOff() { return cutoff; }
224 string GlobalData::getFormat() { return format; }
225 string GlobalData::getPrecision() { return precision; }
226 string GlobalData::getMethod() { return method; }
227 string GlobalData::getFileRoot() { return fileroot; }
228 string GlobalData::getIters() { return iters; }
229 string GlobalData::getJumble() { return jumble; }
230 string GlobalData::getFreq() { return freq; }
231 string GlobalData::getAbund() { return abund; }
232 string GlobalData::getRandomTree() { return randomtree; }
233 string GlobalData::getGroups() { return groups; }
234 string GlobalData::getStep() { return step; }
235 string GlobalData::getForm() { return form; }
236 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
237 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
238 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
239 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
240 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
241 void GlobalData::setNameFile(string file) { namefile = file; }
242 void GlobalData::setFormat(string Format) { format = Format; }
243 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
244 void GlobalData::setGroups(string g) { groups = g; }
245 void GlobalData::setCalc(string Calc) { calc = Calc; }
247 /*******************************************************/
249 /******************************************************/
250 GlobalData::GlobalData() {
251 //option definitions should go here...
255 /*******************************************************/
257 /******************************************************/
258 void GlobalData::clear() {
259 //option definitions should go here...
278 jumble = "1"; //0 means don't jumble, 1 means jumble.
279 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
288 //*******************************************************/
290 /******************************************************/
291 void GlobalData::reset() {
296 jumble = "1"; //0 means don't jumble, 1 means jumble.
297 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
305 /*******************************************************/
307 /******************************************************/
308 GlobalData::~GlobalData() {
310 if(gListVector != NULL) { delete gListVector; }
311 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
312 if(gorder != NULL) { delete gorder; }
314 /*******************************************************/