]> git.donarmstrong.com Git - mothur.git/blob - mothurout.h
add debugout to mothurout.cpp
[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 struct logger {
17     
18     logger() {}
19     ~logger() {}
20     
21     template< class T >
22     logger& operator <<( const T& o ) {
23         cout << o; return *this;
24     }
25     
26     logger& operator<<(ostream& (*m)(ostream&) ) {
27         cout << m; return *this;
28     }
29     
30 }; 
31 /***********************************************/
32
33 class MothurOut {
34         
35         public:
36                 static MothurOut* getInstance();
37                 void setFileName(string);
38                 
39                 void mothurOut(string); //writes to cout and the logfile
40                 void debugOut(string); //writes to cout and the logfile if debugging is on
41                 void mothurOutEndLine(); //writes to cout and the logfile
42                 void mothurOut(string, ofstream&); //writes to the ofstream, cout and the logfile
43                 void debugOut(string, ofstream&); //writes to the ofstream, cout and the logfile if debugging is on
44                 void mothurOutEndLine(ofstream&); //writes to the ofstream, cout and the logfile
45         void mothurOutJustToScreen(string); //writes to cout
46                 void mothurOutJustToLog(string);
47                 void errorOut(exception&, string, string);
48                 void closeLog();
49                 string getDefaultPath() { return defaultPath; }
50                 void setDefaultPath(string);
51                 string getOutputDir() { return outputDir; }
52                 void setOutputDir(string);
53                 
54                 string getReleaseDate() { return releaseDate; }
55                 void setReleaseDate(string r) { releaseDate = r; }
56                 string getVersion() { return version; }
57                 void setVersion(string r) { version = r; }
58         
59                 void addGroup(string g) { Groups.push_back(g); }
60                 void setGroups(vector<string>& g) { sort(g.begin(), g.end()); Groups = g; }
61                 void clearGroups() { Groups.clear(); }
62             int getNumGroups() { return Groups.size(); }
63                 vector<string> getGroups() { sort(Groups.begin(), Groups.end()); return Groups; }
64                 void addAllGroup(string g) { namesOfGroups.push_back(g); }
65                 void setAllGroups(vector<string>& g) { sort(g.begin(), g.end()); namesOfGroups = g; }
66                 void clearAllGroups() { namesOfGroups.clear(); }
67                 int getNumAllGroups() { return namesOfGroups.size(); }
68         
69                 vector<string> getAllGroups() { sort(namesOfGroups.begin(), namesOfGroups.end()); return namesOfGroups; }
70                 vector<string> Treenames;
71                 vector<string> sharedBinLabelsInFile;
72                 vector<string> currentSharedBinLabels;
73         vector<string> listBinLabelsInFile;
74                 string saveNextLabel, argv, sharedHeaderMode, groupMode;
75                 bool printedSharedHeaders, printedListHeaders, commandInputsConvertError, changedSeqNames, modifyNames;
76                 
77                 //functions from mothur.h
78                 //file operations
79         bool dirCheck(string&); //completes path, appends appropriate / or \, makes sure dir is writable.
80                 vector<unsigned long long> divideFile(string, int&); //divides splitting unevenness by sequence
81         vector<unsigned long long> divideFilePerLine(string, int&); //divides splitting unevenness at line breaks
82                 int divideFile(string, int&, vector<string>&);
83                 vector<unsigned long long> setFilePosEachLine(string, int&);
84                 vector<unsigned long long> setFilePosFasta(string, int&);
85                 string sortFile(string, string);
86                 int appendFiles(string, string);
87         int appendBinaryFiles(string, string);
88         int appendFilesWithoutHeaders(string, string);
89                 int renameFile(string, string); //oldname, newname
90                 string getFullPathName(string);
91         string findProgramPath(string programName);
92                 string hasPath(string);
93                 string getExtension(string);
94                 string getPathName(string);
95                 string getSimpleName(string);
96                 string getRootName(string);
97                 bool isBlank(string);
98                 int openOutputFile(string, ofstream&);
99         int openOutputFileBinary(string, ofstream&);
100                 int openOutputFileAppend(string, ofstream&);
101         int openOutputFileBinaryAppend(string, ofstream&);
102                 int openInputFile(string, ifstream&);
103         int openInputFileBinary(string, ifstream&);
104         int openInputFileBinary(string, ifstream&, string);
105                 int openInputFile(string, ifstream&, string); //no error given
106     
107         bool checkLocations(string&, string);  //filename, inputDir. checks for file in ./, inputdir, default and mothur's exe location.  Returns false if cant be found. If found completes name with location
108                 string getline(ifstream&);
109                 string getline(istringstream&);
110                 void gobble(istream&);
111                 void gobble(istringstream&);
112         vector<string> splitWhiteSpace(string& rest, char[], int);
113         vector<string> splitWhiteSpace(string);
114         set<string> readAccnos(string);
115         int readAccnos(string, vector<string>&);
116         map<string, int> readNames(string);
117         map<string, int> readNames(string, unsigned long int&);
118         int readTax(string, map<string, string>&);
119         vector<consTax> readConsTax(string);
120         int readConsTax(string, map<string, consTax2>&);
121         int readNames(string, map<string, string>&, map<string, int>&);
122                 int readNames(string, map<string, string>&);
123         int readNames(string, map<string, string>&, bool);
124         int readNames(string, map<string, string>&, int);
125                 int readNames(string, map<string, vector<string> >&);
126                 int readNames(string, vector<seqPriorityNode>&, map<string, string>&);
127                 int mothurRemove(string);
128                 bool mothurConvert(string, int&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
129         bool mothurConvert(string, intDist&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
130                 bool mothurConvert(string, float&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
131                 bool mothurConvert(string, double&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
132         
133                 
134                 //searchs and checks
135                 bool checkReleaseVersion(ifstream&, string);
136                 bool anyLabelsToProcess(string, set<string>&, string);
137                 bool inUsersGroups(vector<string>, vector<string>);
138         bool inUsersGroups(vector<int>, vector< vector<int> >);
139                 bool inUsersGroups(string, vector<string>);
140         bool inUsersGroups(int, vector<int>);
141                 void getNumSeqs(ifstream&, int&);
142                 int getNumSeqs(ifstream&);
143                 int getNumNames(string);
144                 int getNumChar(string, char);
145                 bool isTrue(string);
146                 bool isContainingOnlyDigits(string);
147                 bool isNumeric1(string);
148         bool isLabelEquivalent(string, string);
149         string getSimpleLabel(string);
150         string findEdianness();
151         
152                 
153                 //string manipulation
154                 void splitAtEquals(string&, string&);
155                 void splitAtComma(string&, string&);    
156                 void splitAtComma(string&, vector<string>&);
157                 void splitAtDash(string&, set<int>&);
158                 void splitAtDash(string&, set<string>&);
159                 void splitAtDash(string&, vector<string>&);
160                 void splitAtChar(string&, vector<string>&, char);
161         void splitAtChar(string&, string&, char);
162         vector<string> splitWhiteSpaceWithQuotes(string);
163                 int removeConfidences(string&);
164         string removeQuotes(string);
165         string makeList(vector<string>&);
166         bool isSubset(vector<string>, vector<string>); //bigSet, subset
167         int checkName(string&);
168         map<string, vector<string> > parseClasses(string);
169                 
170                 //math operation
171         double max(vector<double>&); //returns largest value in vector
172         double min(vector<double>&); //returns smallest value in vector
173                 int factorial(int num);
174                 vector<vector<double> > binomial(int);
175                 float ceilDist(float, int);
176                 float roundDist(float, int);
177                 unsigned int fromBase36(string);
178         double median(vector<double>);
179                 int getRandomIndex(int); //highest
180         double getStandardDeviation(vector<int>&);
181         vector<double> getStandardDeviation(vector< vector<double> >&);
182         vector<double> getStandardDeviation(vector< vector<double> >&, vector<double>&);
183         vector<double> getAverages(vector< vector<double> >&);
184         double getAverage(vector<double>);
185         vector< vector<seqDist> > getStandardDeviation(vector< vector< vector<seqDist> > >&);
186         vector< vector<seqDist> > getStandardDeviation(vector< vector< vector<seqDist> > >&, vector< vector<seqDist> >&);
187         vector< vector<seqDist> > getAverages(vector< vector< vector<seqDist> > >&, string);
188         vector< vector<seqDist> > getAverages(vector< vector< vector<seqDist> > >&);
189
190                 int control_pressed;
191                 bool executing, runParse, jumble, gui, mothurCalling, debug;
192                 
193                 //current files - if you add a new type you must edit optionParser->getParameters, get.current and set.current commands and mothurOut->printCurrentFiles/clearCurrentFiles/getCurrentTypes. add a get and set function.
194                 string getPhylipFile()          { return phylipfile;            }
195                 string getColumnFile()          { return columnfile;            }
196                 string getListFile()            { return listfile;                      }
197                 string getRabundFile()          { return rabundfile;            }
198                 string getSabundFile()          { return sabundfile;            }
199                 string getNameFile()            { return namefile;                      }       
200                 string getGroupFile()           { return groupfile;                     }       
201                 string getOrderFile()           { return orderfile;                     }
202                 string getOrderGroupFile()      { return ordergroupfile;        }
203                 string getTreeFile()            { return treefile;                      }
204                 string getSharedFile()          { return sharedfile;            }
205                 string getRelAbundFile()        { return relabundfile;          }
206                 string getDesignFile()          { return designfile;            }
207                 string getFastaFile()           { return fastafile;                     }
208                 string getSFFFile()                     { return sfffile;                       }
209                 string getQualFile()            { return qualfile;                      }
210                 string getOligosFile()          { return oligosfile;            }
211                 string getAccnosFile()          { return accnosfile;            }
212                 string getTaxonomyFile()        { return taxonomyfile;          }
213                 string getFlowFile()            { return flowfile;                      }
214         string getBiomFile()            { return biomfile;                      }
215         string getCountTableFile()      { return counttablefile;        }
216         string getSummaryFile()     { return summaryfile;       }
217                 string getProcessors()          { return processors;            }
218                 
219                 void setListFile(string f)                      { listfile = getFullPathName(f);                        }
220                 void setTreeFile(string f)                      { treefile = getFullPathName(f);                        }
221                 void setGroupFile(string f)                     { groupfile = getFullPathName(f);       groupMode = "group";            }               
222                 void setPhylipFile(string f)            { phylipfile = getFullPathName(f);                      }
223                 void setColumnFile(string f)            { columnfile = getFullPathName(f);                      }
224                 void setNameFile(string f)                      { namefile = getFullPathName(f);                        }       
225                 void setRabundFile(string f)            { rabundfile = getFullPathName(f);                      }
226                 void setSabundFile(string f)            { sabundfile = getFullPathName(f);                      }
227                 void setSharedFile(string f)            { sharedfile = getFullPathName(f);                      }
228                 void setRelAbundFile(string f)          { relabundfile = getFullPathName(f);            }
229                 void setOrderFile(string f)                     { orderfile = getFullPathName(f);                       }
230                 void setOrderGroupFile(string f)        { ordergroupfile = getFullPathName(f);          }
231                 void setDesignFile(string f)            { designfile = getFullPathName(f);                      }
232                 void setFastaFile(string f)                     { fastafile = getFullPathName(f);                       }
233                 void setSFFFile(string f)                       { sfffile = getFullPathName(f);                         }
234                 void setQualFile(string f)                      { qualfile = getFullPathName(f);                        }
235                 void setOligosFile(string f)            { oligosfile = getFullPathName(f);                      }
236                 void setAccnosFile(string f)            { accnosfile = getFullPathName(f);                      }
237                 void setTaxonomyFile(string f)          { taxonomyfile = getFullPathName(f);            }
238                 void setFlowFile(string f)                      { flowfile = getFullPathName(f);                        }
239         void setBiomFile(string f)                      { biomfile = getFullPathName(f);                        }
240         void setSummaryFile(string f)           { summaryfile = getFullPathName(f);                     }
241         void setCountTableFile(string f)        { counttablefile = getFullPathName(f);  groupMode = "count";    }
242         void setProcessors(string p)            { processors = p; mothurOut("\nUsing " + toString(p) + " processors.\n");       }
243                 
244                 void printCurrentFiles();
245                 bool hasCurrentFiles();
246                 void clearCurrentFiles();
247         set<string> getCurrentTypes(); 
248                 
249         private:
250                 static MothurOut* _uniqueInstance;
251                 MothurOut( const MothurOut& ); // Disable copy constructor
252                 void operator=( const MothurOut& ); // Disable assignment operator
253                 MothurOut() { 
254                         control_pressed = false; defaultPath=""; 
255                         phylipfile = "";
256                         columnfile = "";
257                         listfile = "";
258                         rabundfile = "";
259                         sabundfile = "";
260                         namefile = "";
261                         groupfile = "";
262                         designfile = "";
263                         orderfile = "";
264                         treefile = "";
265                         sharedfile = "";
266                         ordergroupfile = "";
267                         relabundfile = "";
268                         fastafile = "";
269                         qualfile = "";
270                         sfffile = "";
271                         oligosfile = "";
272                         accnosfile = "";
273                         taxonomyfile = "";
274                         processors = "1";
275                         flowfile = "";
276             biomfile = "";
277             counttablefile = "";
278             summaryfile = "";
279                         gui = false;
280                         printedSharedHeaders = false;
281             printedListHeaders = false;
282                         commandInputsConvertError = false;
283             mothurCalling = false;
284             debug = false;
285                         sharedHeaderMode = "";
286             groupMode = "group";
287             changedSeqNames = false;
288             modifyNames = true;
289                 }
290                 ~MothurOut();
291
292                 string logFileName;
293                 string defaultPath, outputDir;
294                 string releaseDate, version;
295         
296                 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile, biomfile;
297                 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile, counttablefile, summaryfile;
298
299                 vector<string> Groups;
300                 vector<string> namesOfGroups;
301                 ofstream out;
302                 
303                 int mem_usage(double&, double&);
304
305 };
306 /***********************************************/
307
308 #endif
309