]> git.donarmstrong.com Git - mothur.git/blobdiff - utilities.hpp
added heatmap command
[mothur.git] / utilities.hpp
index 0c67561e427737ec95e2bb9e0ae29e8b87ff46ef..d1b32490beca985771529fb0665842109272329b 100644 (file)
@@ -3,14 +3,8 @@
 
 using namespace std;
 
-#include <iostream>
-#include <iomanip>
-#include <fstream>
-#include <sstream>
-#include <cmath>
-#include <vector>
-#include <stdexcept>
-#include <set>
+#include "mothur.h"
+#include "treemap.h"
 
 typedef unsigned long long ull;
 
@@ -33,6 +27,19 @@ inline void convert(const string& s, T& x, bool failIfLeftoverChars = true){
        if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
                throw BadConversion(s);
 }
+//**********************************************************************************************************************
+
+template<typename T>
+inline bool convertTest(const string& s, T& x, bool failIfLeftoverChars = true){
+       istringstream i(s);
+       char c;
+       if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
+       {
+               cout << "'" << s << "' is unable to be converted into an integer.\n";
+               return false;
+       } 
+       return true;
+}
 
 //**********************************************************************************************************************
 
@@ -45,6 +52,17 @@ string toString(const T&x){
 
 //**********************************************************************************************************************
 
+template<typename T>
+string toHex(const T&x){
+       stringstream output;
+       
+       output << hex << x;
+
+    return output.str();
+}
+
+//**********************************************************************************************************************
+
 template<typename T>
 string toString(const T&x, int i){
        stringstream output;
@@ -58,7 +76,7 @@ string toString(const T&x, int i){
 
 /***********************************************************************/
 
-inline void gobble(ifstream& f){
+inline void gobble(istream& f){
        
        char d;
     while(isspace(d=f.get()))          {;}
@@ -285,8 +303,12 @@ inline void splitAtComma(string& prefix, string& suffix){
        try {
                prefix = suffix.substr(0,suffix.find_first_of(','));
                if ((suffix.find_first_of(',')+2) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
-                       suffix = suffix.substr(suffix.find_first_of(',')+2, suffix.length());
+                       suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
+                       string space = " ";
+                       while(suffix.at(0) == ' ')
+                               suffix = suffix.substr(1, suffix.length());
                }
+
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function splitAtComma. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -323,8 +345,23 @@ inline void splitAtEquals(string& key, string& value){
        }
 
 }
-/*******************************************************/
-
+/**************************************************************************************************/
 
+inline bool inUsersGroups(string groupname, vector<string> Groups) {
+       try {
+               for (int i = 0; i < Groups.size(); i++) {
+                       if (groupname == Groups[i]) { return true; }
+               }
+               return false;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the utilities class Function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the utilities class function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
 
 #endif