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){
24 commandName = commandString; //save command name to be used by other classes
26 //set all non filename paramters to default
29 //clears out data from previous read
30 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) {
34 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 splitAtDash(value, lines);
128 if (key == "label") {//stores lines to be used in a vector
132 splitAtDash(value, labels);
135 if (key == "groups") {//stores groups to be used in a vector
138 splitAtDash(value, Groups);
142 //set format for shared
143 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
144 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
146 //input defaults for calculators
147 if (commandName == "collect.single") {
148 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
150 splitAtDash(calc, Estimators);
152 if (commandName == "rarefaction.single") {
153 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
155 splitAtDash(calc, Estimators);
157 if (commandName == "collect.shared") {
158 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
160 splitAtDash(calc, Estimators);
162 if (commandName == "summary.single") {
163 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
165 splitAtDash(calc, Estimators);
167 if (commandName == "summary.shared") {
168 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
170 splitAtDash(calc, Estimators);
172 if (commandName == "rarefaction.shared") {
173 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
175 splitAtDash(calc, Estimators);
178 //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
179 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
180 if (listfile != "") { format = "list"; }
181 else if (sabundfile != "") { format = "sabund"; }
182 else if (rabundfile != "") { format = "rabund"; }
185 catch(exception& e) {
186 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
190 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
194 /*******************************************************/
196 /******************************************************/
197 // These functions give you the option parameters of the commands
198 string GlobalData::getPhylipFile() { return phylipfile; }
199 string GlobalData::getColumnFile() { return columnfile; }
200 string GlobalData::getListFile() { return listfile; }
201 string GlobalData::getRabundFile() { return rabundfile; }
202 string GlobalData::getSabundFile() { return sabundfile; }
203 string GlobalData::getNameFile() { return namefile; }
204 string GlobalData::getGroupFile() { return groupfile; }
205 string GlobalData::getOrderFile() { return orderfile; }
206 string GlobalData::getTreeFile() { return treefile; }
207 string GlobalData::getSharedFile() { return sharedfile; }
208 string GlobalData::getFastaFile() { return fastafile; }
209 string GlobalData::getCutOff() { return cutoff; }
210 string GlobalData::getFormat() { return format; }
211 string GlobalData::getPrecision() { return precision; }
212 string GlobalData::getMethod() { return method; }
213 string GlobalData::getFileRoot() { return fileroot; }
214 string GlobalData::getIters() { return iters; }
215 string GlobalData::getJumble() { return jumble; }
216 string GlobalData::getFreq() { return freq; }
217 string GlobalData::getAbund() { return abund; }
218 string GlobalData::getRandomTree() { return randomtree; }
219 string GlobalData::getGroups() { return groups; }
220 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
221 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
222 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
223 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
224 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
225 void GlobalData::setNameFile(string file) { namefile = file; }
226 void GlobalData::setFormat(string Format) { format = Format; }
227 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
228 void GlobalData::setGroups(string g) { groups = g; }
229 void GlobalData::setCalc(string Calc) { calc = Calc; }
231 /*******************************************************/
233 /******************************************************/
234 GlobalData::GlobalData() {
235 //option definitions should go here...
239 /*******************************************************/
241 /******************************************************/
242 void GlobalData::clear() {
243 //option definitions should go here...
262 jumble = "1"; //0 means don't jumble, 1 means jumble.
263 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
270 //*******************************************************/
272 /******************************************************/
273 void GlobalData::reset() {
280 jumble = "1"; //0 means don't jumble, 1 means jumble.
281 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
287 /*******************************************************/
289 /******************************************************/
290 GlobalData::~GlobalData() {
292 if(gListVector != NULL) { delete gListVector; }
293 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
294 if(gorder != NULL) { delete gorder; }
296 /*******************************************************/