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