X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedutilities.cpp;h=15f16a6f1942921ca41098dd502750d68c75ce3e;hb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;hp=edd16c7cdee387c1c83f50471d6caf025c8352ec;hpb=51cf89e90eef8b300c2786eb1560dd89e6e83445;p=mothur.git diff --git a/sharedutilities.cpp b/sharedutilities.cpp index edd16c7..15f16a6 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -49,11 +49,7 @@ void SharedUtil::getSharedVectors(vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectors"); exit(1); } } @@ -66,7 +62,6 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectorswithReplacement"); exit(1); } } /**************************************************************************************************/ //need to have mode because different commands require different number of valid groups -void SharedUtil::setGroups(vector& userGroups, vector& allGroups, string mode) { +void SharedUtil::setGroups(vector& userGroups, vector& allGroups) { 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; + 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--; } } + + //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(); + 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,41 +134,44 @@ void SharedUtil::setGroups(vector& userGroups, vector& 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) { + m->errorOut(e, "SharedUtil", "setGroups"); + 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 { + 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) { + 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--; } } - }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; + 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]); } @@ -178,29 +180,26 @@ 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); } - } + /**************************************************************************************/ //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 { 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--; @@ -211,24 +210,25 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups for (int i=0; i < allGroups.size(); i++) { if (allGroups[i] != "xxx") { userGroups.push_back(allGroups[i]); - label += allGroups[i] + "-"; } } } }else { //the user has not entered groups for (int i=0; i < allGroups.size(); i++) { if (allGroups[i] != "xxx") { - label += allGroups[i] + "-"; if (mode == "weighted") { userGroups.push_back(allGroups[i]); }else { numGroups = 1; + label += allGroups[i] + "-"; } } } + //rip extra - off allgroups + label = label.substr(0, label.length()-1); + if ((mode != "weighted") && (allGroups.size() > 10)) { label = "merged"; } } - if (mode == "weighted") { //if the user only entered invalid groups if (userGroups.size() == 0) { @@ -237,9 +237,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") { @@ -252,32 +252,19 @@ 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]); - label += allGroups[i] + "-"; } } - }else { - for (int i = 0; i < userGroups.size(); i++) { - label += userGroups[i] + "-"; - } } - //rip extra - off allgroups - label = label.substr(0, label.length()-1); - if (numGroups != 1) { numGroups = userGroups.size(); } - } } 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); } } @@ -288,18 +275,18 @@ void SharedUtil::getCombos(vector& groupComb, vector 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); } } @@ -313,16 +300,12 @@ 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); } } -/**************************************************************************************/ +/************************************************************************************** void SharedUtil::updateGroupIndex(vector& userGroups, map& index) { try { index.clear(); @@ -331,11 +314,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); } } +/**************************************************************************************/ + +