X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sharedutilities.cpp;h=d9891db7966da9178ce0b0deaa177ddeb192fc79;hp=703241b532504ac6f4ab3b761507b089e41c58a5;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=0470f6d037aacb3563c3f7010708120a4a67d4e6 diff --git a/sharedutilities.cpp b/sharedutilities.cpp index 703241b..d9891db 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -22,7 +22,9 @@ void SharedUtil::getSharedVectors(vector Groups, vectorgetNumBins()); @@ -49,11 +51,7 @@ void SharedUtil::getSharedVectors(vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectors"); exit(1); } } @@ -66,7 +64,6 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectorswithReplacement"); exit(1); } } @@ -111,13 +104,16 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vector& userGroups, vector& allGroups) { try { -//cout << "groups size" << userGroups.size() << endl; + + 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) { - 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--; @@ -126,7 +122,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //if the user only entered invalid groups if (userGroups.size() == 0) { - cout << "You provided no 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 file."); m->mothurOutEndLine(); for (int i = 0; i < allGroups.size(); i++) { userGroups.push_back(allGroups[i]); } @@ -146,25 +142,24 @@ void SharedUtil::setGroups(vector& userGroups, vector& 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"; + m->errorOut(e, "SharedUtil", "setGroups"); 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& 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) { - 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--; @@ -186,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)) { - 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]); } @@ -195,14 +190,9 @@ void SharedUtil::setGroups(vector& userGroups, vector& 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); } - } @@ -210,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 = ""; @@ -219,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) { - 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--; @@ -246,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") { @@ -256,9 +250,9 @@ void SharedUtil::setGroups(vector& userGroups, vector& 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") { @@ -271,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)) { - 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]); @@ -283,33 +277,30 @@ void SharedUtil::setGroups(vector& userGroups, vector& 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); } } /**************************************************************************************/ 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) { - 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); } } @@ -323,11 +314,7 @@ bool SharedUtil::isValidGroup(string groupname, vector 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); } } @@ -341,11 +328,10 @@ void SharedUtil::updateGroupIndex(vector& userGroups, map& } } 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); } } +/**************************************************************************************/ + +