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