X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sharedutilities.cpp;h=fd0595de079b588a53e5b11c23d89c5a56687d78;hb=37a229b590342d94cd22bb1f7f4127e85197a27f;hp=4e35ff3df44fcf24df6accc2c0b920ecac60bcd9;hpb=c5c7502f435e1413c19e373dab1dfebcaa67588d;p=mothur.git diff --git a/sharedutilities.cpp b/sharedutilities.cpp index 4e35ff3..fd0595d 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -30,7 +30,7 @@ void SharedUtil::getSharedVectors(vector Groups, vectorsetGroup(Groups[i]); lookup.push_back(temp); } - + int numSeqs = order->size(); //sample all the members for(int i=0;i Groups, vector Groups, vector& lookup, SharedOrderVector* order) { + try { + + //delete each sharedrabundvector in lookup + for (int j = 0; j < lookup.size(); j++) { + delete lookup[j]; + } + + lookup.clear(); + + //create and initialize vector of sharedvectors, one for each group + for (int i = 0; i < Groups.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins()); + temp->setLabel(order->getLabel()); + temp->setGroup(Groups[i]); + lookup.push_back(temp); + } + + int numSeqs = order->size(); + + //sample all the members + for(int i=0;iget(random); + + int abundance; + //set info for sharedvector in chosens group + for (int j = 0; j < lookup.size(); j++) { + if (chosen.group == lookup[j]->getGroup()) { + abundance = lookup[j]->getAbundance(chosen.bin); + lookup[j]->set(chosen.bin, (abundance + 1), chosen.group); + break; + } + } + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the SharedUtil class Function getSharedVectorswithReplacement. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the SharedUtil class function getSharedVectorswithReplacement. 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) { +void SharedUtil::setGroups(vector& userGroups, vector& allGroups) { try { if (userGroups.size() != 0) { if (userGroups[0] != "all") { @@ -73,6 +122,14 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups i--; } } + + //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; + 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(); @@ -86,38 +143,46 @@ 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) { + 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& 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) { + 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; @@ -139,6 +204,7 @@ 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 @@ -162,24 +228,24 @@ 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") { //if the user only entered invalid groups if (userGroups.size() == 0) { @@ -207,20 +273,11 @@ 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 { - 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) {