]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedutilities.cpp
1.18.1
[mothur.git] / sharedutilities.cpp
index fc1b3350599ebb6db17da3d6f02f977a1f793bb1..f43bb8107f3ec05ef462bcbb491283706c6a9730 100644 (file)
@@ -49,11 +49,7 @@ void SharedUtil::getSharedVectors(vector<string> Groups, vector<SharedRAbundVect
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "getSharedVectors");
                exit(1);
        }
 }
@@ -66,7 +62,6 @@ void SharedUtil::getSharedVectorswithReplacement(vector<string> Groups, vector<S
                for (int j = 0; j < lookup.size(); j++) {
                        delete lookup[j];
                }
-               
                lookup.clear();
                
                //create and initialize vector of sharedvectors, one for each group
@@ -98,11 +93,7 @@ void SharedUtil::getSharedVectorswithReplacement(vector<string> Groups, vector<S
                
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getSharedVectorswithReplacement. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function getSharedVectorswithReplacement. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "getSharedVectorswithReplacement");
                exit(1);
        }
 }
@@ -116,7 +107,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                                //check that groups are valid
                                for (int i = 0; i < userGroups.size(); i++) {
                                        if (isValidGroup(userGroups[i], allGroups) != true) {
-                                               cout << userGroups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               m->mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine();
                                                // erase the invalid group from userGroups
                                                userGroups.erase(userGroups.begin()+i);
                                                i--;
@@ -125,7 +116,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                                
                                //if the user only entered invalid groups
                                if (userGroups.size() == 0) { 
-                                       cout << "When using the groups parameter you must have at least 1 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       m->mothurOut("You provided no valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine();
                                        for (int i = 0; i < allGroups.size(); i++) {
                                                userGroups.push_back(allGroups[i]);
                                        }
@@ -145,14 +136,9 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                        
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "setGroups");
                exit(1);
        }
-
 }
 /**************************************************************************************************/
 //need to have mode because different commands require different number of valid groups
@@ -163,7 +149,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                                //check that groups are valid
                                for (int i = 0; i < userGroups.size(); i++) {
                                        if (isValidGroup(userGroups[i], allGroups) != true) {
-                                               cout << userGroups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               m->mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine();
                                                // erase the invalid group from userGroups
                                                userGroups.erase(userGroups.begin()+i);
                                                i--;
@@ -185,7 +171,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                if ((mode == "collect") || (mode == "rarefact") || (mode == "summary") || (mode == "treegroup")) {
                                //if the user only entered invalid groups
                                if ((userGroups.size() == 0) || (userGroups.size() == 1)) { 
-                                       cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                                       m->mothurOut("When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine();
                                        for (int i = 0; i < allGroups.size(); i++) {
                                                userGroups.push_back(allGroups[i]);
                                        }
@@ -194,14 +180,9 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
        
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "setGroups");
                exit(1);
        }
-
 }
 
 
@@ -211,13 +192,14 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
        try {
                numGroups = 0;
                label = "";
+
                //if the user has not entered specific groups to analyze then do them all
                if (userGroups.size() != 0) {
                        if (userGroups[0] != "all") {
                                //check that groups are valid
                                for (int i = 0; i < userGroups.size(); i++) {
                                        if (isValidGroup(userGroups[i], allGroups) != true) {
-                                               cout << userGroups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               m->mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine();
                                                // erase the invalid group from globaldata->Groups
                                                userGroups.erase(userGroups.begin()+i);
                                                i--;
@@ -244,6 +226,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                        }
                        //rip extra - off allgroups 
                        label = label.substr(0, label.length()-1);
+                       if ((mode != "weighted") && (allGroups.size() > 10)) {  label = "merged";  }
                }
                
                if (mode == "weighted") {
@@ -254,9 +237,9 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                                                userGroups.push_back(allGroups[i]);
                                        }
                                }
-                               cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; 
+                               m->mothurOut("When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine();
                        }else if (userGroups.size() == 1) { 
-                               cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
+                               m->mothurOut("When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine();
                                userGroups.clear();
                                for (int i=0; i < allGroups.size(); i++) { 
                                        if (allGroups[i] != "xxx") {
@@ -269,7 +252,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                }else if ((mode == "unweighted") || (mode == "parsimony")) {
                                //if the user only entered invalid groups
                                if ((userGroups.size() == 0) && (numGroups == 0)) { 
-                                       cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile." << endl; 
+                                       m->mothurOut("When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine();
                                        for (int i = 0; i < allGroups.size(); i++) {
                                                if (allGroups[i] != "xxx") {
                                                        userGroups.push_back(allGroups[i]);
@@ -281,11 +264,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "setGroups");
                exit(1);
        }
 }
@@ -296,18 +275,18 @@ void SharedUtil::getCombos(vector<string>& groupComb, vector<string> userGroups,
                numComp = 0;
                for (int i=0; i< userGroups.size(); i++) { 
                        numComp += i; 
-                       for (int l = i+1; l < userGroups.size(); l++) {
-                               //set group comparison labels
-                               groupComb.push_back(userGroups[i] + "-" + userGroups[l]);
+                       for (int l = 0; l < i; l++) {
+                               if (userGroups[i] > userGroups[l]) {
+                                       //set group comparison labels
+                                       groupComb.push_back(userGroups[l] + "-" + userGroups[i]);
+                               }else{
+                                       groupComb.push_back(userGroups[i] + "-" + userGroups[l]);
+                               }
                        }
                } 
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getCombos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function getCombos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "getCombos");
                exit(1);
        }
 }
@@ -321,11 +300,7 @@ bool SharedUtil::isValidGroup(string groupname, vector<string> groups) {
                return false;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function isValidGroup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "isValidGroup");
                exit(1);
        }
 }
@@ -339,11 +314,10 @@ void SharedUtil::updateGroupIndex(vector<string>& userGroups, map<string, int>&
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function updateGroupIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the SharedUtil class function updateGroupIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "SharedUtil", "updateGroupIndex");
                exit(1);
        }
 }
+/**************************************************************************************/
+
+