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