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