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