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