]> git.donarmstrong.com Git - mothur.git/blobdiff - sharedutilities.cpp
changing command name classify.shared to classifyrf.shared
[mothur.git] / sharedutilities.cpp
index 4339a254efbfd9af51796e5c1d473fffa9ffaefa..d9891db7966da9178ce0b0deaa177ddeb192fc79 100644 (file)
@@ -22,7 +22,9 @@ void SharedUtil::getSharedVectors(vector<string> Groups, vector<SharedRAbundVect
                }
                
                lookup.clear();
-               
+        
+               sort(Groups.begin(), Groups.end());
+        
                //create and initialize vector of sharedvectors, one for each group
                for (int i = 0; i < Groups.size(); i++) { 
                        SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
@@ -102,6 +104,10 @@ 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) {
        try {
+               
+               sort(userGroups.begin(), userGroups.end());
+               sort(allGroups.begin(), allGroups.end());
+               
                if (userGroups.size() != 0) {
                        if (userGroups[0] != "all") {
                                //check that groups are valid
@@ -116,7 +122,7 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
                                
                                //if the user only entered invalid groups
                                if (userGroups.size() == 0) { 
-                                       m->mothurOut("You provided no valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine();
+                                       m->mothurOut("You provided no valid groups. I will run the command using all the groups in your file."); m->mothurOutEndLine();
                                        for (int i = 0; i < allGroups.size(); i++) {
                                                userGroups.push_back(allGroups[i]);
                                        }
@@ -144,6 +150,10 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
 //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 {
+               
+               sort(userGroups.begin(), userGroups.end());
+               sort(allGroups.begin(), allGroups.end());
+               
                if (userGroups.size() != 0) {
                        if (userGroups[0] != "all") {
                                //check that groups are valid
@@ -190,6 +200,9 @@ 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
        try {
+               sort(userGroups.begin(), userGroups.end());
+               sort(allGroups.begin(), allGroups.end());
+               
                numGroups = 0;
                label = "";
 
@@ -226,6 +239,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") {
@@ -270,13 +284,18 @@ void SharedUtil::setGroups(vector<string>& userGroups, vector<string>& allGroups
 /**************************************************************************************/
 void SharedUtil::getCombos(vector<string>& groupComb, vector<string> userGroups, int& numComp) { //groupcomb, globaldata->Groups, numcomb
        try {
+               sort(userGroups.begin(), userGroups.end());
                //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
                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]);
+                               }
                        }
                } 
        }
@@ -313,3 +332,6 @@ void SharedUtil::updateGroupIndex(vector<string>& userGroups, map<string, int>&
                exit(1);
        }
 }
+/**************************************************************************************/
+
+