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") {
45 //set default value for cutoff
46 if (commandName == "dist.seqs") { cutoff = "1.0"; }
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 == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
62 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
63 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
64 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
65 if (key == "name" ) { namefile = value; }
66 if (key == "order" ) { orderfile = value; }
67 if (key == "group" ) { groupfile = value; }
68 if (key == "cutoff" ) { cutoff = value; }
69 if (key == "precision" ) { precision = value; }
70 if (key == "iters" ) { iters = value; }
71 if (key == "jumble" ) { jumble = value; }
72 if (key == "freq" ) { freq = value; }
73 if (key == "method" ) { method = value; }
74 if (key == "fileroot" ) { fileroot = value; }
75 if (key == "abund" ) { abund = value; }
76 if (key == "random" ) { randomtree = value; }
77 if (key == "calc") { calc = value; }
78 if (key == "step") { step = value; }
79 if (key == "form") { form = value; }
80 if (key == "sorted") { sorted = value; }
81 if (key == "vertical") { vertical = value; }
82 if (key == "trump") { trump = value; }
83 if (key == "filter") { filter = value; }
84 if (key == "soft") { soft = value; }
85 if (key == "scale") { scale = value; }
86 if (key == "ends" ) { ends = value; }
87 if (key == "processors" ) { processors = value; }
93 if (key == "line") {//stores lines to be used in a set
98 splitAtDash(value, lines);
101 if (key == "label") {//stores labels to be used in a set
106 splitAtDash(value, labels);
110 if (key == "groups") {//stores groups to be used in a vector
113 splitAtDash(value, Groups);
118 //saves the last parameter
120 splitAtEquals(key, value);
121 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
122 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
123 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
124 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
125 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
126 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
127 if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
128 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
129 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
130 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
131 if (key == "name" ) { namefile = value; }
132 if (key == "order" ) { orderfile = value; }
133 if (key == "group" ) { groupfile = value; }
134 if (key == "cutoff" ) { cutoff = value; }
135 if (key == "precision" ) { precision = value; }
136 if (key == "iters" ) { iters = value; }
137 if (key == "jumble" ) { jumble = value; }
138 if (key == "freq" ) { freq = value; }
139 if (key == "method" ) { method = value; }
140 if (key == "fileroot" ) { fileroot = value; }
141 if (key == "abund" ) { abund = value; }
142 if (key == "random" ) { randomtree = value; }
143 if (key == "calc") { calc = value; }
144 if (key == "step") { step = value; }
145 if (key == "form") { form = value; }
146 if (key == "sorted") { sorted = value; }
147 if (key == "vertical") { vertical = value; }
148 if (key == "trump") { trump = value; }
149 if (key == "filter") { filter = value; }
150 if (key == "soft") { soft = value; }
151 if (key == "scale") { scale = value; }
152 if (key == "ends" ) { ends = value; }
153 if (key == "processors" ) { processors = value; }
156 if (key == "line") {//stores lines to be used in a vector
161 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
162 else { allLines = 1; }
165 if (key == "label") {//stores lines to be used in a vector
170 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
171 else { allLines = 1; }
174 if (key == "groups") {//stores groups to be used in a vector
177 splitAtDash(value, Groups);
181 //set format for shared
182 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
183 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
185 //input defaults for calculators
186 if (commandName == "collect.single") {
188 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
190 splitAtDash(calc, Estimators);
192 if (commandName == "rarefaction.single") {
193 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
195 splitAtDash(calc, Estimators);
197 if (commandName == "collect.shared") {
199 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
201 splitAtDash(calc, Estimators);
203 if (commandName == "summary.single") {
204 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
206 splitAtDash(calc, Estimators);
208 if (commandName == "summary.shared") {
209 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
211 splitAtDash(calc, Estimators);
213 if (commandName == "rarefaction.shared") {
214 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
216 splitAtDash(calc, Estimators);
218 if (commandName == "dist.seqs") {
219 if ((calc == "default") || (calc == "")) { calc = "onegap"; }
221 splitAtDash(calc, Estimators);
223 if (commandName == "venn") {
224 if ((calc == "default") || (calc == "")) {
225 if (format == "list") { calc = "sobs"; }
226 else { calc = "sharedsobs"; }
229 splitAtDash(calc, Estimators);
231 if ((commandName == "tree.shared") || (commandName == "bootstrap.shared")) {
234 splitAtDash(calc, Estimators);
235 }else { cout << "You have not specified any calculators." << endl; }
239 //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
240 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
241 if (listfile != "") { format = "list"; }
242 else if (sabundfile != "") { format = "sabund"; }
243 else if (rabundfile != "") { format = "rabund"; }
246 catch(exception& e) {
247 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
251 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
255 /*******************************************************/
257 /******************************************************/
258 // These functions give you the option parameters of the commands
259 string GlobalData::getPhylipFile() { return phylipfile; }
260 string GlobalData::getColumnFile() { return columnfile; }
261 string GlobalData::getListFile() { return listfile; }
262 string GlobalData::getRabundFile() { return rabundfile; }
263 string GlobalData::getSabundFile() { return sabundfile; }
264 string GlobalData::getNameFile() { return namefile; }
265 string GlobalData::getGroupFile() { return groupfile; }
266 string GlobalData::getOrderFile() { return orderfile; }
267 string GlobalData::getTreeFile() { return treefile; }
268 string GlobalData::getSharedFile() { return sharedfile; }
269 string GlobalData::getFastaFile() { return fastafile; }
270 string GlobalData::getNexusFile() { return nexusfile; }
271 string GlobalData::getClustalFile() { return clustalfile; }
272 string GlobalData::getCutOff() { return cutoff; }
273 string GlobalData::getFormat() { return format; }
274 string GlobalData::getPrecision() { return precision; }
275 string GlobalData::getMethod() { return method; }
276 string GlobalData::getFileRoot() { return fileroot; }
277 string GlobalData::getIters() { return iters; }
278 string GlobalData::getJumble() { return jumble; }
279 string GlobalData::getFreq() { return freq; }
280 string GlobalData::getAbund() { return abund; }
281 string GlobalData::getRandomTree() { return randomtree; }
282 string GlobalData::getGroups() { return groups; }
283 string GlobalData::getStep() { return step; }
284 string GlobalData::getForm() { return form; }
285 string GlobalData::getSorted() { return sorted; }
286 string GlobalData::getTrump() { return trump; }
287 string GlobalData::getSoft() { return soft; }
288 string GlobalData::getFilter() { return filter; }
289 string GlobalData::getScale() { return scale; }
290 string GlobalData::getEnds() { return ends; }
291 string GlobalData::getProcessors() { return processors; }
293 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file;}
294 void GlobalData::setGroupFile(string file) { groupfile = file; }
295 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file;}
296 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file;}
297 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file;}
298 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file;}
299 void GlobalData::setSharedFile(string file) { sharedfile = file; inputFileName = file; fileroot = file;}
300 void GlobalData::setNameFile(string file) { namefile = file; }
301 void GlobalData::setFormat(string Format) { format = Format; }
302 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
303 void GlobalData::setGroups(string g) { groups = g; }
304 void GlobalData::setCalc(string Calc) { calc = Calc; }
305 void GlobalData::setEnds(string e) { ends = e; }
306 void GlobalData::setProcessors(string p) { processors = p; }
309 /*******************************************************/
311 /******************************************************/
312 GlobalData::GlobalData() {
313 //option definitions should go here...
317 gSparseMatrix == NULL;
319 /*******************************************************/
321 /******************************************************/
322 void GlobalData::clear() {
323 //option definitions should go here...
344 jumble = "1"; //0 means don't jumble, 1 means jumble.
345 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
352 sorted = "T"; //F means don't sort, T means sort.
363 //*******************************************************/
365 /******************************************************/
366 void GlobalData::reset() {
371 jumble = "1"; //0 means don't jumble, 1 means jumble.
372 sorted = "T"; //F means don't sort, T means sort.
373 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
383 /*******************************************************/
385 /******************************************************/
386 GlobalData::~GlobalData() {
388 if(gListVector != NULL) { delete gListVector; }
389 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
390 if(gorder != NULL) { delete gorder; }
392 /*******************************************************/
394 /*******************************************************/
395 void GlobalData::parseTreeFile() {
396 //only takes names from the first tree and assumes that all trees use the same names.
398 string filename = treefile;
400 openInputFile(filename, filehandle);
404 //if you are not a nexus file
405 if ((c = filehandle.peek()) != '#') {
406 while((c = filehandle.peek()) != ';') {
407 while ((c = filehandle.peek()) != ';') {
415 if((c == '(') && (comment != 1)){ break; }
419 readTreeString(filehandle);
421 //if you are a nexus file
422 }else if ((c = filehandle.peek()) == '#') {
426 while(holder != "translate" && holder != "Translate"){
427 if(holder == "[" || holder == "[!"){
433 filehandle >> holder;
435 //if there is no translate then you must read tree string otherwise use translate to get names
436 if(holder == "tree" && comment != 1){
437 //pass over the "tree rep.6878900 = "
438 while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF) ) {;}
440 if (c == EOF ) { break; }
441 filehandle.putback(c); //put back first ( of tree.
442 readTreeString(filehandle);
447 //use nexus translation rather than parsing tree to save time
448 if ((holder == "translate") || (holder == "Translate")) {
450 string number, name, h;
451 h = ""; // so it enters the loop the first time
452 while((h != ";") && (number != ";")) {
453 filehandle >> number;
456 //c = , until done with translation then c = ;
457 h = name.substr(name.length()-1, name.length());
458 name.erase(name.end()-1); //erase the comma
459 Treenames.push_back(number);
461 if (number == ";") { Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name
466 catch(exception& e) {
467 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
471 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
475 /*******************************************************/
477 /*******************************************************/
478 void GlobalData::readTreeString(ifstream& filehandle) {
483 while((c = filehandle.peek()) != ';') {
485 if ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
487 c = filehandle.get();
490 while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {
492 c = filehandle.get();
494 //cout << " in name while " << k << endl;
497 //cout << "name = " << name << endl;
498 Treenames.push_back(name);
499 filehandle.putback(c);
501 //cout << " after putback" << k << endl;
504 if (c == ':') { //read until you reach the end of the branch length
505 while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
506 c = filehandle.get();
508 //cout << " in branch while " << k << endl;
510 filehandle.putback(c);
512 c = filehandle.get();
513 if (c == ';') { break; }
519 catch(exception& e) {
520 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
524 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
529 /*******************************************************/
531 /*******************************************************/