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