]> git.donarmstrong.com Git - mothur.git/blob - mothurout.h
added sparseDistanceMatrix class. Modified cluster commands to use the new sparse...
[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                 
145                 //math operation
146                 int factorial(int num);
147                 vector<vector<double> > binomial(int);
148                 float ceilDist(float, int);
149                 float roundDist(float, int);
150                 unsigned int fromBase36(string);
151                 int getRandomIndex(int); //highest
152
153                 int control_pressed;
154                 bool executing, runParse, jumble, gui, mothurCalling, debug;
155                 
156                 //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles/getCurrentTypes.
157                 string getPhylipFile()          { return phylipfile;            }
158                 string getColumnFile()          { return columnfile;            }
159                 string getListFile()            { return listfile;                      }
160                 string getRabundFile()          { return rabundfile;            }
161                 string getSabundFile()          { return sabundfile;            }
162                 string getNameFile()            { return namefile;                      }       
163                 string getGroupFile()           { return groupfile;                     }       
164                 string getOrderFile()           { return orderfile;                     }
165                 string getOrderGroupFile()      { return ordergroupfile;        }
166                 string getTreeFile()            { return treefile;                      }
167                 string getSharedFile()          { return sharedfile;            }
168                 string getRelAbundFile()        { return relabundfile;          }
169                 string getDesignFile()          { return designfile;            }
170                 string getFastaFile()           { return fastafile;                     }
171                 string getSFFFile()                     { return sfffile;                       }
172                 string getQualFile()            { return qualfile;                      }
173                 string getOligosFile()          { return oligosfile;            }
174                 string getAccnosFile()          { return accnosfile;            }
175                 string getTaxonomyFile()        { return taxonomyfile;          }
176                 string getFlowFile()            { return flowfile;                      }
177         string getBiomFile()            { return biomfile;                      }
178         string getCountTableFile()      { return counttablefile;        }
179                 string getProcessors()          { return processors;            }
180                 
181                 void setListFile(string f)                      { listfile = getFullPathName(f);                        }
182                 void setTreeFile(string f)                      { treefile = getFullPathName(f);                        }
183                 void setGroupFile(string f)                     { groupfile = getFullPathName(f);       groupMode = "group";            }               
184                 void setPhylipFile(string f)            { phylipfile = getFullPathName(f);                      }
185                 void setColumnFile(string f)            { columnfile = getFullPathName(f);                      }
186                 void setNameFile(string f)                      { namefile = getFullPathName(f);                        }       
187                 void setRabundFile(string f)            { rabundfile = getFullPathName(f);                      }
188                 void setSabundFile(string f)            { sabundfile = getFullPathName(f);                      }
189                 void setSharedFile(string f)            { sharedfile = getFullPathName(f);                      }
190                 void setRelAbundFile(string f)          { relabundfile = getFullPathName(f);            }
191                 void setOrderFile(string f)                     { orderfile = getFullPathName(f);                       }
192                 void setOrderGroupFile(string f)        { ordergroupfile = getFullPathName(f);          }
193                 void setDesignFile(string f)            { designfile = getFullPathName(f);                      }
194                 void setFastaFile(string f)                     { fastafile = getFullPathName(f);                       }
195                 void setSFFFile(string f)                       { sfffile = getFullPathName(f);                         }
196                 void setQualFile(string f)                      { qualfile = getFullPathName(f);                        }
197                 void setOligosFile(string f)            { oligosfile = getFullPathName(f);                      }
198                 void setAccnosFile(string f)            { accnosfile = getFullPathName(f);                      }
199                 void setTaxonomyFile(string f)          { taxonomyfile = getFullPathName(f);            }
200                 void setFlowFile(string f)                      { flowfile = getFullPathName(f);                        }
201         void setBiomFile(string f)                      { biomfile = getFullPathName(f);                        }
202         void setCountTableFile(string f)        { counttablefile = getFullPathName(f);  groupMode = "count";    }
203         void setProcessors(string p)            { processors = p; mothurOut("\nUsing " + toString(p) + " processors.\n");       }
204                 
205                 void printCurrentFiles();
206                 bool hasCurrentFiles();
207                 void clearCurrentFiles();
208         set<string> getCurrentTypes(); 
209                 
210         private:
211                 static MothurOut* _uniqueInstance;
212                 MothurOut( const MothurOut& ); // Disable copy constructor
213                 void operator=( const MothurOut& ); // Disable assignment operator
214                 MothurOut() { 
215                         control_pressed = false; defaultPath=""; 
216                         phylipfile = "";
217                         columnfile = "";
218                         listfile = "";
219                         rabundfile = "";
220                         sabundfile = "";
221                         namefile = "";
222                         groupfile = "";
223                         designfile = "";
224                         orderfile = "";
225                         treefile = "";
226                         sharedfile = "";
227                         ordergroupfile = "";
228                         relabundfile = "";
229                         fastafile = "";
230                         qualfile = "";
231                         sfffile = "";
232                         oligosfile = "";
233                         accnosfile = "";
234                         taxonomyfile = "";
235                         processors = "1";
236                         flowfile = "";
237             biomfile = "";
238             counttablefile = "";
239                         gui = false;
240                         printedHeaders = false;
241                         commandInputsConvertError = false;
242             mothurCalling = false;
243             debug = false;
244                         sharedHeaderMode = "";
245             groupMode = "group";
246                 }
247                 ~MothurOut();
248
249                 string logFileName;
250                 string defaultPath, outputDir;
251                 string releaseDate, version;
252         
253                 string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile, biomfile;
254                 string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors, flowfile, counttablefile;
255
256                 vector<string> Groups;
257                 vector<string> namesOfGroups;
258                 ofstream out;
259                 
260                 int mem_usage(double&, double&);
261
262 };
263 /***********************************************/
264
265 #endif
266