]> git.donarmstrong.com Git - mothur.git/blob - mothurout.h
adding labels to list file.
[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 mothurOutJustToScreen(string); //writes to cout
44                 void mothurOutJustToLog(string);
45                 void errorOut(exception&, string, string);
46                 void closeLog();
47                 string getDefaultPath() { return defaultPath; }
48                 void setDefaultPath(string);
49                 string getOutputDir() { return outputDir; }
50                 void setOutputDir(string);
51                 
52                 string getReleaseDate() { return releaseDate; }
53                 void setReleaseDate(string r) { releaseDate = r; }
54                 string getVersion() { return version; }
55                 void setVersion(string r) { version = r; }
56         
57                 void addGroup(string g) { Groups.push_back(g); }
58                 void setGroups(vector<string>& g) { sort(g.begin(), g.end()); Groups = g; }
59                 void clearGroups() { Groups.clear(); }
60             int getNumGroups() { return Groups.size(); }
61                 vector<string> getGroups() { sort(Groups.begin(), Groups.end()); return Groups; }
62                 void addAllGroup(string g) { namesOfGroups.push_back(g); }
63                 void setAllGroups(vector<string>& g) { sort(g.begin(), g.end()); namesOfGroups = g; }
64                 void clearAllGroups() { namesOfGroups.clear(); }
65                 int getNumAllGroups() { return namesOfGroups.size(); }
66         
67                 vector<string> getAllGroups() { sort(namesOfGroups.begin(), namesOfGroups.end()); return namesOfGroups; }
68                 vector<string> Treenames;
69                 //map<string, string> names;
70                 vector<string> sharedBinLabelsInFile;
71                 vector<string> currentSharedBinLabels;
72         vector<string> listBinLabelsInFile;
73         //vector<string> currentListBinLabels;
74                 string saveNextLabel, argv, sharedHeaderMode, groupMode;
75                 bool printedSharedHeaders, printedListHeaders, commandInputsConvertError, changedSeqNames, modifyNames;
76                 
77                 //functions from mothur.h
78                 //file operations
79         bool dirCheck(string&); //completes path, appends appropriate / or \, makes sure dir is writable.
80                 vector<unsigned long long> divideFile(string, int&); //divides splitting unevenness by sequence
81         vector<unsigned long long> divideFilePerLine(string, int&); //divides splitting unevenness at line breaks
82                 int divideFile(string, int&, vector<string>&);
83                 vector<unsigned long long> setFilePosEachLine(string, int&);
84                 vector<unsigned long long> setFilePosFasta(string, int&);
85                 string sortFile(string, string);
86                 int appendFiles(string, string);
87         int appendFilesWithoutHeaders(string, string);
88                 int renameFile(string, string); //oldname, newname
89                 string getFullPathName(string);
90         string findProgramPath(string programName);
91                 string hasPath(string);
92                 string getExtension(string);
93                 string getPathName(string);
94                 string getSimpleName(string);
95                 string getRootName(string);
96                 bool isBlank(string);
97                 int openOutputFile(string, ofstream&);
98         int openOutputFileBinary(string, ofstream&);
99                 int openOutputFileAppend(string, ofstream&);
100         int openOutputFileBinaryAppend(string, ofstream&);
101                 int openInputFile(string, ifstream&);
102                 int openInputFile(string, ifstream&, string); //no error given 
103                 string getline(ifstream&);
104                 string getline(istringstream&);
105                 void gobble(istream&);
106                 void gobble(istringstream&);
107         vector<string> splitWhiteSpace(string& rest, char[], int);
108         vector<string> splitWhiteSpace(string);
109         set<string> readAccnos(string);
110         int readAccnos(string, vector<string>&);
111         map<string, int> readNames(string);
112         map<string, int> readNames(string, unsigned long int&);
113         int readTax(string, map<string, string>&);
114         vector<consTax> readConsTax(string);
115         int readConsTax(string, map<string, consTax2>&);
116         int readNames(string, map<string, string>&, map<string, int>&);
117                 int readNames(string, map<string, string>&);
118         int readNames(string, map<string, string>&, bool);
119         int readNames(string, map<string, string>&, int);
120                 int readNames(string, map<string, vector<string> >&);
121                 int readNames(string, vector<seqPriorityNode>&, map<string, string>&);
122                 int mothurRemove(string);
123                 bool mothurConvert(string, int&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
124         bool mothurConvert(string, intDist&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
125                 bool mothurConvert(string, float&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
126                 bool mothurConvert(string, double&); //use for converting user inputs. Sets commandInputsConvertError to true if error occurs. Engines check this.
127         
128                 
129                 //searchs and checks
130                 bool checkReleaseVersion(ifstream&, string);
131                 bool anyLabelsToProcess(string, set<string>&, string);
132                 bool inUsersGroups(vector<string>, vector<string>);
133         bool inUsersGroups(vector<int>, vector< vector<int> >);
134                 bool inUsersGroups(string, vector<string>);
135         bool inUsersGroups(int, vector<int>);
136                 void getNumSeqs(ifstream&, int&);
137                 int getNumSeqs(ifstream&);
138                 int getNumNames(string);
139                 int getNumChar(string, char);
140                 bool isTrue(string);
141                 bool isContainingOnlyDigits(string);
142                 bool isNumeric1(string);
143         bool isLabelEquivalent(string, string);
144         string getSimpleLabel(string);
145         string findEdianness();
146         
147                 
148                 //string manipulation
149                 void splitAtEquals(string&, string&);
150                 void splitAtComma(string&, string&);    
151                 void splitAtComma(string&, vector<string>&);
152                 void splitAtDash(string&, set<int>&);
153                 void splitAtDash(string&, set<string>&);
154                 void splitAtDash(string&, vector<string>&);
155                 void splitAtChar(string&, vector<string>&, char);
156         void splitAtChar(string&, string&, char);
157         vector<string> splitWhiteSpaceWithQuotes(string);
158                 int removeConfidences(string&);
159         string removeQuotes(string);
160         string makeList(vector<string>&);
161         bool isSubset(vector<string>, vector<string>); //bigSet, subset
162         int checkName(string&);
163         map<string, vector<string> > parseClasses(string);
164                 
165                 //math operation
166         double max(vector<double>&); //returns largest value in vector
167         double min(vector<double>&); //returns smallest value in vector
168                 int factorial(int num);
169                 vector<vector<double> > binomial(int);
170                 float ceilDist(float, int);
171                 float roundDist(float, int);
172                 unsigned int fromBase36(string);
173         double median(vector<double>);
174                 int getRandomIndex(int); //highest
175         double getStandardDeviation(vector<int>&);
176         vector<double> getStandardDeviation(vector< vector<double> >&);
177         vector<double> getStandardDeviation(vector< vector<double> >&, vector<double>&);
178         vector<double> getAverages(vector< vector<double> >&);
179         double getAverage(vector<double>);
180         vector< vector<seqDist> > getStandardDeviation(vector< vector< vector<seqDist> > >&);
181         vector< vector<seqDist> > getStandardDeviation(vector< vector< vector<seqDist> > >&, vector< vector<seqDist> >&);
182         vector< vector<seqDist> > getAverages(vector< vector< vector<seqDist> > >&, string);
183         vector< vector<seqDist> > getAverages(vector< vector< vector<seqDist> > >&);
184
185                 int control_pressed;
186                 bool executing, runParse, jumble, gui, mothurCalling, debug;
187                 
188                 //current files - if you add a new type you must edit optionParser->getParameters, get.current and set.current commands and mothurOut->printCurrentFiles/clearCurrentFiles/getCurrentTypes. add a get and set function.
189                 string getPhylipFile()          { return phylipfile;            }
190                 string getColumnFile()          { return columnfile;            }
191                 string getListFile()            { return listfile;                      }
192                 string getRabundFile()          { return rabundfile;            }
193                 string getSabundFile()          { return sabundfile;            }
194                 string getNameFile()            { return namefile;                      }       
195                 string getGroupFile()           { return groupfile;                     }       
196                 string getOrderFile()           { return orderfile;                     }
197                 string getOrderGroupFile()      { return ordergroupfile;        }
198                 string getTreeFile()            { return treefile;                      }
199                 string getSharedFile()          { return sharedfile;            }
200                 string getRelAbundFile()        { return relabundfile;          }
201                 string getDesignFile()          { return designfile;            }
202                 string getFastaFile()           { return fastafile;                     }
203                 string getSFFFile()                     { return sfffile;                       }
204                 string getQualFile()            { return qualfile;                      }
205                 string getOligosFile()          { return oligosfile;            }
206                 string getAccnosFile()          { return accnosfile;            }
207                 string getTaxonomyFile()        { return taxonomyfile;          }
208                 string getFlowFile()            { return flowfile;                      }
209         string getBiomFile()            { return biomfile;                      }
210         string getCountTableFile()      { return counttablefile;        }
211         string getSummaryFile()     { return summaryfile;       }
212                 string getProcessors()          { return processors;            }
213                 
214                 void setListFile(string f)                      { listfile = getFullPathName(f);                        }
215                 void setTreeFile(string f)                      { treefile = getFullPathName(f);                        }
216                 void setGroupFile(string f)                     { groupfile = getFullPathName(f);       groupMode = "group";            }               
217                 void setPhylipFile(string f)            { phylipfile = getFullPathName(f);                      }
218                 void setColumnFile(string f)            { columnfile = getFullPathName(f);                      }
219                 void setNameFile(string f)                      { namefile = getFullPathName(f);                        }       
220                 void setRabundFile(string f)            { rabundfile = getFullPathName(f);                      }
221                 void setSabundFile(string f)            { sabundfile = getFullPathName(f);                      }
222                 void setSharedFile(string f)            { sharedfile = getFullPathName(f);                      }
223                 void setRelAbundFile(string f)          { relabundfile = getFullPathName(f);            }
224                 void setOrderFile(string f)                     { orderfile = getFullPathName(f);                       }
225                 void setOrderGroupFile(string f)        { ordergroupfile = getFullPathName(f);          }
226                 void setDesignFile(string f)            { designfile = getFullPathName(f);                      }
227                 void setFastaFile(string f)                     { fastafile = getFullPathName(f);                       }
228                 void setSFFFile(string f)                       { sfffile = getFullPathName(f);                         }
229                 void setQualFile(string f)                      { qualfile = getFullPathName(f);                        }
230                 void setOligosFile(string f)            { oligosfile = getFullPathName(f);                      }
231                 void setAccnosFile(string f)            { accnosfile = getFullPathName(f);                      }
232                 void setTaxonomyFile(string f)          { taxonomyfile = getFullPathName(f);            }
233                 void setFlowFile(string f)                      { flowfile = getFullPathName(f);                        }
234         void setBiomFile(string f)                      { biomfile = getFullPathName(f);                        }
235         void setSummaryFile(string f)           { summaryfile = getFullPathName(f);                     }
236         void setCountTableFile(string f)        { counttablefile = getFullPathName(f);  groupMode = "count";    }
237         void setProcessors(string p)            { processors = p; mothurOut("\nUsing " + toString(p) + " processors.\n");       }
238                 
239                 void printCurrentFiles();
240                 bool hasCurrentFiles();
241                 void clearCurrentFiles();
242         set<string> getCurrentTypes(); 
243                 
244         private:
245                 static MothurOut* _uniqueInstance;
246                 MothurOut( const MothurOut& ); // Disable copy constructor
247                 void operator=( const MothurOut& ); // Disable assignment operator
248                 MothurOut() { 
249                         control_pressed = false; defaultPath=""; 
250                         phylipfile = "";
251                         columnfile = "";
252                         listfile = "";
253                         rabundfile = "";
254                         sabundfile = "";
255                         namefile = "";
256                         groupfile = "";
257                         designfile = "";
258                         orderfile = "";
259                         treefile = "";
260                         sharedfile = "";
261                         ordergroupfile = "";
262                         relabundfile = "";
263                         fastafile = "";
264                         qualfile = "";
265                         sfffile = "";
266                         oligosfile = "";
267                         accnosfile = "";
268                         taxonomyfile = "";
269                         processors = "1";
270                         flowfile = "";
271             biomfile = "";
272             counttablefile = "";
273             summaryfile = "";
274                         gui = false;
275                         printedSharedHeaders = false;
276             printedListHeaders = false;
277                         commandInputsConvertError = false;
278             mothurCalling = false;
279             debug = false;
280                         sharedHeaderMode = "";
281             groupMode = "group";
282             changedSeqNames = false;
283             modifyNames = true;
284                 }
285                 ~MothurOut();
286
287                 string logFileName;
288                 string defaultPath, outputDir;
289                 string releaseDate, version;
290         
291                 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile, biomfile;
292                 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile, counttablefile, summaryfile;
293
294                 vector<string> Groups;
295                 vector<string> namesOfGroups;
296                 ofstream out;
297                 
298                 int mem_usage(double&, double&);
299
300 };
301 /***********************************************/
302
303 #endif
304