]> git.donarmstrong.com Git - mothur.git/blob - mothurout.h
a57fb136ba3d41b210e671e2fe85848a4d40f359
[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 mothurOutEndLine(); //writes to cout and the logfile
41                 void mothurOut(string, ofstream&); //writes to the ofstream, cout and the logfile
42                 void mothurOutEndLine(ofstream&); //writes to the ofstream, cout and the logfile
43         void mothurOutJustToScreen(string); //writes to cout
44                 void mothurOutJustToLog(string);
45                 void errorOut(exception&, string, string);
46                 void closeLog();
47                 string getDefaultPath() { return defaultPath; }
48                 void setDefaultPath(string);
49                 string getOutputDir() { return outputDir; }
50                 void setOutputDir(string);
51                 
52                 string getReleaseDate() { return releaseDate; }
53                 void setReleaseDate(string r) { releaseDate = r; }
54                 string getVersion() { return version; }
55                 void setVersion(string r) { version = r; }
56         
57                 void addGroup(string g) { Groups.push_back(g); }
58                 void setGroups(vector<string>& g) { sort(g.begin(), g.end()); Groups = g; }
59                 void clearGroups() { Groups.clear(); }
60             int getNumGroups() { return Groups.size(); }
61                 vector<string> getGroups() { sort(Groups.begin(), Groups.end()); return Groups; }
62                 void addAllGroup(string g) { namesOfGroups.push_back(g); }
63                 void setAllGroups(vector<string>& g) { sort(g.begin(), g.end()); namesOfGroups = g; }
64                 void clearAllGroups() { namesOfGroups.clear(); }
65                 int getNumAllGroups() { return namesOfGroups.size(); }
66         
67                 vector<string> getAllGroups() { sort(namesOfGroups.begin(), namesOfGroups.end()); return namesOfGroups; }
68                 vector<string> Treenames;
69                 vector<string> sharedBinLabelsInFile;
70                 vector<string> currentSharedBinLabels;
71         vector<string> listBinLabelsInFile;
72                 string saveNextLabel, argv, sharedHeaderMode, groupMode;
73                 bool printedSharedHeaders, printedListHeaders, commandInputsConvertError, changedSeqNames, modifyNames;
74                 
75                 //functions from mothur.h
76                 //file operations
77         bool dirCheck(string&); //completes path, appends appropriate / or \, makes sure dir is writable.
78                 vector<unsigned long long> divideFile(string, int&); //divides splitting unevenness by sequence
79         vector<unsigned long long> divideFilePerLine(string, int&); //divides splitting unevenness at line breaks
80                 int divideFile(string, int&, vector<string>&);
81                 vector<unsigned long long> setFilePosEachLine(string, int&);
82                 vector<unsigned long long> setFilePosFasta(string, int&);
83                 string sortFile(string, string);
84                 int appendFiles(string, string);
85         int appendBinaryFiles(string, string);
86         int appendFilesWithoutHeaders(string, string);
87                 int renameFile(string, string); //oldname, newname
88                 string getFullPathName(string);
89         string findProgramPath(string programName);
90                 string hasPath(string);
91                 string getExtension(string);
92                 string getPathName(string);
93                 string getSimpleName(string);
94                 string getRootName(string);
95                 bool isBlank(string);
96                 int openOutputFile(string, ofstream&);
97         int openOutputFileBinary(string, ofstream&);
98                 int openOutputFileAppend(string, ofstream&);
99         int openOutputFileBinaryAppend(string, ofstream&);
100                 int openInputFile(string, ifstream&);
101         int openInputFileBinary(string, ifstream&);
102         int openInputFileBinary(string, ifstream&, string);
103                 int openInputFile(string, ifstream&, string); //no error given
104     
105         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
106                 string getline(ifstream&);
107                 string getline(istringstream&);
108                 void gobble(istream&);
109                 void gobble(istringstream&);
110         vector<string> splitWhiteSpace(string& rest, char[], int);
111         vector<string> splitWhiteSpace(string);
112         set<string> readAccnos(string);
113         int readAccnos(string, vector<string>&);
114         map<string, int> readNames(string);
115         map<string, int> readNames(string, unsigned long int&);
116         int readTax(string, map<string, string>&);
117         vector<consTax> readConsTax(string);
118         int readConsTax(string, map<string, consTax2>&);
119         int readNames(string, map<string, string>&, map<string, int>&);
120                 int readNames(string, map<string, string>&);
121         int readNames(string, map<string, string>&, bool);
122         int readNames(string, map<string, string>&, int);
123                 int readNames(string, map<string, vector<string> >&);
124                 int readNames(string, vector<seqPriorityNode>&, map<string, string>&);
125                 int mothurRemove(string);
126                 bool mothurConvert(string, int&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
127         bool mothurConvert(string, intDist&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
128                 bool mothurConvert(string, float&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
129                 bool mothurConvert(string, double&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
130         
131                 
132                 //searchs and checks
133                 bool checkReleaseVersion(ifstream&, string);
134                 bool anyLabelsToProcess(string, set<string>&, string);
135                 bool inUsersGroups(vector<string>, vector<string>); //returns true if any of the strings in first vector are in second vector
136         bool inUsersGroups(vector<int>, vector< vector<int> >);
137                 bool inUsersGroups(string, vector<string>);
138         bool inUsersGroups(int, vector<int>);
139                 void getNumSeqs(ifstream&, int&);
140                 int getNumSeqs(ifstream&);
141                 int getNumNames(string);
142                 int getNumChar(string, char);
143                 bool isTrue(string);
144                 bool isContainingOnlyDigits(string);
145                 bool isNumeric1(string);
146         bool isLabelEquivalent(string, string);
147         string getSimpleLabel(string);
148         string findEdianness();
149         string mothurGetpid(int);
150         
151                 
152                 //string manipulation
153                 void splitAtEquals(string&, string&);
154                 void splitAtComma(string&, string&);    
155                 void splitAtComma(string&, vector<string>&);
156                 void splitAtDash(string&, set<int>&);
157                 void splitAtDash(string&, set<string>&);
158                 void splitAtDash(string&, vector<string>&);
159                 void splitAtChar(string&, vector<string>&, char);
160         void splitAtChar(string&, string&, char);
161         int removeBlanks(vector<string>&);
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