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; }
77 if (key == "sorted") { sorted = value; }
81 if (key == "line") {//stores lines to be used in a set
86 splitAtDash(value, lines);
89 if (key == "label") {//stores labels to be used in a set
94 splitAtDash(value, labels);
98 if (key == "groups") {//stores groups to be used in a vector
101 splitAtDash(value, Groups);
106 //saves the last parameter
108 splitAtEquals(key, value);
109 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
110 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
111 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
112 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
113 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
114 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
115 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
116 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
117 if (key == "name" ) { namefile = value; }
118 if (key == "order" ) { orderfile = value; }
119 if (key == "group" ) { groupfile = value; }
120 if (key == "cutoff" ) { cutoff = value; }
121 if (key == "precision" ) { precision = value; }
122 if (key == "iters" ) { iters = value; }
123 if (key == "jumble" ) { jumble = value; }
124 if (key == "freq" ) { freq = value; }
125 if (key == "method" ) { method = value; }
126 if (key == "fileroot" ) { fileroot = value; }
127 if (key == "abund" ) { abund = value; }
128 if (key == "random" ) { randomtree = value; }
129 if (key == "calc") { calc = value; }
130 if (key == "step") { step = value; }
131 if (key == "form") { form = value; }
132 if (key == "sorted") { sorted = value; }
134 if (key == "line") {//stores lines to be used in a vector
139 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
140 else { allLines = 1; }
142 if (key == "label") {//stores lines to be used in a vector
147 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
148 else { allLines = 1; }
151 if (key == "groups") {//stores groups to be used in a vector
154 splitAtDash(value, Groups);
158 //set format for shared
159 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
160 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
162 //input defaults for calculators
163 if (commandName == "collect.single") {
164 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-qstat-logsd-bergerparker-bstick"; }
166 splitAtDash(calc, Estimators);
168 if (commandName == "rarefaction.single") {
169 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
171 splitAtDash(calc, Estimators);
173 if (commandName == "collect.shared") {
174 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
176 splitAtDash(calc, Estimators);
178 if (commandName == "summary.single") {
179 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-logsd-qstat-bergerparker-bstick"; }
181 splitAtDash(calc, Estimators);
183 if (commandName == "summary.shared") {
184 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
186 splitAtDash(calc, Estimators);
188 if (commandName == "rarefaction.shared") {
189 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
191 splitAtDash(calc, Estimators);
193 if (commandName == "venn") {
194 if ((calc == "default") || (calc == "")) {
195 if (format == "list") { calc = "sobs"; }
196 else { calc = "sharedsobs"; }
199 splitAtDash(calc, Estimators);
202 //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
203 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
204 if (listfile != "") { format = "list"; }
205 else if (sabundfile != "") { format = "sabund"; }
206 else if (rabundfile != "") { format = "rabund"; }
209 catch(exception& e) {
210 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
214 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
218 /*******************************************************/
220 /******************************************************/
221 // These functions give you the option parameters of the commands
222 string GlobalData::getPhylipFile() { return phylipfile; }
223 string GlobalData::getColumnFile() { return columnfile; }
224 string GlobalData::getListFile() { return listfile; }
225 string GlobalData::getRabundFile() { return rabundfile; }
226 string GlobalData::getSabundFile() { return sabundfile; }
227 string GlobalData::getNameFile() { return namefile; }
228 string GlobalData::getGroupFile() { return groupfile; }
229 string GlobalData::getOrderFile() { return orderfile; }
230 string GlobalData::getTreeFile() { return treefile; }
231 string GlobalData::getSharedFile() { return sharedfile; }
232 string GlobalData::getFastaFile() { return fastafile; }
233 string GlobalData::getCutOff() { return cutoff; }
234 string GlobalData::getFormat() { return format; }
235 string GlobalData::getPrecision() { return precision; }
236 string GlobalData::getMethod() { return method; }
237 string GlobalData::getFileRoot() { return fileroot; }
238 string GlobalData::getIters() { return iters; }
239 string GlobalData::getJumble() { return jumble; }
240 string GlobalData::getFreq() { return freq; }
241 string GlobalData::getAbund() { return abund; }
242 string GlobalData::getRandomTree() { return randomtree; }
243 string GlobalData::getGroups() { return groups; }
244 string GlobalData::getStep() { return step; }
245 string GlobalData::getForm() { return form; }
246 string GlobalData::getSorted() { return sorted; }
247 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
248 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
249 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
250 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
251 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
252 void GlobalData::setNameFile(string file) { namefile = file; }
253 void GlobalData::setFormat(string Format) { format = Format; }
254 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
255 void GlobalData::setGroups(string g) { groups = g; }
256 void GlobalData::setCalc(string Calc) { calc = Calc; }
258 /*******************************************************/
260 /******************************************************/
261 GlobalData::GlobalData() {
262 //option definitions should go here...
266 /*******************************************************/
268 /******************************************************/
269 void GlobalData::clear() {
270 //option definitions should go here...
289 jumble = "1"; //0 means don't jumble, 1 means jumble.
290 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
297 sorted = "1"; //0 means don't sort, 1 means sort.
300 //*******************************************************/
302 /******************************************************/
303 void GlobalData::reset() {
308 jumble = "1"; //0 means don't jumble, 1 means jumble.
309 sorted = "1"; //0 means don't sort, 1 means sort.
310 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
318 /*******************************************************/
320 /******************************************************/
321 GlobalData::~GlobalData() {
323 if(gListVector != NULL) { delete gListVector; }
324 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
325 if(gorder != NULL) { delete gorder; }
327 /*******************************************************/