]> git.donarmstrong.com Git - mothur.git/blob - mothurout.h
rewrote metastats command in c++, added mothurRemove function to handle ~ error....
[mothur.git] / mothurout.h
1 #ifndef MOTHUROUT_H
2 #define MOTHUROUT_H
3
4 /*
5  *  mothurOut.h
6  *  Mothur
7  *
8  *  Created by westcott on 2/25/10.
9  *  Copyright 2010 Schloss Lab. All rights reserved.
10  *
11  */
12
13 #include "mothur.h"
14
15 /***********************************************/
16
17 class MothurOut {
18         
19         public:
20                 static MothurOut* getInstance();
21                 void setFileName(string);
22                 
23                 void mothurOut(string); //writes to cout and the logfile
24                 void mothurOutEndLine(); //writes to cout and the logfile
25                 void mothurOut(string, ofstream&); //writes to the ofstream, cout and the logfile
26                 void mothurOutEndLine(ofstream&); //writes to the ofstream, cout and the logfile
27                 void mothurOutJustToLog(string);
28                 void errorOut(exception&, string, string);
29                 void closeLog();
30                 string getDefaultPath() { return defaultPath; }
31                 void setDefaultPath(string);
32                 string getOutputDir() { return outputDir; }
33                 void setOutputDir(string);
34                 
35                 string getReleaseDate() { return releaseDate; }
36                 void setReleaseDate(string r) { releaseDate = r; }
37                 string getVersion() { return version; }
38                 void setVersion(string r) { version = r; }
39                 vector<string> Groups;
40                 vector<string> Treenames;
41                 map<string, string> names;
42                 vector<string> namesOfGroups;
43                 string saveNextLabel, argv, sharedHeaderMode;
44                 bool printedHeaders;
45                 
46                 //functions from mothur.h
47                 //file operations
48                 vector<unsigned long int> divideFile(string, int&);
49                 int divideFile(string, int&, vector<string>&);
50                 vector<unsigned long int> setFilePosEachLine(string, int&);
51                 vector<unsigned long int> setFilePosFasta(string, int&);
52                 string sortFile(string, string);
53                 void appendFiles(string, string);
54                 int renameFile(string, string); //oldname, newname
55                 string getFullPathName(string);
56                 string hasPath(string);
57                 string getExtension(string);
58                 string getPathName(string);
59                 string getSimpleName(string);
60                 string getRootName(string);
61                 bool isBlank(string);
62                 int openOutputFile(string, ofstream&);
63                 int openOutputFileAppend(string, ofstream&);
64                 int openInputFile(string, ifstream&);
65                 int openInputFile(string, ifstream&, string); //no error given 
66                 string getline(ifstream&);
67                 string getline(istringstream&);
68                 void gobble(istream&);
69                 void gobble(istringstream&);
70                 map<string, int> readNames(string);
71                 int readNames(string, map<string, string>&);
72                 int readNames(string, vector<seqPriorityNode>&, map<string, string>&);
73                 void mothurRemove(string);
74                 
75                 //searchs and checks
76                 bool checkReleaseVersion(ifstream&, string);
77                 bool anyLabelsToProcess(string, set<string>&, string);
78                 bool inUsersGroups(vector<string>, vector<string>);
79                 bool inUsersGroups(string, vector<string>);
80                 void getNumSeqs(ifstream&, int&);
81                 int getNumSeqs(ifstream&);
82                 int getNumNames(string);
83                 bool isTrue(string);
84                 bool isContainingOnlyDigits(string);
85         
86                 
87                 //string manipulation
88                 void splitAtEquals(string&, string&);
89                 void splitAtComma(string&, string&);    
90                 void splitAtComma(string&, vector<string>&);
91                 void splitAtDash(string&, set<int>&);
92                 void splitAtDash(string&, set<string>&);
93                 void splitAtDash(string&, vector<string>&);
94                 void splitAtChar(string&, vector<string>&, char);
95                 
96                 //math operation
97                 int factorial(int num);
98                 vector<vector<double> > binomial(int);
99                 float ceilDist(float, int);
100                 float roundDist(float, int);
101                 unsigned int fromBase36(string);
102                 int getRandomIndex(int); //highest
103
104                 int control_pressed;
105                 bool executing, runParse, jumble, gui;
106                 
107                 //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles.
108                 string getPhylipFile()          { return phylipfile;            }
109                 string getColumnFile()          { return columnfile;            }
110                 string getListFile()            { return listfile;                      }
111                 string getRabundFile()          { return rabundfile;            }
112                 string getSabundFile()          { return sabundfile;            }
113                 string getNameFile()            { return namefile;                      }       
114                 string getGroupFile()           { return groupfile;                     }       
115                 string getOrderFile()           { return orderfile;                     }
116                 string getOrderGroupFile()      { return ordergroupfile;        }
117                 string getTreeFile()            { return treefile;                      }
118                 string getSharedFile()          { return sharedfile;            }
119                 string getRelAbundFile()        { return relabundfile;          }
120                 string getDesignFile()          { return designfile;            }
121                 string getFastaFile()           { return fastafile;                     }
122                 string getSFFFile()                     { return sfffile;                       }
123                 string getQualFile()            { return qualfile;                      }
124                 string getOligosFile()          { return oligosfile;            }
125                 string getAccnosFile()          { return accnosfile;            }
126                 string getTaxonomyFile()        { return taxonomyfile;          }
127                 string getFlowFile()            { return flowfile;                      }
128                 string getProcessors()          { return processors;            }
129                 
130                 void setListFile(string f)                      { listfile = getFullPathName(f);                        }
131                 void setTreeFile(string f)                      { treefile = getFullPathName(f);                        }
132                 void setGroupFile(string f)                     { groupfile = getFullPathName(f);                       }               
133                 void setPhylipFile(string f)            { phylipfile = getFullPathName(f);                      }
134                 void setColumnFile(string f)            { columnfile = getFullPathName(f);                      }
135                 void setNameFile(string f)                      { namefile = getFullPathName(f);                        }       
136                 void setRabundFile(string f)            { rabundfile = getFullPathName(f);                      }
137                 void setSabundFile(string f)            { sabundfile = getFullPathName(f);                      }
138                 void setSharedFile(string f)            { sharedfile = getFullPathName(f);                      }
139                 void setRelAbundFile(string f)          { relabundfile = getFullPathName(f);            }
140                 void setOrderFile(string f)                     { orderfile = getFullPathName(f);                       }
141                 void setOrderGroupFile(string f)        { ordergroupfile = getFullPathName(f);          }
142                 void setDesignFile(string f)            { designfile = getFullPathName(f);                      }
143                 void setFastaFile(string f)                     { fastafile = getFullPathName(f);                       }
144                 void setSFFFile(string f)                       { sfffile = getFullPathName(f);                         }
145                 void setQualFile(string f)                      { qualfile = getFullPathName(f);                        }
146                 void setOligosFile(string f)            { oligosfile = getFullPathName(f);                      }
147                 void setAccnosFile(string f)            { accnosfile = getFullPathName(f);                      }
148                 void setTaxonomyFile(string f)          { taxonomyfile = getFullPathName(f);            }
149                 void setFlowFile(string f)                      { flowfile = getFullPathName(f);                        }
150                 void setProcessors(string p)            { processors = p;                                                       }
151                 
152                 void printCurrentFiles();
153                 bool hasCurrentFiles();
154                 void clearCurrentFiles();
155                 
156         private:
157                 static MothurOut* _uniqueInstance;
158                 MothurOut( const MothurOut& ); // Disable copy constructor
159                 void operator=( const MothurOut& ); // Disable assignment operator
160                 MothurOut() { 
161                         control_pressed = false; defaultPath=""; 
162                         phylipfile = "";
163                         columnfile = "";
164                         listfile = "";
165                         rabundfile = "";
166                         sabundfile = "";
167                         namefile = "";
168                         groupfile = "";
169                         designfile = "";
170                         orderfile = "";
171                         treefile = "";
172                         sharedfile = "";
173                         ordergroupfile = "";
174                         relabundfile = "";
175                         fastafile = "";
176                         qualfile = "";
177                         sfffile = "";
178                         oligosfile = "";
179                         accnosfile = "";
180                         taxonomyfile = "";
181                         processors = "1";
182                         flowfile = "";
183                         gui = false;
184                         printedHeaders = false;
185                         sharedHeaderMode = "";
186                 }
187                 ~MothurOut();
188
189                 string logFileName;
190                 string defaultPath, outputDir;
191                 string releaseDate, version;
192         
193                 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile;
194                 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile;
195
196         
197                 ofstream out;
198                 
199                 int mem_usage(double&, double&);
200
201 };
202 /***********************************************/
203
204 #endif
205