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