]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedutilities.cpp
changed heatmap and venn command to use vector of sharedrabunds instead of order...
[mothur.git] / sharedutilities.cpp
index 454b7d4073396f74c804ad1bba68cbea57ac5f57..fc1b3350599ebb6db17da3d6f02f977a1f793bb1 100644 (file)
@@ -109,7 +109,7 @@ void SharedUtil::getSharedVectorswithReplacement(vector<string> Groups, vector<S
 
 /**************************************************************************************************/
 //need to have mode because different commands require different number of valid groups
-void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string mode) {
+void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups) {
        try {
                if (userGroups.size() != 0) {
                        if (userGroups[0] != "all") {
@@ -122,6 +122,14 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                                                i--;
                                        }
                                }
+                               
+                               //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; 
+                                       for (int i = 0; i < allGroups.size(); i++) {
+                                               userGroups.push_back(allGroups[i]);
+                                       }
+                               }
 
                        }else{//user has enter "all" and wants the default groups
                                userGroups.clear();
@@ -135,38 +143,46 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                        }
                }
                        
-               if (mode == "venn")  {
-                               //if the user only entered invalid groups
-                               if (userGroups.size() == 0) { 
-                                       if (allGroups.size() > 4) {
-                                               cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using the first four groups in your groupfile." << endl; 
-                                               for (int i = 0; i < 4; i++) {
-                                                       userGroups.push_back(allGroups[i]);
-                                               }
-                                       }else {
-                                               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; 
-                                               for (int i = 0; i < allGroups.size(); i++) {
-                                                       userGroups.push_back(allGroups[i]);
-                                               }
-                                       }
-                               }
-                               
-                               //check to make sure their are only 4 groups
-                               if (userGroups.size() > 4) {
-                                       cout << "You may only use up to 4 groups at a time with this command.  I will choose the first four and disregard the rest." << endl;
-                                       for (int i = 4; i < userGroups.size(); i++) {
+       }
+       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";
+               exit(1);
+       }
+
+}
+/**************************************************************************************************/
+//need to have mode because different commands require different number of valid groups
+void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string mode) {
+       try {
+               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;
+                                               // erase the invalid group from userGroups
                                                userGroups.erase(userGroups.begin()+i);
+                                               i--;
                                        }
                                }
-               }else if (mode == "heat") {
-                               //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; 
-                                       for (int i = 0; i < allGroups.size(); i++) {
-                                               userGroups.push_back(allGroups[i]);
-                                       }
+
+                       }else{//user has enter "all" and wants the default groups
+                               userGroups.clear();
+                               for (int i = 0; i < allGroups.size(); i++) {
+                                       userGroups.push_back(allGroups[i]);
                                }
-               }else if ((mode == "collect") || (mode == "rarefact") || (mode == "summary") || (mode == "treegroup")) {
+                       }
+               }else { //the user has not entered groups
+                       for (int i = 0; i < allGroups.size(); i++) {
+                               userGroups.push_back(allGroups[i]);
+                       }
+               }
+                       
+               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; 
@@ -188,6 +204,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
 
 }
 
+
 /**************************************************************************************/
 //for parsimony and unifrac commands you set pairwise groups as well as an allgroups in calc
 void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups, string& label, int& numGroups, string mode){  //globaldata->Groups, your tree or group map, allgroups, mode