]> 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 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(vector<int>, vector< vector<int> >);
124                 bool inUsersGroups(string, vector<string>);
125         bool inUsersGroups(int, vector<int>);
126                 void getNumSeqs(ifstream&, int&);
127                 int getNumSeqs(ifstream&);
128                 int getNumNames(string);
129                 int getNumChar(string, char);
130                 bool isTrue(string);
131                 bool isContainingOnlyDigits(string);
132                 bool isNumeric1(string);
133         
134                 
135                 //string manipulation
136                 void splitAtEquals(string&, string&);
137                 void splitAtComma(string&, string&);    
138                 void splitAtComma(string&, vector<string>&);
139                 void splitAtDash(string&, set<int>&);
140                 void splitAtDash(string&, set<string>&);
141                 void splitAtDash(string&, vector<string>&);
142                 void splitAtChar(string&, vector<string>&, char);
143         void splitAtChar(string&, string&, char);
144         vector<string> splitWhiteSpaceWithQuotes(string);
145                 int removeConfidences(string&);
146         string removeQuotes(string);
147         string makeList(vector<string>&);
148         bool isSubset(vector<string>, vector<string>); //bigSet, subset
149                 
150                 //math operation
151                 int factorial(int num);
152                 vector<vector<double> > binomial(int);
153                 float ceilDist(float, int);
154                 float roundDist(float, int);
155                 unsigned int fromBase36(string);
156                 int getRandomIndex(int); //highest
157         double getStandardDeviation(vector<int>&);
158
159                 int control_pressed;
160                 bool executing, runParse, jumble, gui, mothurCalling, debug;
161                 
162                 //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles/getCurrentTypes.
163                 string getPhylipFile()          { return phylipfile;            }
164                 string getColumnFile()          { return columnfile;            }
165                 string getListFile()            { return listfile;                      }
166                 string getRabundFile()          { return rabundfile;            }
167                 string getSabundFile()          { return sabundfile;            }
168                 string getNameFile()            { return namefile;                      }       
169                 string getGroupFile()           { return groupfile;                     }       
170                 string getOrderFile()           { return orderfile;                     }
171                 string getOrderGroupFile()      { return ordergroupfile;        }
172                 string getTreeFile()            { return treefile;                      }
173                 string getSharedFile()          { return sharedfile;            }
174                 string getRelAbundFile()        { return relabundfile;          }
175                 string getDesignFile()          { return designfile;            }
176                 string getFastaFile()           { return fastafile;                     }
177                 string getSFFFile()                     { return sfffile;                       }
178                 string getQualFile()            { return qualfile;                      }
179                 string getOligosFile()          { return oligosfile;            }
180                 string getAccnosFile()          { return accnosfile;            }
181                 string getTaxonomyFile()        { return taxonomyfile;          }
182                 string getFlowFile()            { return flowfile;                      }
183         string getBiomFile()            { return biomfile;                      }
184         string getCountTableFile()      { return counttablefile;        }
185                 string getProcessors()          { return processors;            }
186                 
187                 void setListFile(string f)                      { listfile = getFullPathName(f);                        }
188                 void setTreeFile(string f)                      { treefile = getFullPathName(f);                        }
189                 void setGroupFile(string f)                     { groupfile = getFullPathName(f);       groupMode = "group";            }               
190                 void setPhylipFile(string f)            { phylipfile = getFullPathName(f);                      }
191                 void setColumnFile(string f)            { columnfile = getFullPathName(f);                      }
192                 void setNameFile(string f)                      { namefile = getFullPathName(f);                        }       
193                 void setRabundFile(string f)            { rabundfile = getFullPathName(f);                      }
194                 void setSabundFile(string f)            { sabundfile = getFullPathName(f);                      }
195                 void setSharedFile(string f)            { sharedfile = getFullPathName(f);                      }
196                 void setRelAbundFile(string f)          { relabundfile = getFullPathName(f);            }
197                 void setOrderFile(string f)                     { orderfile = getFullPathName(f);                       }
198                 void setOrderGroupFile(string f)        { ordergroupfile = getFullPathName(f);          }
199                 void setDesignFile(string f)            { designfile = getFullPathName(f);                      }
200                 void setFastaFile(string f)                     { fastafile = getFullPathName(f);                       }
201                 void setSFFFile(string f)                       { sfffile = getFullPathName(f);                         }
202                 void setQualFile(string f)                      { qualfile = getFullPathName(f);                        }
203                 void setOligosFile(string f)            { oligosfile = getFullPathName(f);                      }
204                 void setAccnosFile(string f)            { accnosfile = getFullPathName(f);                      }
205                 void setTaxonomyFile(string f)          { taxonomyfile = getFullPathName(f);            }
206                 void setFlowFile(string f)                      { flowfile = getFullPathName(f);                        }
207         void setBiomFile(string f)                      { biomfile = getFullPathName(f);                        }
208         void setCountTableFile(string f)        { counttablefile = getFullPathName(f);  groupMode = "count";    }
209         void setProcessors(string p)            { processors = p; mothurOut("\nUsing " + toString(p) + " processors.\n");       }
210                 
211                 void printCurrentFiles();
212                 bool hasCurrentFiles();
213                 void clearCurrentFiles();
214         set<string> getCurrentTypes(); 
215                 
216         private:
217                 static MothurOut* _uniqueInstance;
218                 MothurOut( const MothurOut& ); // Disable copy constructor
219                 void operator=( const MothurOut& ); // Disable assignment operator
220                 MothurOut() { 
221                         control_pressed = false; defaultPath=""; 
222                         phylipfile = "";
223                         columnfile = "";
224                         listfile = "";
225                         rabundfile = "";
226                         sabundfile = "";
227                         namefile = "";
228                         groupfile = "";
229                         designfile = "";
230                         orderfile = "";
231                         treefile = "";
232                         sharedfile = "";
233                         ordergroupfile = "";
234                         relabundfile = "";
235                         fastafile = "";
236                         qualfile = "";
237                         sfffile = "";
238                         oligosfile = "";
239                         accnosfile = "";
240                         taxonomyfile = "";
241                         processors = "1";
242                         flowfile = "";
243             biomfile = "";
244             counttablefile = "";
245                         gui = false;
246                         printedHeaders = false;
247                         commandInputsConvertError = false;
248             mothurCalling = false;
249             debug = false;
250                         sharedHeaderMode = "";
251             groupMode = "group";
252                 }
253                 ~MothurOut();
254
255                 string logFileName;
256                 string defaultPath, outputDir;
257                 string releaseDate, version;
258         
259                 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile, biomfile;
260                 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile, counttablefile;
261
262                 vector<string> Groups;
263                 vector<string> namesOfGroups;
264                 ofstream out;
265                 
266                 int mem_usage(double&, double&);
267
268 };
269 /***********************************************/
270
271 #endif
272