X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sharedutilities.cpp;h=d9891db7966da9178ce0b0deaa177ddeb192fc79;hp=7d85c4cbbf3e989b4e92ac400b22ab274b60c548;hb=cf9987b67aa49777a4c91c2d21f96e58bf17aa82;hpb=510b1cfc25cd79391d6973ca20c5ec25fb1bb3b2 diff --git a/sharedutilities.cpp b/sharedutilities.cpp index 7d85c4c..d9891db 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -22,7 +22,9 @@ void SharedUtil::getSharedVectors(vector Groups, vectorgetNumBins()); @@ -49,7 +51,7 @@ void SharedUtil::getSharedVectors(vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectors"); exit(1); } } @@ -93,7 +95,7 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectorswithReplacement"); exit(1); } } @@ -102,12 +104,16 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vector& userGroups, vector& 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 for (int i = 0; i < userGroups.size(); i++) { if (isValidGroup(userGroups[i], allGroups) != true) { - mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine(); + 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--; @@ -116,7 +122,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //if the user only entered invalid groups if (userGroups.size() == 0) { - mothurOut("You provided no valid groups. I will run the command using all the groups in your groupfile."); 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]); } @@ -136,7 +142,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups } catch(exception& e) { - errorOut(e, "SharedUtil", "setGroups"); + m->errorOut(e, "SharedUtil", "setGroups"); exit(1); } } @@ -144,12 +150,16 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //need to have mode because different commands require different number of valid groups void SharedUtil::setGroups(vector& userGroups, vector& 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 for (int i = 0; i < userGroups.size(); i++) { if (isValidGroup(userGroups[i], allGroups) != true) { - mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine(); + 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--; @@ -171,7 +181,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups if ((mode == "collect") || (mode == "rarefact") || (mode == "summary") || (mode == "treegroup")) { //if the user only entered invalid groups if ((userGroups.size() == 0) || (userGroups.size() == 1)) { - 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."); mothurOutEndLine(); + 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]); } @@ -180,7 +190,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups } catch(exception& e) { - errorOut(e, "SharedUtil", "setGroups"); + m->errorOut(e, "SharedUtil", "setGroups"); exit(1); } } @@ -190,6 +200,9 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //for parsimony and unifrac commands you set pairwise groups as well as an allgroups in calc void SharedUtil::setGroups(vector& userGroups, vector& 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 = ""; @@ -199,7 +212,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //check that groups are valid for (int i = 0; i < userGroups.size(); i++) { if (isValidGroup(userGroups[i], allGroups) != true) { - mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine(); + 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--; @@ -226,6 +239,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups } //rip extra - off allgroups label = label.substr(0, label.length()-1); + if ((mode != "weighted") && (allGroups.size() > 10)) { label = "merged"; } } if (mode == "weighted") { @@ -236,9 +250,9 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups userGroups.push_back(allGroups[i]); } } - 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."); mothurOutEndLine(); + 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) { - 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."); mothurOutEndLine(); + 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") { @@ -251,7 +265,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups }else if ((mode == "unweighted") || (mode == "parsimony")) { //if the user only entered invalid groups if ((userGroups.size() == 0) && (numGroups == 0)) { - 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."); mothurOutEndLine(); + 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]); @@ -263,25 +277,30 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups } } catch(exception& e) { - errorOut(e, "SharedUtil", "setGroups"); + m->errorOut(e, "SharedUtil", "setGroups"); exit(1); } } /**************************************************************************************/ void SharedUtil::getCombos(vector& groupComb, vector 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]); + } } } } catch(exception& e) { - errorOut(e, "SharedUtil", "getCombos"); + m->errorOut(e, "SharedUtil", "getCombos"); exit(1); } } @@ -295,7 +314,7 @@ bool SharedUtil::isValidGroup(string groupname, vector groups) { return false; } catch(exception& e) { - errorOut(e, "SharedUtil", "isValidGroup"); + m->errorOut(e, "SharedUtil", "isValidGroup"); exit(1); } } @@ -309,7 +328,10 @@ void SharedUtil::updateGroupIndex(vector& userGroups, map& } } catch(exception& e) { - errorOut(e, "SharedUtil", "updateGroupIndex"); + m->errorOut(e, "SharedUtil", "updateGroupIndex"); exit(1); } } +/**************************************************************************************/ + +