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);
36 //**********************************************************************************************************************
39 inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
42 if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
44 cout << "'" << s << "' is unable to be converted into an integer.\n";
50 //**********************************************************************************************************************
53 string toString(const T&x){
59 //**********************************************************************************************************************
62 string toString(const T&x, int i){
72 /***********************************************************************/
74 inline void gobble(istream& f){
77 while(isspace(d=f.get())) {;}
82 /***********************************************************************/
84 inline float roundDist(float dist, int precision){
86 return int(dist * precision + 0.5)/float(precision);
90 /***********************************************************************/
92 inline int getNumNames(string names){
98 for(int i=0;i<names.size();i++){
109 /**************************************************************************************************/
111 inline vector<vector<double> > binomial(int maxOrder){
113 vector<vector<double> > binomial(maxOrder+1);
115 for(int i=0;i<=maxOrder;i++){
116 binomial[i].resize(maxOrder+1);
125 for(int i=2;i<=maxOrder;i++){
129 for(int i=2;i<=maxOrder;i++){
130 for(int j=1;j<=maxOrder;j++){
131 if(i==j){ binomial[i][j]=1; }
132 if(j>i) { binomial[i][j]=0; }
133 else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
140 /***********************************************************************/
142 inline string getRootName(string longName){
144 string rootName = longName;
146 if(longName.find_last_of(".") != longName.npos){
147 int pos = longName.find_last_of('.')+1;
148 rootName = longName.substr(0, pos);
153 /***********************************************************************/
155 inline string getSimpleName(string longName){
157 string simpleName = longName;
159 if(longName.find_last_of("/") != longName.npos){
160 int pos = longName.find_last_of('/')+1;
161 simpleName = longName.substr(pos, longName.length());
167 /***********************************************************************/
169 inline string getPathName(string longName){
171 string rootPathName = longName;
173 if(longName.find_last_of("/") != longName.npos){
174 int pos = longName.find_last_of('/')+1;
175 rootPathName = longName.substr(0, pos);
181 /***********************************************************************/
183 inline int openInputFile(string fileName, ifstream& fileHandle){
185 fileHandle.open(fileName.c_str());
187 cerr << "Error: Could not open " << fileName << endl;
196 /***********************************************************************/
198 inline int openOutputFile(string fileName, ofstream& fileHandle){
200 fileHandle.open(fileName.c_str(), ios::trunc);
202 cerr << "Error: Could not open " << fileName << endl;
211 /***********************************************************************/
213 //This function parses the estimator options and puts them in a vector
214 inline void splitAtDash(string& estim, vector<string>& container) {
218 while (estim.find_first_of('-') != -1) {
219 individual = estim.substr(0,estim.find_first_of('-'));
220 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
221 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
222 container.push_back(individual);
226 container.push_back(estim);
228 catch(exception& e) {
229 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
233 cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
239 /***********************************************************************/
240 //This function parses the label options and puts them in a set
241 inline void splitAtDash(string& estim, set<string>& container) {
245 while (estim.find_first_of('-') != -1) {
246 individual = estim.substr(0,estim.find_first_of('-'));
247 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
248 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
249 container.insert(individual);
253 container.insert(estim);
255 catch(exception& e) {
256 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
260 cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
265 /***********************************************************************/
266 //This function parses the line options and puts them in a set
267 inline void splitAtDash(string& estim, set<int>& container) {
272 while (estim.find_first_of('-') != -1) {
273 individual = estim.substr(0,estim.find_first_of('-'));
274 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
275 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
276 convert(individual, lineNum); //convert the string to int
277 container.insert(lineNum);
281 convert(estim, lineNum); //convert the string to int
282 container.insert(lineNum);
284 catch(exception& e) {
285 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
289 cout << "An unknown error has occurred in the utilities class function splitAtDash. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
294 /***********************************************************************/
296 //This function splits up the various option parameters
297 inline void splitAtComma(string& prefix, string& suffix){
299 prefix = suffix.substr(0,suffix.find_first_of(','));
300 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
301 suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
303 while(suffix.at(0) == ' ')
304 suffix = suffix.substr(1, suffix.length());
308 catch(exception& e) {
309 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
313 cout << "An unknown error has occurred in the utilities class function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
318 /***********************************************************************/
320 //This function separates the key value from the option value i.e. dist=96_...
321 inline void splitAtEquals(string& key, string& value){
323 if(value.find_first_of('=') != -1){
324 key = value.substr(0,value.find_first_of('='));
325 if ((value.find_first_of('=')+1) <= value.length()) {
326 value = value.substr(value.find_first_of('=')+1, value.length());
333 catch(exception& e) {
334 cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
338 cout << "An unknown error has occurred in the utilities class function splitAtEquals. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
343 /*******************************************************/