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