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;
43 //reads in parameters and values
44 if((optionText != "") && (commandName != "help")){
45 while((optionText.find_first_of(',') != -1)) { //while there are parameters
46 splitAtComma(value, optionText);
47 splitAtEquals(key, value);
49 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
50 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
51 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
52 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
53 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
54 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
55 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
56 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
57 if (key == "name" ) { namefile = value; }
58 if (key == "order" ) { orderfile = value; }
59 if (key == "group" ) { groupfile = value; }
60 if (key == "cutoff" ) { cutoff = value; }
61 if (key == "precision" ) { precision = value; }
62 if (key == "iters" ) { iters = value; }
63 if (key == "jumble" ) { jumble = value; }
64 if (key == "freq" ) { freq = value; }
65 if (key == "method" ) { method = value; }
66 if (key == "fileroot" ) { fileroot = value; }
67 if (key == "abund" ) { abund = value; }
68 if (key == "random" ) { randomtree = value; }
69 if (key == "calc") { calc = value; }
72 if (key == "line") {//stores lines to be used in a set
76 splitAtDash(value, lines);
79 if (key == "label") {//stores labels to be used in a set
83 splitAtDash(value, labels);
87 if (key == "groups") {//stores groups to be used in a vector
90 splitAtDash(value, Groups);
95 //saves the last parameter
97 splitAtEquals(key, value);
98 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
99 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
100 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
101 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
102 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
103 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
104 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
105 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
106 if (key == "name" ) { namefile = value; }
107 if (key == "order" ) { orderfile = value; }
108 if (key == "group" ) { groupfile = value; }
109 if (key == "cutoff" ) { cutoff = value; }
110 if (key == "precision" ) { precision = value; }
111 if (key == "iters" ) { iters = value; }
112 if (key == "jumble" ) { jumble = value; }
113 if (key == "freq" ) { freq = value; }
114 if (key == "method" ) { method = value; }
115 if (key == "fileroot" ) { fileroot = value; }
116 if (key == "abund" ) { abund = value; }
117 if (key == "random" ) { randomtree = value; }
118 if (key == "calc") { calc = value; }
121 if (key == "line") {//stores lines to be used in a vector
125 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
126 else { allLines = 1; }
128 if (key == "label") {//stores lines to be used in a vector
132 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
133 else { allLines = 1; }
136 if (key == "groups") {//stores groups to be used in a vector
139 splitAtDash(value, Groups);
143 //set format for shared
144 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
145 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
147 //input defaults for calculators
148 if (commandName == "collect.single") {
149 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
151 splitAtDash(calc, Estimators);
153 if (commandName == "rarefaction.single") {
154 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
156 splitAtDash(calc, Estimators);
158 if (commandName == "collect.shared") {
159 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
161 splitAtDash(calc, Estimators);
163 if (commandName == "summary.single") {
164 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
166 splitAtDash(calc, Estimators);
168 if (commandName == "summary.shared") {
169 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
171 splitAtDash(calc, Estimators);
173 if (commandName == "rarefaction.shared") {
174 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
176 splitAtDash(calc, Estimators);
179 //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
180 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
181 if (listfile != "") { format = "list"; }
182 else if (sabundfile != "") { format = "sabund"; }
183 else if (rabundfile != "") { format = "rabund"; }
186 catch(exception& e) {
187 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
191 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
195 /*******************************************************/
197 /******************************************************/
198 // These functions give you the option parameters of the commands
199 string GlobalData::getPhylipFile() { return phylipfile; }
200 string GlobalData::getColumnFile() { return columnfile; }
201 string GlobalData::getListFile() { return listfile; }
202 string GlobalData::getRabundFile() { return rabundfile; }
203 string GlobalData::getSabundFile() { return sabundfile; }
204 string GlobalData::getNameFile() { return namefile; }
205 string GlobalData::getGroupFile() { return groupfile; }
206 string GlobalData::getOrderFile() { return orderfile; }
207 string GlobalData::getTreeFile() { return treefile; }
208 string GlobalData::getSharedFile() { return sharedfile; }
209 string GlobalData::getFastaFile() { return fastafile; }
210 string GlobalData::getCutOff() { return cutoff; }
211 string GlobalData::getFormat() { return format; }
212 string GlobalData::getPrecision() { return precision; }
213 string GlobalData::getMethod() { return method; }
214 string GlobalData::getFileRoot() { return fileroot; }
215 string GlobalData::getIters() { return iters; }
216 string GlobalData::getJumble() { return jumble; }
217 string GlobalData::getFreq() { return freq; }
218 string GlobalData::getAbund() { return abund; }
219 string GlobalData::getRandomTree() { return randomtree; }
220 string GlobalData::getGroups() { return groups; }
221 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
222 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
223 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
224 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
225 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
226 void GlobalData::setNameFile(string file) { namefile = file; }
227 void GlobalData::setFormat(string Format) { format = Format; }
228 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
229 void GlobalData::setGroups(string g) { groups = g; }
230 void GlobalData::setCalc(string Calc) { calc = Calc; }
232 /*******************************************************/
234 /******************************************************/
235 GlobalData::GlobalData() {
236 //option definitions should go here...
240 /*******************************************************/
242 /******************************************************/
243 void GlobalData::clear() {
244 //option definitions should go here...
263 jumble = "1"; //0 means don't jumble, 1 means jumble.
264 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
271 //*******************************************************/
273 /******************************************************/
274 void GlobalData::reset() {
279 jumble = "1"; //0 means don't jumble, 1 means jumble.
280 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
286 /*******************************************************/
288 /******************************************************/
289 GlobalData::~GlobalData() {
291 if(gListVector != NULL) { delete gListVector; }
292 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
293 if(gorder != NULL) { delete gorder; }
295 /*******************************************************/