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