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; }
99 if (key == "start" ) { startPos = value; }
100 if (key == "end" ) { endPos = value; }
101 if (key == "maxambig" ) { maxAmbig = value; }
102 if (key == "maxhomop" ) { maxHomoPolymer = value; }
103 if (key == "minlength" ) { minLength = value; }
104 if (key == "maxlength" ) { maxLength = value; }
106 if (key == "line") {//stores lines to be used in a vector
111 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
112 else { allLines = 1; }
115 if (key == "label") {//stores lines to be used in a vector
120 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
121 else { allLines = 1; }
124 if (key == "groups") {//stores groups to be used in a vector
127 splitAtDash(value, Groups);
132 //saves the last parameter
134 splitAtEquals(key, value);
135 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
136 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
137 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
138 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
139 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
140 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
141 if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
142 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
143 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
144 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
145 if (key == "name" ) { namefile = value; }
146 if (key == "order" ) { orderfile = value; }
147 if (key == "group" ) { groupfile = value; }
148 if (key == "cutoff" ) { cutoff = value; }
149 if (key == "precision" ) { precision = value; }
150 if (key == "iters" ) { iters = value; }
151 if (key == "jumble" ) { jumble = value; }
152 if (key == "freq" ) { freq = value; }
153 if (key == "method" ) { method = value; }
154 if (key == "fileroot" ) { fileroot = value; }
155 if (key == "abund" ) { abund = value; }
156 if (key == "random" ) { randomtree = value; }
157 if (key == "calc") { calc = value; }
158 if (key == "step") { step = value; }
159 if (key == "form") { form = value; }
160 if (key == "sorted") { sorted = value; }
161 if (key == "vertical") { vertical = value; }
162 if (key == "trump") { trump = value; }
163 if (key == "hard") { hard = value; }
164 if (key == "soft") { soft = value; }
165 if (key == "scale") { scale = value; }
166 if (key == "countends" ) { countends = value; }
167 if (key == "processors" ) { processors = value; }
168 if (key == "size" ) { size = value; }
169 if (key == "candidate") { candidatefile = value; }
170 if (key == "search") { search = value; }
171 if (key == "ksize") { ksize = value; }
172 if (key == "align") { align = value; }
173 if (key == "match") { match = value; }
174 if (key == "mismatch") { mismatch = value; }
175 if (key == "gapopen") { gapopen = value; }
176 if (key == "gapextend" ) { gapextend = value; }
177 if (key == "start" ) { startPos = value; }
178 if (key == "end" ) { endPos = value; }
179 if (key == "maxambig" ) { maxAmbig = value; }
180 if (key == "maxhomop" ) { maxHomoPolymer = value; }
181 if (key == "minlength" ) { minLength = value; }
182 if (key == "maxlength" ) { maxLength = value; }
185 if (key == "line") {//stores lines to be used in a vector
190 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
191 else { allLines = 1; }
194 if (key == "label") {//stores lines to be used in a vector
199 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
200 else { allLines = 1; }
203 if (key == "groups") {//stores groups to be used in a vector
206 splitAtDash(value, Groups);
210 //set format for shared
211 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
212 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
214 //input defaults for calculators
215 if (commandName == "collect.single") {
217 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
219 splitAtDash(calc, Estimators);
221 if (commandName == "rarefaction.single") {
222 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
224 splitAtDash(calc, Estimators);
226 if (commandName == "collect.shared") {
227 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
229 splitAtDash(calc, Estimators);
231 if (commandName == "summary.single") {
232 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
234 splitAtDash(calc, Estimators);
236 if (commandName == "summary.shared") {
237 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
239 splitAtDash(calc, Estimators);
241 if (commandName == "rarefaction.shared") {
242 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
244 splitAtDash(calc, Estimators);
246 if (commandName == "dist.seqs") {
247 if ((calc == "default") || (calc == "")) { calc = "onegap"; }
248 if (countends == "") { countends = "T"; }
250 splitAtDash(calc, Estimators);
252 if (commandName == "venn") {
253 if ((calc == "default") || (calc == "")) {
254 if (format == "list") { calc = "sobs"; }
255 else { calc = "sharedsobs"; }
258 splitAtDash(calc, Estimators);
260 if ((commandName == "tree.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")) {
261 if ((calc == "default") || (calc == "")) {
262 calc = "jclass-thetayc";
265 splitAtDash(calc, Estimators);
268 if(commandName == "filter.seqs"){
269 if(trump == "" && vertical == "" && hard == "" && soft == ""){
275 //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
276 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
277 if (listfile != "") { format = "list"; }
278 else if (sabundfile != "") { format = "sabund"; }
279 else if (rabundfile != "") { format = "rabund"; }
282 catch(exception& e) {
283 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
287 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
291 /*******************************************************/
293 /******************************************************/
294 // These functions give you the option parameters of the commands
295 string GlobalData::getPhylipFile() { return phylipfile; }
296 string GlobalData::getColumnFile() { return columnfile; }
297 string GlobalData::getListFile() { return listfile; }
298 string GlobalData::getRabundFile() { return rabundfile; }
299 string GlobalData::getSabundFile() { return sabundfile; }
300 string GlobalData::getNameFile() { return namefile; }
301 string GlobalData::getGroupFile() { return groupfile; }
302 string GlobalData::getOrderFile() { return orderfile; }
303 string GlobalData::getTreeFile() { return treefile; }
304 string GlobalData::getSharedFile() { return sharedfile; }
305 string GlobalData::getFastaFile() { return fastafile; }
306 string GlobalData::getNexusFile() { return nexusfile; }
307 string GlobalData::getClustalFile() { return clustalfile; }
308 string GlobalData::getCutOff() { return cutoff; }
309 string GlobalData::getFormat() { return format; }
310 string GlobalData::getPrecision() { return precision; }
311 string GlobalData::getMethod() { return method; }
312 string GlobalData::getFileRoot() { return fileroot; }
313 string GlobalData::getIters() { return iters; }
314 string GlobalData::getJumble() { return jumble; }
315 string GlobalData::getFreq() { return freq; }
316 string GlobalData::getAbund() { return abund; }
317 string GlobalData::getRandomTree() { return randomtree; }
318 string GlobalData::getGroups() { return groups; }
319 string GlobalData::getStep() { return step; }
320 string GlobalData::getForm() { return form; }
321 string GlobalData::getSorted() { return sorted; }
322 string GlobalData::getVertical() { return vertical; }
323 string GlobalData::getTrump() { return trump; }
324 string GlobalData::getSoft() { return soft; }
325 string GlobalData::getHard() { return hard; }
326 string GlobalData::getScale() { return scale; }
327 string GlobalData::getCountEnds() { return countends; }
328 string GlobalData::getProcessors() { return processors; }
329 string GlobalData::getSize() { return size; }
330 string GlobalData::getCandidateFile() { return candidatefile;}
331 string GlobalData::getSearch() { return search; }
332 string GlobalData::getKSize() { return ksize; }
333 string GlobalData::getAlign() { return align; }
334 string GlobalData::getMatch() { return match; }
335 string GlobalData::getMismatch() { return mismatch; }
336 string GlobalData::getGapopen() { return gapopen; }
337 string GlobalData::getGapextend() { return gapextend; }
338 string GlobalData::getStartPos() { return startPos; }
339 string GlobalData::getEndPos() { return endPos; }
340 string GlobalData::getMaxAmbig() { return maxAmbig; }
341 string GlobalData::getMaxHomoPolymer() { return maxHomoPolymer; }
342 string GlobalData::getMinLength() { return minLength; }
343 string GlobalData::getMaxLength() { return maxLength; }
346 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file; }
347 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file; }
348 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file; }
349 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file; }
350 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file; }
351 void GlobalData::setGroupFile(string file) { groupfile = file; }
352 void GlobalData::setSharedFile(string file) { sharedfile = file; inputFileName = file; fileroot = file; }
353 void GlobalData::setNameFile(string file) { namefile = file; }
354 void GlobalData::setFormat(string Format) { format = Format; }
355 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
356 void GlobalData::setGroups(string g) { groups = g; }
357 void GlobalData::setCalc(string Calc) { calc = Calc; }
358 void GlobalData::setCountEnds(string e) { countends = e; }
359 void GlobalData::setProcessors(string p) { processors = p; }
362 /*******************************************************/
364 /******************************************************/
365 GlobalData::GlobalData() {
366 //option definitions should go here...
370 gSparseMatrix == NULL;
372 /*******************************************************/
374 /******************************************************/
375 void GlobalData::clear() {
376 //option definitions should go here...
398 jumble = "1"; //0 means don't jumble, 1 means jumble.
399 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
406 sorted = "T"; //F means don't sort, T means sort.
412 countends = "T"; //yes
425 maxHomoPolymer = "-1";
431 //*******************************************************/
433 /******************************************************/
434 void GlobalData::reset() {
439 jumble = "1"; //0 means don't jumble, 1 means jumble.
440 sorted = "T"; //F means don't sort, T means sort.
441 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
465 maxHomoPolymer = "-1";
470 /*******************************************************/
472 /******************************************************/
473 GlobalData::~GlobalData() {
475 if(gListVector != NULL) { delete gListVector; }
476 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
477 if(gorder != NULL) { delete gorder; }
479 /*******************************************************/
481 /*******************************************************/
482 void GlobalData::parseTreeFile() {
483 //Why is THIS in GlobalData??? - PDS
485 //only takes names from the first tree and assumes that all trees use the same names.
487 string filename = treefile;
489 openInputFile(filename, filehandle);
493 //if you are not a nexus file
494 if ((c = filehandle.peek()) != '#') {
495 while((c = filehandle.peek()) != ';') {
496 while ((c = filehandle.peek()) != ';') {
504 if((c == '(') && (comment != 1)){ break; }
508 readTreeString(filehandle);
510 //if you are a nexus file
511 }else if ((c = filehandle.peek()) == '#') {
515 while(holder != "translate" && holder != "Translate"){
516 if(holder == "[" || holder == "[!"){
522 filehandle >> holder;
524 //if there is no translate then you must read tree string otherwise use translate to get names
525 if(holder == "tree" && comment != 1){
526 //pass over the "tree rep.6878900 = "
527 while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF) ) {;}
529 if (c == EOF ) { break; }
530 filehandle.putback(c); //put back first ( of tree.
531 readTreeString(filehandle);
536 //use nexus translation rather than parsing tree to save time
537 if ((holder == "translate") || (holder == "Translate")) {
539 string number, name, h;
540 h = ""; // so it enters the loop the first time
541 while((h != ";") && (number != ";")) {
542 filehandle >> number;
545 //c = , until done with translation then c = ;
546 h = name.substr(name.length()-1, name.length());
547 name.erase(name.end()-1); //erase the comma
548 Treenames.push_back(number);
550 if (number == ";") { Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name
555 catch(exception& e) {
556 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
560 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
564 /*******************************************************/
566 /*******************************************************/
567 void GlobalData::readTreeString(ifstream& filehandle) {
572 while((c = filehandle.peek()) != ';') {
574 if ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
576 c = filehandle.get();
579 while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {
581 c = filehandle.get();
583 //cout << " in name while " << k << endl;
586 //cout << "name = " << name << endl;
587 Treenames.push_back(name);
588 filehandle.putback(c);
590 //cout << " after putback" << k << endl;
593 if (c == ':') { //read until you reach the end of the branch length
594 while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
595 c = filehandle.get();
597 //cout << " in branch while " << k << endl;
599 filehandle.putback(c);
601 c = filehandle.get();
602 if (c == ';') { break; }
608 catch(exception& e) {
609 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
613 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
618 /*******************************************************/
620 /*******************************************************/