15 typedef unsigned long long ull;
17 /***********************************************************************/
19 // snagged from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2
20 // works for now, but there should be a way to do it without killing the whole program
22 class BadConversion : public runtime_error {
24 BadConversion(const string& s) : runtime_error(s){ }
27 //**********************************************************************************************************************
30 inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
33 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
34 throw BadConversion(s);
37 //**********************************************************************************************************************
40 string toString(const T&x){
46 //**********************************************************************************************************************
49 string toString(const T&x, int i){
59 /***********************************************************************/
61 inline void gobble(ifstream& f){
64 while(isspace(d=f.get())) {;}
69 /***********************************************************************/
71 inline float roundDist(float dist, int precision){
73 return int(dist * precision + 0.5)/float(precision);
77 /***********************************************************************/
79 inline int getNumNames(string names){
85 for(int i=0;i<names.size();i++){
96 /**************************************************************************************************/
98 inline vector<vector<double> > binomial(int maxOrder){
100 vector<vector<double> > binomial(maxOrder+1);
102 for(int i=0;i<=maxOrder;i++){
103 binomial[i].resize(maxOrder+1);
112 for(int i=2;i<=maxOrder;i++){
116 for(int i=2;i<=maxOrder;i++){
117 for(int j=1;j<=maxOrder;j++){
118 if(i==j){ binomial[i][j]=1; }
119 if(j>i) { binomial[i][j]=0; }
120 else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
127 /***********************************************************************/
129 inline string getRootName(string longName){
131 string rootName = longName;
133 if(longName.find_last_of(".") != longName.npos){
134 int pos = longName.find_last_of('.')+1;
135 rootName = longName.substr(0, pos);
140 /***********************************************************************/
142 inline string getSimpleName(string longName){
144 string simpleName = longName;
146 if(longName.find_last_of("/") != longName.npos){
147 int pos = longName.find_last_of('/')+1;
148 simpleName = longName.substr(pos, longName.length());
154 /***********************************************************************/
156 inline string getPathName(string longName){
158 string rootPathName = longName;
160 if(longName.find_last_of("/") != longName.npos){
161 int pos = longName.find_last_of('/')+1;
162 rootPathName = longName.substr(0, pos);
168 /***********************************************************************/
170 inline int openInputFile(string fileName, ifstream& fileHandle){
172 fileHandle.open(fileName.c_str());
174 cerr << "Error: Could not open " << fileName << endl;
183 /***********************************************************************/
185 inline int openOutputFile(string fileName, ofstream& fileHandle){
187 fileHandle.open(fileName.c_str(), ios::trunc);
189 cerr << "Error: Could not open " << fileName << endl;
198 /***********************************************************************/
200 //This function parses the estimator options and puts them in a vector
201 inline void splitAtDash(string& estim, vector<string>& container) {
205 while (estim.find_first_of('-') != -1) {
206 individual = estim.substr(0,estim.find_first_of('-'));
207 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
208 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
209 container.push_back(individual);
213 container.push_back(estim);
215 catch(exception& e) {
216 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
220 cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
226 /***********************************************************************/
227 //This function parses the label options and puts them in a set
228 inline void splitAtDash(string& estim, set<string>& container) {
232 while (estim.find_first_of('-') != -1) {
233 individual = estim.substr(0,estim.find_first_of('-'));
234 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
235 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
236 container.insert(individual);
240 container.insert(estim);
242 catch(exception& e) {
243 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
247 cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
252 /***********************************************************************/
253 //This function parses the line options and puts them in a set
254 inline void splitAtDash(string& estim, set<int>& container) {
259 while (estim.find_first_of('-') != -1) {
260 individual = estim.substr(0,estim.find_first_of('-'));
261 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
262 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
263 convert(individual, lineNum); //convert the string to int
264 container.insert(lineNum);
268 convert(estim, lineNum); //convert the string to int
269 container.insert(lineNum);
271 catch(exception& e) {
272 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
276 cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
281 /***********************************************************************/
283 //This function splits up the various option parameters
284 inline void splitAtComma(string& prefix, string& suffix){
286 prefix = suffix.substr(0,suffix.find_first_of(','));
287 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
288 suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
291 catch(exception& e) {
292 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
296 cout << "An unknown error has occurred in the utilities class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
301 /***********************************************************************/
303 //This function separates the key value from the option value i.e. dist=96_...
304 inline void splitAtEquals(string& key, string& value){
306 if(value.find_first_of('=') != -1){
307 key = value.substr(0,value.find_first_of('='));
308 if ((value.find_first_of('=')+1) <= value.length()) {
309 value = value.substr(value.find_first_of('=')+1, value.length());
316 catch(exception& e) {
317 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
321 cout << "An unknown error has occurred in the utilities class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
326 /*******************************************************/