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")) {
34 labels.clear(); lines.clear(); groups.clear();
39 if (commandName =="help") {
40 helpRequest = optionText;
43 if (commandName == "libshuff") {
49 //reads in parameters and values
50 if((optionText != "") && (commandName != "help")){
51 while((optionText.find_first_of(',') != -1)) { //while there are parameters
52 splitAtComma(value, optionText);
53 splitAtEquals(key, value);
55 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
56 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
57 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
58 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
59 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
60 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
61 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
62 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
63 if (key == "name" ) { namefile = value; }
64 if (key == "order" ) { orderfile = value; }
65 if (key == "group" ) { groupfile = value; }
66 if (key == "cutoff" ) { cutoff = value; }
67 if (key == "precision" ) { precision = value; }
68 if (key == "iters" ) { iters = value; }
69 if (key == "jumble" ) { jumble = value; }
70 if (key == "freq" ) { freq = value; }
71 if (key == "method" ) { method = value; }
72 if (key == "fileroot" ) { fileroot = value; }
73 if (key == "abund" ) { abund = value; }
74 if (key == "random" ) { randomtree = value; }
75 if (key == "calc") { calc = value; }
76 if (key == "step") { step = value; }
77 if (key == "form") { form = value; }
78 if (key == "sorted") { sorted = value; }
82 if (key == "line") {//stores lines to be used in a set
87 splitAtDash(value, lines);
90 if (key == "label") {//stores labels to be used in a set
95 splitAtDash(value, labels);
99 if (key == "groups") {//stores groups to be used in a vector
102 splitAtDash(value, Groups);
107 //saves the last parameter
109 splitAtEquals(key, value);
110 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
111 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
112 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
113 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
114 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
115 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
116 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
117 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
118 if (key == "name" ) { namefile = value; }
119 if (key == "order" ) { orderfile = value; }
120 if (key == "group" ) { groupfile = value; }
121 if (key == "cutoff" ) { cutoff = value; }
122 if (key == "precision" ) { precision = value; }
123 if (key == "iters" ) { iters = value; }
124 if (key == "jumble" ) { jumble = value; }
125 if (key == "freq" ) { freq = value; }
126 if (key == "method" ) { method = value; }
127 if (key == "fileroot" ) { fileroot = value; }
128 if (key == "abund" ) { abund = value; }
129 if (key == "random" ) { randomtree = value; }
130 if (key == "calc") { calc = value; }
131 if (key == "step") { step = value; }
132 if (key == "form") { form = value; }
133 if (key == "sorted") { sorted = value; }
135 if (key == "line") {//stores lines to be used in a vector
140 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
141 else { allLines = 1; }
143 if (key == "label") {//stores lines to be used in a vector
148 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
149 else { allLines = 1; }
152 if (key == "groups") {//stores groups to be used in a vector
155 splitAtDash(value, Groups);
159 //set format for shared
160 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
161 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
163 //input defaults for calculators
164 if (commandName == "collect.single") {
165 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-qstat-logsd-bergerparker-bstick"; }
167 splitAtDash(calc, Estimators);
169 if (commandName == "rarefaction.single") {
170 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
172 splitAtDash(calc, Estimators);
174 if (commandName == "collect.shared") {
175 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
177 splitAtDash(calc, Estimators);
179 if (commandName == "summary.single") {
180 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson-geom-logsd-qstat-bergerparker-bstick"; }
182 splitAtDash(calc, Estimators);
184 if (commandName == "summary.shared") {
185 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-sharedjabund-sharedsorensonabund-sharedjclass-sharedsorclass-sharedjest-sharedsorest-sharedthetayc-sharedthetan-sharedkstest-sharedbdiversity"; }
187 splitAtDash(calc, Estimators);
189 if (commandName == "rarefaction.shared") {
190 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
192 splitAtDash(calc, Estimators);
194 if (commandName == "venn") {
195 if ((calc == "default") || (calc == "")) {
196 if (format == "list") { calc = "sobs"; }
197 else { calc = "sharedsobs"; }
200 splitAtDash(calc, Estimators);
203 //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
204 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
205 if (listfile != "") { format = "list"; }
206 else if (sabundfile != "") { format = "sabund"; }
207 else if (rabundfile != "") { format = "rabund"; }
210 catch(exception& e) {
211 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
215 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
219 /*******************************************************/
221 /******************************************************/
222 // These functions give you the option parameters of the commands
223 string GlobalData::getPhylipFile() { return phylipfile; }
224 string GlobalData::getColumnFile() { return columnfile; }
225 string GlobalData::getListFile() { return listfile; }
226 string GlobalData::getRabundFile() { return rabundfile; }
227 string GlobalData::getSabundFile() { return sabundfile; }
228 string GlobalData::getNameFile() { return namefile; }
229 string GlobalData::getGroupFile() { return groupfile; }
230 string GlobalData::getOrderFile() { return orderfile; }
231 string GlobalData::getTreeFile() { return treefile; }
232 string GlobalData::getSharedFile() { return sharedfile; }
233 string GlobalData::getFastaFile() { return fastafile; }
234 string GlobalData::getCutOff() { return cutoff; }
235 string GlobalData::getFormat() { return format; }
236 string GlobalData::getPrecision() { return precision; }
237 string GlobalData::getMethod() { return method; }
238 string GlobalData::getFileRoot() { return fileroot; }
239 string GlobalData::getIters() { return iters; }
240 string GlobalData::getJumble() { return jumble; }
241 string GlobalData::getFreq() { return freq; }
242 string GlobalData::getAbund() { return abund; }
243 string GlobalData::getRandomTree() { return randomtree; }
244 string GlobalData::getGroups() { return groups; }
245 string GlobalData::getStep() { return step; }
246 string GlobalData::getForm() { return form; }
247 string GlobalData::getSorted() { return sorted; }
248 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
249 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
250 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
251 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
252 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
253 void GlobalData::setNameFile(string file) { namefile = file; }
254 void GlobalData::setFormat(string Format) { format = Format; }
255 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
256 void GlobalData::setGroups(string g) { groups = g; }
257 void GlobalData::setCalc(string Calc) { calc = Calc; }
259 /*******************************************************/
261 /******************************************************/
262 GlobalData::GlobalData() {
263 //option definitions should go here...
267 /*******************************************************/
269 /******************************************************/
270 void GlobalData::clear() {
271 //option definitions should go here...
290 jumble = "1"; //0 means don't jumble, 1 means jumble.
291 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
298 sorted = "1"; //0 means don't sort, 1 means sort.
301 //*******************************************************/
303 /******************************************************/
304 void GlobalData::reset() {
309 jumble = "1"; //0 means don't jumble, 1 means jumble.
310 sorted = "1"; //0 means don't sort, 1 means sort.
311 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
319 /*******************************************************/
321 /******************************************************/
322 GlobalData::~GlobalData() {
324 if(gListVector != NULL) { delete gListVector; }
325 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
326 if(gorder != NULL) { delete gorder; }
328 /*******************************************************/
330 /*******************************************************/
331 void GlobalData::parseTreeFile() {
332 //only takes names from the first tree and assumes that all trees use the same names.
334 string filename = treefile;
336 openInputFile(filename, filehandle);
340 //if you are not a nexus file
341 if ((c = filehandle.peek()) != '#') {
342 while((c = filehandle.peek()) != ';') {
343 while ((c = filehandle.peek()) != ';') {
351 if((c == '(') && (comment != 1)){ break; }
355 readTreeString(filehandle);
357 //if you are a nexus file
358 }else if ((c = filehandle.peek()) == '#') {
362 while(holder != "translate" && holder != "Translate"){
363 if(holder == "[" || holder == "[!"){
369 filehandle >> holder;
371 //if there is no translate then you must read tree string otherwise use translate to get names
372 if(holder == "tree" && comment != 1){
373 //pass over the "tree rep.6878900 = "
374 while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF) ) {;}
376 if (c == EOF ) { break; }
377 filehandle.putback(c); //put back first ( of tree.
378 readTreeString(filehandle);
383 //use nexus translation rather than parsing tree to save time
384 if ((holder == "translate") || (holder == "Translate")) {
385 cout << "there is a translate " << endl;
386 string number, name, h;
387 h = ""; // so it enters the loop the first time
388 while((h != ";") && (number != ";")) {
389 filehandle >> number;
392 //c = , until done with translation then c = ;
393 h = name.substr(name.length()-1, name.length());
394 name.erase(name.end()-1); //erase the comma
395 Treenames.push_back(number);
397 if (number == ";") { Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name
402 catch(exception& e) {
403 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
407 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
411 /*******************************************************/
413 /*******************************************************/
414 void GlobalData::readTreeString(ifstream& filehandle) {
419 while((c = filehandle.peek()) != ';') {
421 if ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
423 c = filehandle.get();
426 while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {
428 c = filehandle.get();
430 //cout << " in name while " << k << endl;
433 //cout << "name = " << name << endl;
434 Treenames.push_back(name);
435 filehandle.putback(c);
437 //cout << " after putback" << k << endl;
440 if (c == ':') { //read until you reach the end of the branch length
441 while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
442 c = filehandle.get();
444 //cout << " in branch while " << k << endl;
446 filehandle.putback(c);
448 c = filehandle.get();
449 if (c == ';') { break; }
455 catch(exception& e) {
456 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
460 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
465 /*******************************************************/
467 /*******************************************************/