]> git.donarmstrong.com Git - mothur.git/blob - mothurout.h
added code to check path for uchime and catchall executables
[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;
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                 map<string, int> readNames(string);
101                 int readNames(string, map<string, string>&);
102                 int readNames(string, map<string, vector<string> >&);
103                 int readNames(string, vector<seqPriorityNode>&, map<string, string>&);
104                 int mothurRemove(string);
105                 bool mothurConvert(string, int&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
106                 bool mothurConvert(string, float&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
107                 bool mothurConvert(string, double&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
108         
109                 
110                 //searchs and checks
111                 bool checkReleaseVersion(ifstream&, string);
112                 bool anyLabelsToProcess(string, set<string>&, string);
113                 bool inUsersGroups(vector<string>, vector<string>);
114                 bool inUsersGroups(string, vector<string>);
115                 void getNumSeqs(ifstream&, int&);
116                 int getNumSeqs(ifstream&);
117                 int getNumNames(string);
118                 int getNumChar(string, char);
119                 bool isTrue(string);
120                 bool isContainingOnlyDigits(string);
121                 bool isNumeric1(string);
122         
123                 
124                 //string manipulation
125                 void splitAtEquals(string&, string&);
126                 void splitAtComma(string&, string&);    
127                 void splitAtComma(string&, vector<string>&);
128                 void splitAtDash(string&, set<int>&);
129                 void splitAtDash(string&, set<string>&);
130                 void splitAtDash(string&, vector<string>&);
131                 void splitAtChar(string&, vector<string>&, char);
132         void splitAtChar(string&, string&, char);
133                 int removeConfidences(string&);
134         string makeList(vector<string>&);
135                 
136                 //math operation
137                 int factorial(int num);
138                 vector<vector<double> > binomial(int);
139                 float ceilDist(float, int);
140                 float roundDist(float, int);
141                 unsigned int fromBase36(string);
142                 int getRandomIndex(int); //highest
143
144                 int control_pressed;
145                 bool executing, runParse, jumble, gui, mothurCalling, debug;
146                 
147                 //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles.
148                 string getPhylipFile()          { return phylipfile;            }
149                 string getColumnFile()          { return columnfile;            }
150                 string getListFile()            { return listfile;                      }
151                 string getRabundFile()          { return rabundfile;            }
152                 string getSabundFile()          { return sabundfile;            }
153                 string getNameFile()            { return namefile;                      }       
154                 string getGroupFile()           { return groupfile;                     }       
155                 string getOrderFile()           { return orderfile;                     }
156                 string getOrderGroupFile()      { return ordergroupfile;        }
157                 string getTreeFile()            { return treefile;                      }
158                 string getSharedFile()          { return sharedfile;            }
159                 string getRelAbundFile()        { return relabundfile;          }
160                 string getDesignFile()          { return designfile;            }
161                 string getFastaFile()           { return fastafile;                     }
162                 string getSFFFile()                     { return sfffile;                       }
163                 string getQualFile()            { return qualfile;                      }
164                 string getOligosFile()          { return oligosfile;            }
165                 string getAccnosFile()          { return accnosfile;            }
166                 string getTaxonomyFile()        { return taxonomyfile;          }
167                 string getFlowFile()            { return flowfile;                      }
168         string getBiomFile()            { return biomfile;                      }
169                 string getProcessors()          { return processors;            }
170                 
171                 void setListFile(string f)                      { listfile = getFullPathName(f);                        }
172                 void setTreeFile(string f)                      { treefile = getFullPathName(f);                        }
173                 void setGroupFile(string f)                     { groupfile = getFullPathName(f);                       }               
174                 void setPhylipFile(string f)            { phylipfile = getFullPathName(f);                      }
175                 void setColumnFile(string f)            { columnfile = getFullPathName(f);                      }
176                 void setNameFile(string f)                      { namefile = getFullPathName(f);                        }       
177                 void setRabundFile(string f)            { rabundfile = getFullPathName(f);                      }
178                 void setSabundFile(string f)            { sabundfile = getFullPathName(f);                      }
179                 void setSharedFile(string f)            { sharedfile = getFullPathName(f);                      }
180                 void setRelAbundFile(string f)          { relabundfile = getFullPathName(f);            }
181                 void setOrderFile(string f)                     { orderfile = getFullPathName(f);                       }
182                 void setOrderGroupFile(string f)        { ordergroupfile = getFullPathName(f);          }
183                 void setDesignFile(string f)            { designfile = getFullPathName(f);                      }
184                 void setFastaFile(string f)                     { fastafile = getFullPathName(f);                       }
185                 void setSFFFile(string f)                       { sfffile = getFullPathName(f);                         }
186                 void setQualFile(string f)                      { qualfile = getFullPathName(f);                        }
187                 void setOligosFile(string f)            { oligosfile = getFullPathName(f);                      }
188                 void setAccnosFile(string f)            { accnosfile = getFullPathName(f);                      }
189                 void setTaxonomyFile(string f)          { taxonomyfile = getFullPathName(f);            }
190                 void setFlowFile(string f)                      { flowfile = getFullPathName(f);                        }
191         void setBiomFile(string f)                      { biomfile = getFullPathName(f);                        }
192                 void setProcessors(string p)            { processors = p;                                                       }
193                 
194                 void printCurrentFiles();
195                 bool hasCurrentFiles();
196                 void clearCurrentFiles();
197                 
198         private:
199                 static MothurOut* _uniqueInstance;
200                 MothurOut( const MothurOut& ); // Disable copy constructor
201                 void operator=( const MothurOut& ); // Disable assignment operator
202                 MothurOut() { 
203                         control_pressed = false; defaultPath=""; 
204                         phylipfile = "";
205                         columnfile = "";
206                         listfile = "";
207                         rabundfile = "";
208                         sabundfile = "";
209                         namefile = "";
210                         groupfile = "";
211                         designfile = "";
212                         orderfile = "";
213                         treefile = "";
214                         sharedfile = "";
215                         ordergroupfile = "";
216                         relabundfile = "";
217                         fastafile = "";
218                         qualfile = "";
219                         sfffile = "";
220                         oligosfile = "";
221                         accnosfile = "";
222                         taxonomyfile = "";
223                         processors = "1";
224                         flowfile = "";
225             biomfile = "";
226                         gui = false;
227                         printedHeaders = false;
228                         commandInputsConvertError = false;
229             mothurCalling = false;
230             debug = false;
231                         sharedHeaderMode = "";
232                 }
233                 ~MothurOut();
234
235                 string logFileName;
236                 string defaultPath, outputDir;
237                 string releaseDate, version;
238         
239                 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile, biomfile;
240                 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile;
241
242                 vector<string> Groups;
243                 vector<string> namesOfGroups;
244                 ofstream out;
245                 
246                 int mem_usage(double&, double&);
247
248 };
249 /***********************************************/
250
251 #endif
252