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 == "hard") { hard = value; }
84 if (key == "soft") { soft = value; }
85 if (key == "scale") { scale = value; }
86 if (key == "countends" ) { countends = value; }
87 if (key == "processors" ) { processors = value; }
88 if (key == "size" ) { size = value; }
89 if (key == "candidate") { candidatefile = value; }
90 if (key == "search") { search = value; }
91 if (key == "ksize") { ksize = value; }
92 if (key == "align") { align = value; }
93 if (key == "match") { match = value; }
94 if (key == "mismatch") { mismatch = value; }
95 if (key == "gapopen") { gapopen = value; }
96 if (key == "gapextend" ) { gapextend = value; }
98 if (key == "line") {//stores lines to be used in a set
103 splitAtDash(value, lines);
106 if (key == "label") {//stores labels to be used in a set
111 splitAtDash(value, labels);
115 if (key == "groups") {//stores groups to be used in a vector
118 splitAtDash(value, Groups);
123 //saves the last parameter
125 splitAtEquals(key, value);
126 if (key == "phylip" ) { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip"; }
127 if (key == "column" ) { columnfile = value; inputFileName = value; fileroot = value; format = "column"; }
128 if (key == "list" ) { listfile = value; inputFileName = value; fileroot = value; format = "list"; }
129 if (key == "rabund" ) { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund"; }
130 if (key == "sabund" ) { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund"; }
131 if (key == "fasta" ) { fastafile = value; inputFileName = value; fileroot = value; format = "fasta"; }
132 if (key == "nexus" ) { nexusfile = value; inputFileName = value; fileroot = value; format = "nexus"; }
133 if (key == "clustal" ) { clustalfile = value; inputFileName = value; fileroot = value; format = "clustal"; }
134 if (key == "tree" ) { treefile = value; inputFileName = value; fileroot = value; format = "tree"; }
135 if (key == "shared" ) { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile"; }
136 if (key == "name" ) { namefile = value; }
137 if (key == "order" ) { orderfile = value; }
138 if (key == "group" ) { groupfile = value; }
139 if (key == "cutoff" ) { cutoff = value; }
140 if (key == "precision" ) { precision = value; }
141 if (key == "iters" ) { iters = value; }
142 if (key == "jumble" ) { jumble = value; }
143 if (key == "freq" ) { freq = value; }
144 if (key == "method" ) { method = value; }
145 if (key == "fileroot" ) { fileroot = value; }
146 if (key == "abund" ) { abund = value; }
147 if (key == "random" ) { randomtree = value; }
148 if (key == "calc") { calc = value; }
149 if (key == "step") { step = value; }
150 if (key == "form") { form = value; }
151 if (key == "sorted") { sorted = value; }
152 if (key == "vertical") { vertical = value; }
153 if (key == "trump") { trump = value; }
154 if (key == "hard") { hard = value; }
155 if (key == "soft") { soft = value; }
156 if (key == "scale") { scale = value; }
157 if (key == "countends" ) { countends = value; }
158 if (key == "processors" ) { processors = value; }
159 if (key == "size" ) { size = value; }
160 if (key == "candidate") { candidatefile = value; }
161 if (key == "search") { search = value; }
162 if (key == "ksize") { ksize = value; }
163 if (key == "align") { align = value; }
164 if (key == "match") { match = value; }
165 if (key == "mismatch") { mismatch = value; }
166 if (key == "gapopen") { gapopen = value; }
167 if (key == "gapextend" ) { gapextend = value; }
169 if (key == "line") {//stores lines to be used in a vector
174 if (line != "all") { splitAtDash(value, lines); allLines = 0; }
175 else { allLines = 1; }
178 if (key == "label") {//stores lines to be used in a vector
183 if (label != "all") { splitAtDash(value, labels); allLines = 0; }
184 else { allLines = 1; }
187 if (key == "groups") {//stores groups to be used in a vector
190 splitAtDash(value, Groups);
194 //set format for shared
195 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
196 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
198 //input defaults for calculators
199 if (commandName == "collect.single") {
201 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
203 splitAtDash(calc, Estimators);
205 if (commandName == "rarefaction.single") {
206 if ((calc == "default") || (calc == "")) { calc = "sobs"; }
208 splitAtDash(calc, Estimators);
210 if (commandName == "collect.shared") {
212 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
214 splitAtDash(calc, Estimators);
216 if (commandName == "summary.single") {
217 if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
219 splitAtDash(calc, Estimators);
221 if (commandName == "summary.shared") {
222 if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
224 splitAtDash(calc, Estimators);
226 if (commandName == "rarefaction.shared") {
227 if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
229 splitAtDash(calc, Estimators);
231 if (commandName == "dist.seqs") {
232 if ((calc == "default") || (calc == "")) { calc = "onegap"; }
233 if (countends == "") { countends = "T"; }
235 splitAtDash(calc, Estimators);
237 if (commandName == "venn") {
238 if ((calc == "default") || (calc == "")) {
239 if (format == "list") { calc = "sobs"; }
240 else { calc = "sharedsobs"; }
243 splitAtDash(calc, Estimators);
245 if ((commandName == "tree.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")) {
246 if ((calc == "default") || (calc == "")) {
247 calc = "jclass-thetayc";
250 splitAtDash(calc, Estimators);
252 if(commandName == "filter.seqs"){
253 if(trump == "" && vertical == "" && hard == "" && soft == ""){
258 //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
259 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
260 if (listfile != "") { format = "list"; }
261 else if (sabundfile != "") { format = "sabund"; }
262 else if (rabundfile != "") { format = "rabund"; }
265 catch(exception& e) {
266 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
270 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
274 /*******************************************************/
276 /******************************************************/
277 // These functions give you the option parameters of the commands
278 string GlobalData::getPhylipFile() { return phylipfile; }
279 string GlobalData::getColumnFile() { return columnfile; }
280 string GlobalData::getListFile() { return listfile; }
281 string GlobalData::getRabundFile() { return rabundfile; }
282 string GlobalData::getSabundFile() { return sabundfile; }
283 string GlobalData::getNameFile() { return namefile; }
284 string GlobalData::getGroupFile() { return groupfile; }
285 string GlobalData::getOrderFile() { return orderfile; }
286 string GlobalData::getTreeFile() { return treefile; }
287 string GlobalData::getSharedFile() { return sharedfile; }
288 string GlobalData::getFastaFile() { return fastafile; }
289 string GlobalData::getNexusFile() { return nexusfile; }
290 string GlobalData::getClustalFile() { return clustalfile; }
291 string GlobalData::getCutOff() { return cutoff; }
292 string GlobalData::getFormat() { return format; }
293 string GlobalData::getPrecision() { return precision; }
294 string GlobalData::getMethod() { return method; }
295 string GlobalData::getFileRoot() { return fileroot; }
296 string GlobalData::getIters() { return iters; }
297 string GlobalData::getJumble() { return jumble; }
298 string GlobalData::getFreq() { return freq; }
299 string GlobalData::getAbund() { return abund; }
300 string GlobalData::getRandomTree() { return randomtree; }
301 string GlobalData::getGroups() { return groups; }
302 string GlobalData::getStep() { return step; }
303 string GlobalData::getForm() { return form; }
304 string GlobalData::getSorted() { return sorted; }
305 string GlobalData::getVertical() { return vertical; }
306 string GlobalData::getTrump() { return trump; }
307 string GlobalData::getSoft() { return soft; }
308 string GlobalData::getHard() { return hard; }
309 string GlobalData::getScale() { return scale; }
310 string GlobalData::getCountEnds() { return countends; }
311 string GlobalData::getProcessors() { return processors; }
312 string GlobalData::getSize() { return size; }
313 string GlobalData::getCandidateFile() { return candidatefile;}
314 string GlobalData::getSearch() { return search; }
315 string GlobalData::getKSize() { return ksize; }
316 string GlobalData::getAlign() { return align; }
317 string GlobalData::getMatch() { return match; }
318 string GlobalData::getMismatch() { return mismatch; }
319 string GlobalData::getGapopen() { return gapopen; }
320 string GlobalData::getGapextend() { return gapextend; }
323 void GlobalData::setListFile(string file) { listfile = file; inputFileName = file; }
324 void GlobalData::setRabundFile(string file) { rabundfile = file; inputFileName = file; }
325 void GlobalData::setSabundFile(string file) { sabundfile = file; inputFileName = file; }
326 void GlobalData::setPhylipFile(string file) { phylipfile = file; inputFileName = file; }
327 void GlobalData::setColumnFile(string file) { columnfile = file; inputFileName = file; }
328 void GlobalData::setGroupFile(string file) { groupfile = file; }
329 void GlobalData::setSharedFile(string file) { sharedfile = file; inputFileName = file; fileroot = file; }
330 void GlobalData::setNameFile(string file) { namefile = file; }
331 void GlobalData::setFormat(string Format) { format = Format; }
332 void GlobalData::setRandomTree(string Random) { randomtree = Random; }
333 void GlobalData::setGroups(string g) { groups = g; }
334 void GlobalData::setCalc(string Calc) { calc = Calc; }
335 void GlobalData::setCountEnds(string e) { countends = e; }
336 void GlobalData::setProcessors(string p) { processors = p; }
339 /*******************************************************/
341 /******************************************************/
342 GlobalData::GlobalData() {
343 //option definitions should go here...
347 gSparseMatrix == NULL;
349 /*******************************************************/
351 /******************************************************/
352 void GlobalData::clear() {
353 //option definitions should go here...
375 jumble = "1"; //0 means don't jumble, 1 means jumble.
376 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
383 sorted = "T"; //F means don't sort, T means sort.
389 countends = "T"; //yes
401 //*******************************************************/
403 /******************************************************/
404 void GlobalData::reset() {
409 jumble = "1"; //0 means don't jumble, 1 means jumble.
410 sorted = "T"; //F means don't sort, T means sort.
411 randomtree = ""; //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
434 /*******************************************************/
436 /******************************************************/
437 GlobalData::~GlobalData() {
439 if(gListVector != NULL) { delete gListVector; }
440 if(gSparseMatrix != NULL) { delete gSparseMatrix; }
441 if(gorder != NULL) { delete gorder; }
443 /*******************************************************/
445 /*******************************************************/
446 void GlobalData::parseTreeFile() {
447 //only takes names from the first tree and assumes that all trees use the same names.
449 string filename = treefile;
451 openInputFile(filename, filehandle);
455 //if you are not a nexus file
456 if ((c = filehandle.peek()) != '#') {
457 while((c = filehandle.peek()) != ';') {
458 while ((c = filehandle.peek()) != ';') {
466 if((c == '(') && (comment != 1)){ break; }
470 readTreeString(filehandle);
472 //if you are a nexus file
473 }else if ((c = filehandle.peek()) == '#') {
477 while(holder != "translate" && holder != "Translate"){
478 if(holder == "[" || holder == "[!"){
484 filehandle >> holder;
486 //if there is no translate then you must read tree string otherwise use translate to get names
487 if(holder == "tree" && comment != 1){
488 //pass over the "tree rep.6878900 = "
489 while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF) ) {;}
491 if (c == EOF ) { break; }
492 filehandle.putback(c); //put back first ( of tree.
493 readTreeString(filehandle);
498 //use nexus translation rather than parsing tree to save time
499 if ((holder == "translate") || (holder == "Translate")) {
501 string number, name, h;
502 h = ""; // so it enters the loop the first time
503 while((h != ";") && (number != ";")) {
504 filehandle >> number;
507 //c = , until done with translation then c = ;
508 h = name.substr(name.length()-1, name.length());
509 name.erase(name.end()-1); //erase the comma
510 Treenames.push_back(number);
512 if (number == ";") { Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name
517 catch(exception& e) {
518 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
522 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
526 /*******************************************************/
528 /*******************************************************/
529 void GlobalData::readTreeString(ifstream& filehandle) {
534 while((c = filehandle.peek()) != ';') {
536 if ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
538 c = filehandle.get();
541 while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {
543 c = filehandle.get();
545 //cout << " in name while " << k << endl;
548 //cout << "name = " << name << endl;
549 Treenames.push_back(name);
550 filehandle.putback(c);
552 //cout << " after putback" << k << endl;
555 if (c == ':') { //read until you reach the end of the branch length
556 while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
557 c = filehandle.get();
559 //cout << " in branch while " << k << endl;
561 filehandle.putback(c);
563 c = filehandle.get();
564 if (c == ';') { break; }
570 catch(exception& e) {
571 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
575 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
580 /*******************************************************/
582 /*******************************************************/