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")) {
33 labels.clear(); lines.clear(); Groups.clear();
38 if (commandName =="help") {
39 helpRequest = optionText;
42 if (commandName == "libshuff") {
47 //set default value for cutoff
48 if (commandName == "dist.seqs") { cutoff = "1.0"; }
51 //reads in parameters and values
52 if((optionText != "") && (commandName != "help")){
53 while((optionText.find_first_of(',') != -1)) { //while there are parameters
54 splitAtComma(value, optionText);
55 splitAtEquals(key, value);
57 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
58 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
59 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
60 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
61 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
62 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
63 if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
64 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
65 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
66 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
67 if (key == "name" ) { namefile = value; }
68 if (key == "order" ) { orderfile = value; }
69 if (key == "group" ) { groupfile = value; }
70 if (key == "cutoff" ) { cutoff = value; }
71 if (key == "precision" ) { precision = value; }
72 if (key == "iters" ) { iters = value; }
73 if (key == "jumble" ) { jumble = value; }
74 if (key == "freq" ) { freq = value; }
75 if (key == "method" ) { method = value; }
76 if (key == "fileroot" ) { fileroot = value; }
77 if (key == "abund" ) { abund = value; }
78 if (key == "random" ) { randomtree = value; }
79 if (key == "calc") { calc = value; }
80 if (key == "step") { step = value; }
81 if (key == "form") { form = value; }
82 if (key == "sorted") { sorted = value; }
83 if (key == "vertical") { vertical = value; }
84 if (key == "trump") { trump = value; }
85 if (key == "hard") { hard = value; }
86 if (key == "soft") { soft = value; }
87 if (key == "scale") { scale = value; }
88 if (key == "countends" ) { countends = value; }
89 if (key == "processors" ) { processors = value; }
90 if (key == "size" ) { size = value; }
91 if (key == "candidate") { candidatefile = value; }
92 if (key == "search") { search = value; }
93 if (key == "ksize") { ksize = value; }
94 if (key == "align") { align = value; }
95 if (key == "match") { match = value; }
96 if (key == "mismatch") { mismatch = value; }
97 if (key == "gapopen") { gapopen = value; }
98 if (key == "gapextend" ) { gapextend = value; }
100 if (key == "line") {//stores lines to be used in a vector
105 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
106 else { allLines = 1; }
109 if (key == "label") {//stores lines to be used in a vector
114 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
115 else { allLines = 1; }
118 if (key == "groups") {//stores groups to be used in a vector
121 splitAtDash(value, Groups);
126 //saves the last parameter
128 splitAtEquals(key, value);
129 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
130 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
131 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
132 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
133 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
134 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
135 if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
136 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
137 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
138 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
139 if (key == "name" ) { namefile = value; }
140 if (key == "order" ) { orderfile = value; }
141 if (key == "group" ) { groupfile = value; }
142 if (key == "cutoff" ) { cutoff = value; }
143 if (key == "precision" ) { precision = value; }
144 if (key == "iters" ) { iters = value; }
145 if (key == "jumble" ) { jumble = value; }
146 if (key == "freq" ) { freq = value; }
147 if (key == "method" ) { method = value; }
148 if (key == "fileroot" ) { fileroot = value; }
149 if (key == "abund" ) { abund = value; }
150 if (key == "random" ) { randomtree = value; }
151 if (key == "calc") { calc = value; }
152 if (key == "step") { step = value; }
153 if (key == "form") { form = value; }
154 if (key == "sorted") { sorted = value; }
155 if (key == "vertical") { vertical = value; }
156 if (key == "trump") { trump = value; }
157 if (key == "hard") { hard = value; }
158 if (key == "soft") { soft = value; }
159 if (key == "scale") { scale = value; }
160 if (key == "countends" ) { countends = value; }
161 if (key == "processors" ) { processors = value; }
162 if (key == "size" ) { size = value; }
163 if (key == "candidate") { candidatefile = value; }
164 if (key == "search") { search = value; }
165 if (key == "ksize") { ksize = value; }
166 if (key == "align") { align = value; }
167 if (key == "match") { match = value; }
168 if (key == "mismatch") { mismatch = value; }
169 if (key == "gapopen") { gapopen = value; }
170 if (key == "gapextend" ) { gapextend = value; }
172 if (key == "line") {//stores lines to be used in a vector
177 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
178 else { allLines = 1; }
181 if (key == "label") {//stores lines to be used in a vector
186 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
187 else { allLines = 1; }
190 if (key == "groups") {//stores groups to be used in a vector
193 splitAtDash(value, Groups);
197 //set format for shared
198 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
199 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
201 //input defaults for calculators
202 if (commandName == "collect.single") {
204 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
206 splitAtDash(calc, Estimators);
208 if (commandName == "rarefaction.single") {
209 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
211 splitAtDash(calc, Estimators);
213 if (commandName == "collect.shared") {
215 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
217 splitAtDash(calc, Estimators);
219 if (commandName == "summary.single") {
220 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
222 splitAtDash(calc, Estimators);
224 if (commandName == "summary.shared") {
225 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
227 splitAtDash(calc, Estimators);
229 if (commandName == "rarefaction.shared") {
230 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
232 splitAtDash(calc, Estimators);
234 if (commandName == "dist.seqs") {
235 if ((calc == "default") || (calc == "")) { calc = "onegap"; }
236 if (countends == "") { countends = "T"; }
238 splitAtDash(calc, Estimators);
240 if (commandName == "venn") {
241 if ((calc == "default") || (calc == "")) {
242 if (format == "list") { calc = "sobs"; }
243 else { calc = "sharedsobs"; }
246 splitAtDash(calc, Estimators);
248 if ((commandName == "tree.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")) {
249 if ((calc == "default") || (calc == "")) {
250 calc = "jclass-thetayc";
253 splitAtDash(calc, Estimators);
256 if(commandName == "filter.seqs"){
257 if(trump == "" && vertical == "" && hard == "" && soft == ""){
263 //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
264 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
265 if (listfile != "") { format = "list"; }
266 else if (sabundfile != "") { format = "sabund"; }
267 else if (rabundfile != "") { format = "rabund"; }
270 catch(exception& e) {
271 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
275 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
279 /*******************************************************/
281 /******************************************************/
282 // These functions give you the option parameters of the commands
283 string GlobalData::getPhylipFile() { return phylipfile; }
284 string GlobalData::getColumnFile() { return columnfile; }
285 string GlobalData::getListFile() { return listfile; }
286 string GlobalData::getRabundFile() { return rabundfile; }
287 string GlobalData::getSabundFile() { return sabundfile; }
288 string GlobalData::getNameFile() { return namefile; }
289 string GlobalData::getGroupFile() { return groupfile; }
290 string GlobalData::getOrderFile() { return orderfile; }
291 string GlobalData::getTreeFile() { return treefile; }
292 string GlobalData::getSharedFile() { return sharedfile; }
293 string GlobalData::getFastaFile() { return fastafile; }
294 string GlobalData::getNexusFile() { return nexusfile; }
295 string GlobalData::getClustalFile() { return clustalfile; }
296 string GlobalData::getCutOff() { return cutoff; }
297 string GlobalData::getFormat() { return format; }
298 string GlobalData::getPrecision() { return precision; }
299 string GlobalData::getMethod() { return method; }
300 string GlobalData::getFileRoot() { return fileroot; }
301 string GlobalData::getIters() { return iters; }
302 string GlobalData::getJumble() { return jumble; }
303 string GlobalData::getFreq() { return freq; }
304 string GlobalData::getAbund() { return abund; }
305 string GlobalData::getRandomTree() { return randomtree; }
306 string GlobalData::getGroups() { return groups; }
307 string GlobalData::getStep() { return step; }
308 string GlobalData::getForm() { return form; }
309 string GlobalData::getSorted() { return sorted; }
310 string GlobalData::getVertical() { return vertical; }
311 string GlobalData::getTrump() { return trump; }
312 string GlobalData::getSoft() { return soft; }
313 string GlobalData::getHard() { return hard; }
314 string GlobalData::getScale() { return scale; }
315 string GlobalData::getCountEnds() { return countends; }
316 string GlobalData::getProcessors() { return processors; }
317 string GlobalData::getSize() { return size; }
318 string GlobalData::getCandidateFile() { return candidatefile;}
319 string GlobalData::getSearch() { return search; }
320 string GlobalData::getKSize() { return ksize; }
321 string GlobalData::getAlign() { return align; }
322 string GlobalData::getMatch() { return match; }
323 string GlobalData::getMismatch() { return mismatch; }
324 string GlobalData::getGapopen() { return gapopen; }
325 string GlobalData::getGapextend() { return gapextend; }
328 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file; }
329 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file; }
330 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file; }
331 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file; }
332 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file; }
333 void GlobalData::setGroupFile(string file) { groupfile = file; }
334 void GlobalData::setSharedFile(string file) { sharedfile = file; inputFileName = file; fileroot = file; }
335 void GlobalData::setNameFile(string file) { namefile = file; }
336 void GlobalData::setFormat(string Format) { format = Format; }
337 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
338 void GlobalData::setGroups(string g) { groups = g; }
339 void GlobalData::setCalc(string Calc) { calc = Calc; }
340 void GlobalData::setCountEnds(string e) { countends = e; }
341 void GlobalData::setProcessors(string p) { processors = p; }
344 /*******************************************************/
346 /******************************************************/
347 GlobalData::GlobalData() {
348 //option definitions should go here...
352 gSparseMatrix == NULL;
354 /*******************************************************/
356 /******************************************************/
357 void GlobalData::clear() {
358 //option definitions should go here...
380 jumble = "1"; //0 means don't jumble, 1 means jumble.
381 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
388 sorted = "T"; //F means don't sort, T means sort.
394 countends = "T"; //yes
406 //*******************************************************/
408 /******************************************************/
409 void GlobalData::reset() {
414 jumble = "1"; //0 means don't jumble, 1 means jumble.
415 sorted = "T"; //F means don't sort, T means sort.
416 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
439 /*******************************************************/
441 /******************************************************/
442 GlobalData::~GlobalData() {
444 if(gListVector != NULL) { delete gListVector; }
445 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
446 if(gorder != NULL) { delete gorder; }
448 /*******************************************************/
450 /*******************************************************/
451 void GlobalData::parseTreeFile() {
452 //only takes names from the first tree and assumes that all trees use the same names.
454 string filename = treefile;
456 openInputFile(filename, filehandle);
460 //if you are not a nexus file
461 if ((c = filehandle.peek()) != '#') {
462 while((c = filehandle.peek()) != ';') {
463 while ((c = filehandle.peek()) != ';') {
471 if((c == '(') && (comment != 1)){ break; }
475 readTreeString(filehandle);
477 //if you are a nexus file
478 }else if ((c = filehandle.peek()) == '#') {
482 while(holder != "translate" && holder != "Translate"){
483 if(holder == "[" || holder == "[!"){
489 filehandle >> holder;
491 //if there is no translate then you must read tree string otherwise use translate to get names
492 if(holder == "tree" && comment != 1){
493 //pass over the "tree rep.6878900 = "
494 while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF) ) {;}
496 if (c == EOF ) { break; }
497 filehandle.putback(c); //put back first ( of tree.
498 readTreeString(filehandle);
503 //use nexus translation rather than parsing tree to save time
504 if ((holder == "translate") || (holder == "Translate")) {
506 string number, name, h;
507 h = ""; // so it enters the loop the first time
508 while((h != ";") && (number != ";")) {
509 filehandle >> number;
512 //c = , until done with translation then c = ;
513 h = name.substr(name.length()-1, name.length());
514 name.erase(name.end()-1); //erase the comma
515 Treenames.push_back(number);
517 if (number == ";") { Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name
522 catch(exception& e) {
523 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
527 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
531 /*******************************************************/
533 /*******************************************************/
534 void GlobalData::readTreeString(ifstream& filehandle) {
539 while((c = filehandle.peek()) != ';') {
541 if ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
543 c = filehandle.get();
546 while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {
548 c = filehandle.get();
550 //cout << " in name while " << k << endl;
553 //cout << "name = " << name << endl;
554 Treenames.push_back(name);
555 filehandle.putback(c);
557 //cout << " after putback" << k << endl;
560 if (c == ':') { //read until you reach the end of the branch length
561 while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
562 c = filehandle.get();
564 //cout << " in branch while " << k << endl;
566 filehandle.putback(c);
568 c = filehandle.get();
569 if (c == ';') { break; }
575 catch(exception& e) {
576 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
580 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
585 /*******************************************************/
587 /*******************************************************/