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 values
73 //clears out data from previous read
74 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree") || (commandName == "read.shared")) {
81 if (commandName =="help") {
82 helpRequest = optionText;
86 //reads in parameters and values
87 if((optionText != "") && (commandName != "help")){
88 while((optionText.find_first_of(',') != -1)) { //while there are parameters
89 splitAtComma(value, optionText);
90 splitAtEquals(key, value);
92 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
93 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
94 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
95 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
96 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
97 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
98 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
99 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
100 if (key == "name" ) { namefile = value; }
101 if (key == "order" ) { orderfile = value; }
102 if (key == "group" ) { groupfile = value; }
103 if (key == "cutoff" ) { cutoff = value; }
104 if (key == "precision" ) { precision = value; }
105 if (key == "iters" ) { iters = value; }
106 if (key == "jumble" ) { jumble = value; }
107 if (key == "freq" ) { freq = value; }
108 if (key == "method" ) { method = value; }
109 if (key == "fileroot" ) { fileroot = value; }
110 if (key == "randomtree" ) { randomtree = value; }
111 if (key == "groups" ) { groups = value; }
112 if (key == "calc") { calc = value; }
114 if (key == "line") {//stores lines to be used in a set
118 splitAtDash(value, lines);
121 if (key == "label") {//stores labels to be used in a set
125 splitAtDash(value, labels);
128 if (key == "groups") {//stores groups to be used in a vector
131 splitAtDash(value, Groups);
135 //saves the last parameter
137 splitAtEquals(key, value);
138 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
139 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
140 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
141 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
142 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
143 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
144 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
145 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
146 if (key == "name" ) { namefile = value; }
147 if (key == "order" ) { orderfile = value; }
148 if (key == "group" ) { groupfile = value; }
149 if (key == "cutoff" ) { cutoff = value; }
150 if (key == "precision" ) { precision = value; }
151 if (key == "iters" ) { iters = value; }
152 if (key == "jumble" ) { jumble = value; }
153 if (key == "freq" ) { freq = value; }
154 if (key == "method" ) { method = value; }
155 if (key == "fileroot" ) { fileroot = value; }
156 if (key == "randomtree" ) { randomtree = value; }
157 if (key == "groups" ) { groups = value; }
158 if (key == "calc") { calc = value; }
161 if (key == "line") {//stores lines to be used in a vector
165 splitAtDash(value, lines);
168 if (key == "label") {//stores lines to be used in a vector
172 splitAtDash(value, labels);
175 if (key == "groups") {//stores groups to be used in a vector
178 splitAtDash(value, Groups);
182 //set format for shared
183 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
185 //input defaults for calculators
186 if (commandName == "collect.single") {
187 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
189 splitAtDash(calc, Estimators);
191 if (commandName == "rarefaction.single") {
192 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
194 splitAtDash(calc, Estimators);
196 if (commandName == "collect.shared") {
197 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
199 splitAtDash(calc, Estimators);
201 if (commandName == "summary.single") {
202 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson"; }
204 splitAtDash(calc, Estimators);
206 if (commandName == "summary.shared") {
207 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan"; }
209 splitAtDash(calc, Estimators);
211 if (commandName == "rarefaction.shared") {
212 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
214 splitAtDash(calc, Estimators);
217 //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
218 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
219 if (listfile != "") { format = "list"; }
220 else if (sabundfile != "") { format = "sabund"; }
221 else if (rabundfile != "") { format = "rabund"; }
224 catch(exception& e) {
225 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
229 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
233 /*******************************************************/
235 /******************************************************/
236 // These functions give you the option parameters of the commands
237 string GlobalData::getPhylipFile() { return phylipfile; }
238 string GlobalData::getColumnFile() { return columnfile; }
239 string GlobalData::getListFile() { return listfile; }
240 string GlobalData::getRabundFile() { return rabundfile; }
241 string GlobalData::getSabundFile() { return sabundfile; }
242 string GlobalData::getNameFile() { return namefile; }
243 string GlobalData::getGroupFile() { return groupfile; }
244 string GlobalData::getOrderFile() { return orderfile; }
245 string GlobalData::getTreeFile() { return treefile; }
246 string GlobalData::getSharedFile() { return sharedfile; }
247 string GlobalData::getFastaFile() { return fastafile; }
248 string GlobalData::getCutOff() { return cutoff; }
249 string GlobalData::getFormat() { return format; }
250 string GlobalData::getPrecision() { return precision; }
251 string GlobalData::getMethod() { return method; }
252 string GlobalData::getFileRoot() { return fileroot; }
253 string GlobalData::getIters() { return iters; }
254 string GlobalData::getJumble() { return jumble; }
255 string GlobalData::getFreq() { return freq; }
256 string GlobalData::getRandomTree() { return randomtree; }
257 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
258 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
259 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
260 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
261 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
262 void GlobalData::setNameFile(string file) { namefile = file; }
263 void GlobalData::setFormat(string Format) { format = Format; }
264 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
265 void GlobalData::setCalc(string Calc) { calc = Calc; }
267 /*******************************************************/
269 /******************************************************/
270 GlobalData::GlobalData() {
271 //option definitions should go here...
275 /*******************************************************/
277 /******************************************************/
278 void GlobalData::clear() {
279 //option definitions should go here...
298 jumble = "1"; //0 means don't jumble, 1 means jumble.
299 randomtree = "0"; //0 means user will enter some user trees, 1 means they just want the random tree distribution.
305 /*******************************************************/
307 /******************************************************/
308 void GlobalData::reset() {
315 jumble = "1"; //0 means don't jumble, 1 means jumble.
316 randomtree = "0"; //0 means user will enter some user trees, 1 means they just want the random tree distribution.
321 /*******************************************************/
323 /******************************************************/
324 GlobalData::~GlobalData() {
326 if(gListVector != NULL) { delete gListVector; }
327 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
328 if(gorder != NULL) { delete gorder; }
330 /*******************************************************/
332 /******************************************************/