]> git.donarmstrong.com Git - mothur.git/blob - mothurout.h
Merge remote-tracking branch 'origin/master'
[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                 //map<string, string> names;
70                 vector<string> sharedBinLabelsInFile;
71                 vector<string> currentSharedBinLabels;
72         vector<string> listBinLabelsInFile;
73         //vector<string> currentListBinLabels;
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 appendFilesWithoutHeaders(string, string);
88                 int renameFile(string, string); //oldname, newname
89                 string getFullPathName(string);
90         string findProgramPath(string programName);
91                 string hasPath(string);
92                 string getExtension(string);
93                 string getPathName(string);
94                 string getSimpleName(string);
95                 string getRootName(string);
96                 bool isBlank(string);
97                 int openOutputFile(string, ofstream&);
98         int openOutputFileBinary(string, ofstream&);
99                 int openOutputFileAppend(string, ofstream&);
100         int openOutputFileBinaryAppend(string, ofstream&);
101                 int openInputFile(string, ifstream&);
102                 int openInputFile(string, ifstream&, string); //no error given
103     
104         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
105                 string getline(ifstream&);
106                 string getline(istringstream&);
107                 void gobble(istream&);
108                 void gobble(istringstream&);
109         vector<string> splitWhiteSpace(string& rest, char[], int);
110         vector<string> splitWhiteSpace(string);
111         set<string> readAccnos(string);
112         int readAccnos(string, vector<string>&);
113         map<string, int> readNames(string);
114         map<string, int> readNames(string, unsigned long int&);
115         int readTax(string, map<string, string>&);
116         vector<consTax> readConsTax(string);
117         int readConsTax(string, map<string, consTax2>&);
118         int readNames(string, map<string, string>&, map<string, int>&);
119                 int readNames(string, map<string, string>&);
120         int readNames(string, map<string, string>&, bool);
121         int readNames(string, map<string, string>&, int);
122                 int readNames(string, map<string, vector<string> >&);
123                 int readNames(string, vector<seqPriorityNode>&, map<string, string>&);
124                 int mothurRemove(string);
125                 bool mothurConvert(string, int&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
126         bool mothurConvert(string, intDist&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
127                 bool mothurConvert(string, float&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
128                 bool mothurConvert(string, double&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
129         
130                 
131                 //searchs and checks
132                 bool checkReleaseVersion(ifstream&, string);
133                 bool anyLabelsToProcess(string, set<string>&, string);
134                 bool inUsersGroups(vector<string>, vector<string>);
135         bool inUsersGroups(vector<int>, vector< vector<int> >);
136                 bool inUsersGroups(string, vector<string>);
137         bool inUsersGroups(int, vector<int>);
138                 void getNumSeqs(ifstream&, int&);
139                 int getNumSeqs(ifstream&);
140                 int getNumNames(string);
141                 int getNumChar(string, char);
142                 bool isTrue(string);
143                 bool isContainingOnlyDigits(string);
144                 bool isNumeric1(string);
145         bool isLabelEquivalent(string, string);
146         string getSimpleLabel(string);
147         string findEdianness();
148         
149                 
150                 //string manipulation
151                 void splitAtEquals(string&, string&);
152                 void splitAtComma(string&, string&);    
153                 void splitAtComma(string&, vector<string>&);
154                 void splitAtDash(string&, set<int>&);
155                 void splitAtDash(string&, set<string>&);
156                 void splitAtDash(string&, vector<string>&);
157                 void splitAtChar(string&, vector<string>&, char);
158         void splitAtChar(string&, string&, char);
159         vector<string> splitWhiteSpaceWithQuotes(string);
160                 int removeConfidences(string&);
161         string removeQuotes(string);
162         string makeList(vector<string>&);
163         bool isSubset(vector<string>, vector<string>); //bigSet, subset
164         int checkName(string&);
165         map<string, vector<string> > parseClasses(string);
166                 
167                 //math operation
168         double max(vector<double>&); //returns largest value in vector
169         double min(vector<double>&); //returns smallest value in vector
170                 int factorial(int num);
171                 vector<vector<double> > binomial(int);
172                 float ceilDist(float, int);
173                 float roundDist(float, int);
174                 unsigned int fromBase36(string);
175         double median(vector<double>);
176                 int getRandomIndex(int); //highest
177         double getStandardDeviation(vector<int>&);
178         vector<double> getStandardDeviation(vector< vector<double> >&);
179         vector<double> getStandardDeviation(vector< vector<double> >&, vector<double>&);
180         vector<double> getAverages(vector< vector<double> >&);
181         double getAverage(vector<double>);
182         vector< vector<seqDist> > getStandardDeviation(vector< vector< vector<seqDist> > >&);
183         vector< vector<seqDist> > getStandardDeviation(vector< vector< vector<seqDist> > >&, vector< vector<seqDist> >&);
184         vector< vector<seqDist> > getAverages(vector< vector< vector<seqDist> > >&, string);
185         vector< vector<seqDist> > getAverages(vector< vector< vector<seqDist> > >&);
186
187                 int control_pressed;
188                 bool executing, runParse, jumble, gui, mothurCalling, debug;
189                 
190                 //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.
191                 string getPhylipFile()          { return phylipfile;            }
192                 string getColumnFile()          { return columnfile;            }
193                 string getListFile()            { return listfile;                      }
194                 string getRabundFile()          { return rabundfile;            }
195                 string getSabundFile()          { return sabundfile;            }
196                 string getNameFile()            { return namefile;                      }       
197                 string getGroupFile()           { return groupfile;                     }       
198                 string getOrderFile()           { return orderfile;                     }
199                 string getOrderGroupFile()      { return ordergroupfile;        }
200                 string getTreeFile()            { return treefile;                      }
201                 string getSharedFile()          { return sharedfile;            }
202                 string getRelAbundFile()        { return relabundfile;          }
203                 string getDesignFile()          { return designfile;            }
204                 string getFastaFile()           { return fastafile;                     }
205                 string getSFFFile()                     { return sfffile;                       }
206                 string getQualFile()            { return qualfile;                      }
207                 string getOligosFile()          { return oligosfile;            }
208                 string getAccnosFile()          { return accnosfile;            }
209                 string getTaxonomyFile()        { return taxonomyfile;          }
210                 string getFlowFile()            { return flowfile;                      }
211         string getBiomFile()            { return biomfile;                      }
212         string getCountTableFile()      { return counttablefile;        }
213         string getSummaryFile()     { return summaryfile;       }
214                 string getProcessors()          { return processors;            }
215                 
216                 void setListFile(string f)                      { listfile = getFullPathName(f);                        }
217                 void setTreeFile(string f)                      { treefile = getFullPathName(f);                        }
218                 void setGroupFile(string f)                     { groupfile = getFullPathName(f);       groupMode = "group";            }               
219                 void setPhylipFile(string f)            { phylipfile = getFullPathName(f);                      }
220                 void setColumnFile(string f)            { columnfile = getFullPathName(f);                      }
221                 void setNameFile(string f)                      { namefile = getFullPathName(f);                        }       
222                 void setRabundFile(string f)            { rabundfile = getFullPathName(f);                      }
223                 void setSabundFile(string f)            { sabundfile = getFullPathName(f);                      }
224                 void setSharedFile(string f)            { sharedfile = getFullPathName(f);                      }
225                 void setRelAbundFile(string f)          { relabundfile = getFullPathName(f);            }
226                 void setOrderFile(string f)                     { orderfile = getFullPathName(f);                       }
227                 void setOrderGroupFile(string f)        { ordergroupfile = getFullPathName(f);          }
228                 void setDesignFile(string f)            { designfile = getFullPathName(f);                      }
229                 void setFastaFile(string f)                     { fastafile = getFullPathName(f);                       }
230                 void setSFFFile(string f)                       { sfffile = getFullPathName(f);                         }
231                 void setQualFile(string f)                      { qualfile = getFullPathName(f);                        }
232                 void setOligosFile(string f)            { oligosfile = getFullPathName(f);                      }
233                 void setAccnosFile(string f)            { accnosfile = getFullPathName(f);                      }
234                 void setTaxonomyFile(string f)          { taxonomyfile = getFullPathName(f);            }
235                 void setFlowFile(string f)                      { flowfile = getFullPathName(f);                        }
236         void setBiomFile(string f)                      { biomfile = getFullPathName(f);                        }
237         void setSummaryFile(string f)           { summaryfile = getFullPathName(f);                     }
238         void setCountTableFile(string f)        { counttablefile = getFullPathName(f);  groupMode = "count";    }
239         void setProcessors(string p)            { processors = p; mothurOut("\nUsing " + toString(p) + " processors.\n");       }
240                 
241                 void printCurrentFiles();
242                 bool hasCurrentFiles();
243                 void clearCurrentFiles();
244         set<string> getCurrentTypes(); 
245                 
246         private:
247                 static MothurOut* _uniqueInstance;
248                 MothurOut( const MothurOut& ); // Disable copy constructor
249                 void operator=( const MothurOut& ); // Disable assignment operator
250                 MothurOut() { 
251                         control_pressed = false; defaultPath=""; 
252                         phylipfile = "";
253                         columnfile = "";
254                         listfile = "";
255                         rabundfile = "";
256                         sabundfile = "";
257                         namefile = "";
258                         groupfile = "";
259                         designfile = "";
260                         orderfile = "";
261                         treefile = "";
262                         sharedfile = "";
263                         ordergroupfile = "";
264                         relabundfile = "";
265                         fastafile = "";
266                         qualfile = "";
267                         sfffile = "";
268                         oligosfile = "";
269                         accnosfile = "";
270                         taxonomyfile = "";
271                         processors = "1";
272                         flowfile = "";
273             biomfile = "";
274             counttablefile = "";
275             summaryfile = "";
276                         gui = false;
277                         printedSharedHeaders = false;
278             printedListHeaders = false;
279                         commandInputsConvertError = false;
280             mothurCalling = false;
281             debug = false;
282                         sharedHeaderMode = "";
283             groupMode = "group";
284             changedSeqNames = false;
285             modifyNames = true;
286                 }
287                 ~MothurOut();
288
289                 string logFileName;
290                 string defaultPath, outputDir;
291                 string releaseDate, version;
292         
293                 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile, biomfile;
294                 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile, counttablefile, summaryfile;
295
296                 vector<string> Groups;
297                 vector<string> namesOfGroups;
298                 ofstream out;
299                 
300                 int mem_usage(double&, double&);
301
302 };
303 /***********************************************/
304
305 #endif
306