1 #include "globaldata.hpp"
3 #include "sparsematrix.hpp"
5 /*******************************************************/
7 /******************************************************/
8 GlobalData* GlobalData::getInstance() {
9 if( _uniqueInstance == 0 ) {
10 _uniqueInstance = new GlobalData();
12 return _uniqueInstance;
14 /*******************************************************/
16 /******************************************************/
17 //This function parses through the option string of the command to remove its parameters
18 void GlobalData::parseGlobalData(string commandString, string optionText){
20 commandName = commandString; //save command name to be used by other classes
22 //set all non filename paramters to default
25 //clears out data from previous read
26 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) {
31 labels.clear(); lines.clear(); groups.clear();
36 if (commandName =="help") {
37 helpRequest = optionText;
40 if (commandName == "libshuff") {
46 //reads in parameters and values
47 if((optionText != "") && (commandName != "help")){
48 while((optionText.find_first_of(',') != -1)) { //while there are parameters
49 splitAtComma(value, optionText);
50 splitAtEquals(key, value);
52 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
53 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
54 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
55 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
56 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
57 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
58 if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
59 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
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; }
78 if (key == "vertical") { vertical = value; }
79 if (key == "trump") { trump = value; }
80 if (key == "filter") { filter = value; }
81 if (key == "soft") { soft = value; }
82 if (key == "scale") { scale = value; }
88 if (key == "line") {//stores lines to be used in a set
93 splitAtDash(value, lines);
96 if (key == "label") {//stores labels to be used in a set
101 splitAtDash(value, labels);
105 if (key == "groups") {//stores groups to be used in a vector
108 splitAtDash(value, Groups);
113 //saves the last parameter
115 splitAtEquals(key, value);
116 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
117 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
118 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
119 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
120 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
121 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
122 if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
123 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
124 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
125 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
126 if (key == "name" ) { namefile = value; }
127 if (key == "order" ) { orderfile = value; }
128 if (key == "group" ) { groupfile = value; }
129 if (key == "cutoff" ) { cutoff = value; }
130 if (key == "precision" ) { precision = value; }
131 if (key == "iters" ) { iters = value; }
132 if (key == "jumble" ) { jumble = value; }
133 if (key == "freq" ) { freq = value; }
134 if (key == "method" ) { method = value; }
135 if (key == "fileroot" ) { fileroot = value; }
136 if (key == "abund" ) { abund = value; }
137 if (key == "random" ) { randomtree = value; }
138 if (key == "calc") { calc = value; }
139 if (key == "step") { step = value; }
140 if (key == "form") { form = value; }
141 if (key == "sorted") { sorted = value; }
142 if (key == "vertical") { vertical = value; }
143 if (key == "trump") { trump = value; }
144 if (key == "filter") { filter = value; }
145 if (key == "soft") { soft = value; }
146 if (key == "scale") { scale = value; }
152 if (key == "line") {//stores lines to be used in a vector
157 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
158 else { allLines = 1; }
161 if (key == "label") {//stores lines to be used in a vector
166 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
167 else { allLines = 1; }
170 if (key == "groups") {//stores groups to be used in a vector
173 splitAtDash(value, Groups);
177 //set format for shared
178 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
179 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
181 //input defaults for calculators
182 if (commandName == "collect.single") {
184 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
186 splitAtDash(calc, Estimators);
188 if (commandName == "rarefaction.single") {
189 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
191 splitAtDash(calc, Estimators);
193 if (commandName == "collect.shared") {
195 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
197 splitAtDash(calc, Estimators);
199 if (commandName == "summary.single") {
200 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
202 splitAtDash(calc, Estimators);
204 if (commandName == "summary.shared") {
205 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
207 splitAtDash(calc, Estimators);
209 if (commandName == "rarefaction.shared") {
210 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
212 splitAtDash(calc, Estimators);
214 if (commandName == "venn") {
215 if ((calc == "default") || (calc == "")) {
216 if (format == "list") { calc = "sobs"; }
217 else { calc = "sharedsobs"; }
220 splitAtDash(calc, Estimators);
222 if ((commandName == "tree.shared") || (commandName == "bootstrap.shared")) {
225 splitAtDash(calc, Estimators);
226 }else { cout << "You have not specified any calculators." << endl; }
230 //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
231 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
232 if (listfile != "") { format = "list"; }
233 else if (sabundfile != "") { format = "sabund"; }
234 else if (rabundfile != "") { format = "rabund"; }
237 catch(exception& e) {
238 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
242 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
246 /*******************************************************/
248 /******************************************************/
249 // These functions give you the option parameters of the commands
250 string GlobalData::getPhylipFile() { return phylipfile; }
251 string GlobalData::getColumnFile() { return columnfile; }
252 string GlobalData::getListFile() { return listfile; }
253 string GlobalData::getRabundFile() { return rabundfile; }
254 string GlobalData::getSabundFile() { return sabundfile; }
255 string GlobalData::getNameFile() { return namefile; }
256 string GlobalData::getGroupFile() { return groupfile; }
257 string GlobalData::getOrderFile() { return orderfile; }
258 string GlobalData::getTreeFile() { return treefile; }
259 string GlobalData::getSharedFile() { return sharedfile; }
260 string GlobalData::getFastaFile() { return fastafile; }
261 string GlobalData::getNexusFile() { return nexusfile; }
262 string GlobalData::getClustalFile() { return clustalfile; }
263 string GlobalData::getCutOff() { return cutoff; }
264 string GlobalData::getFormat() { return format; }
265 string GlobalData::getPrecision() { return precision; }
266 string GlobalData::getMethod() { return method; }
267 string GlobalData::getFileRoot() { return fileroot; }
268 string GlobalData::getIters() { return iters; }
269 string GlobalData::getJumble() { return jumble; }
270 string GlobalData::getFreq() { return freq; }
271 string GlobalData::getAbund() { return abund; }
272 string GlobalData::getRandomTree() { return randomtree; }
273 string GlobalData::getGroups() { return groups; }
274 string GlobalData::getStep() { return step; }
275 string GlobalData::getForm() { return form; }
276 string GlobalData::getSorted() { return sorted; }
277 string GlobalData::getTrump() { return trump; }
278 string GlobalData::getSoft() { return soft; }
279 string GlobalData::getFilter() { return filter; }
280 string GlobalData::getScale() { return scale; }
282 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
283 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
284 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
285 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
286 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
287 void GlobalData::setNameFile(string file) { namefile = file; }
288 void GlobalData::setFormat(string Format) { format = Format; }
289 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
290 void GlobalData::setGroups(string g) { groups = g; }
291 void GlobalData::setCalc(string Calc) { calc = Calc; }
293 /*******************************************************/
295 /******************************************************/
296 GlobalData::GlobalData() {
297 //option definitions should go here...
301 gSparseMatrix == NULL;
303 /*******************************************************/
305 /******************************************************/
306 void GlobalData::clear() {
307 //option definitions should go here...
328 jumble = "1"; //0 means don't jumble, 1 means jumble.
329 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
336 sorted = "T"; //F means don't sort, T means sort.
345 //*******************************************************/
347 /******************************************************/
348 void GlobalData::reset() {
353 jumble = "1"; //0 means don't jumble, 1 means jumble.
354 sorted = "T"; //F means don't sort, T means sort.
355 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
363 /*******************************************************/
365 /******************************************************/
366 GlobalData::~GlobalData() {
368 if(gListVector != NULL) { delete gListVector; }
369 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
370 if(gorder != NULL) { delete gorder; }
372 /*******************************************************/
374 /*******************************************************/
375 void GlobalData::parseTreeFile() {
376 //only takes names from the first tree and assumes that all trees use the same names.
378 string filename = treefile;
380 openInputFile(filename, filehandle);
384 //if you are not a nexus file
385 if ((c = filehandle.peek()) != '#') {
386 while((c = filehandle.peek()) != ';') {
387 while ((c = filehandle.peek()) != ';') {
395 if((c == '(') && (comment != 1)){ break; }
399 readTreeString(filehandle);
401 //if you are a nexus file
402 }else if ((c = filehandle.peek()) == '#') {
406 while(holder != "translate" && holder != "Translate"){
407 if(holder == "[" || holder == "[!"){
413 filehandle >> holder;
415 //if there is no translate then you must read tree string otherwise use translate to get names
416 if(holder == "tree" && comment != 1){
417 //pass over the "tree rep.6878900 = "
418 while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF) ) {;}
420 if (c == EOF ) { break; }
421 filehandle.putback(c); //put back first ( of tree.
422 readTreeString(filehandle);
427 //use nexus translation rather than parsing tree to save time
428 if ((holder == "translate") || (holder == "Translate")) {
430 string number, name, h;
431 h = ""; // so it enters the loop the first time
432 while((h != ";") && (number != ";")) {
433 filehandle >> number;
436 //c = , until done with translation then c = ;
437 h = name.substr(name.length()-1, name.length());
438 name.erase(name.end()-1); //erase the comma
439 Treenames.push_back(number);
441 if (number == ";") { Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name
446 catch(exception& e) {
447 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
451 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
455 /*******************************************************/
457 /*******************************************************/
458 void GlobalData::readTreeString(ifstream& filehandle) {
463 while((c = filehandle.peek()) != ';') {
465 if ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
467 c = filehandle.get();
470 while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {
472 c = filehandle.get();
474 //cout << " in name while " << k << endl;
477 //cout << "name = " << name << endl;
478 Treenames.push_back(name);
479 filehandle.putback(c);
481 //cout << " after putback" << k << endl;
484 if (c == ':') { //read until you reach the end of the branch length
485 while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
486 c = filehandle.get();
488 //cout << " in branch while " << k << endl;
490 filehandle.putback(c);
492 c = filehandle.get();
493 if (c == ';') { break; }
499 catch(exception& e) {
500 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
504 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
509 /*******************************************************/
511 /*******************************************************/