X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=phylodiversitycommand.cpp;fp=phylodiversitycommand.cpp;h=ca0d02aca04b0a737d45c29b44cb02c2925ff257;hb=55386dddad84cc1140d736cabaf4dd0ae16f2e01;hp=d273e1dd3f4aab843190aceb4888e547a8bd81f5;hpb=990ded2eb38078a417fa00b4fbb4d3c24f4b5046;p=mothur.git diff --git a/phylodiversitycommand.cpp b/phylodiversitycommand.cpp index d273e1d..ca0d02a 100644 --- a/phylodiversitycommand.cpp +++ b/phylodiversitycommand.cpp @@ -137,8 +137,8 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { } m->runParse = true; - m->Groups.clear(); - m->namesOfGroups.clear(); + m->clearGroups(); + m->clearAllGroups(); m->Treenames.clear(); m->names.clear(); @@ -193,7 +193,7 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - m->Groups = Groups; + m->setGroups(Groups); } if ((!collect) && (!rarefy) && (!summary)) { m->mothurOut("No outputs selected. You must set either collect, rarefy or summary to true, summary=T by default."); m->mothurOutEndLine(); abort=true; } @@ -258,7 +258,7 @@ int PhyloDiversityCommand::execute(){ if (m->control_pressed) { delete tmap; for (int i = 0; i < trees.size(); i++) { delete trees[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); - m->Groups.clear(); + m->clearGroups(); return 0; } @@ -277,11 +277,14 @@ int PhyloDiversityCommand::execute(){ } SharedUtil* util = new SharedUtil(); - util->setGroups(m->Groups, tmap->namesOfGroups, "phylo.diversity"); //sets the groups the user wants to analyze + vector mGroups = m->getGroups(); + vector tGroups = tmap->getNamesOfGroups(); + util->setGroups(mGroups, tGroups, "phylo.diversity"); //sets the groups the user wants to analyze delete util; //incase the user had some mismatches between the tree and group files we don't want group xxx to be analyzed - for (int i = 0; i < m->Groups.size(); i++) { if (m->Groups[i] == "xxx") { m->Groups.erase(m->Groups.begin()+i); break; } } + for (int i = 0; i < mGroups.size(); i++) { if (mGroups[i] == "xxx") { mGroups.erase(mGroups.begin()+i); break; } } + m->setGroups(mGroups); vector outputNames; @@ -304,7 +307,7 @@ int PhyloDiversityCommand::execute(){ //create a vector containing indexes of leaf nodes, randomize it, select nodes to send to calculator vector randomLeaf; for (int j = 0; j < numLeafNodes; j++) { - if (m->inUsersGroups(trees[i]->tree[j].getGroup(), m->Groups) == true) { //is this a node from the group the user selected. + if (m->inUsersGroups(trees[i]->tree[j].getGroup(), mGroups) == true) { //is this a node from the group the user selected. randomLeaf.push_back(j); } } @@ -319,15 +322,15 @@ int PhyloDiversityCommand::execute(){ //find largest group total int largestGroup = 0; - for (int j = 0; j < m->Groups.size(); j++) { - if (tmap->seqsPerGroup[m->Groups[j]] > largestGroup) { largestGroup = tmap->seqsPerGroup[m->Groups[j]]; } + for (int j = 0; j < mGroups.size(); j++) { + if (tmap->seqsPerGroup[mGroups[j]] > largestGroup) { largestGroup = tmap->seqsPerGroup[mGroups[j]]; } //initialize diversity - diversity[m->Groups[j]].resize(tmap->seqsPerGroup[m->Groups[j]]+1, 0.0); //numSampled + diversity[mGroups[j]].resize(tmap->seqsPerGroup[mGroups[j]]+1, 0.0); //numSampled //groupA 0.0 0.0 //initialize sumDiversity - sumDiversity[m->Groups[j]].resize(tmap->seqsPerGroup[m->Groups[j]]+1, 0.0); + sumDiversity[mGroups[j]].resize(tmap->seqsPerGroup[mGroups[j]]+1, 0.0); } //convert freq percentage to number @@ -341,8 +344,8 @@ int PhyloDiversityCommand::execute(){ if(largestGroup % increment != 0){ numSampledList.insert(largestGroup); } //add other groups ending points - for (int j = 0; j < m->Groups.size(); j++) { - if (numSampledList.count(diversity[m->Groups[j]].size()-1) == 0) { numSampledList.insert(diversity[m->Groups[j]].size()-1); } + for (int j = 0; j < mGroups.size(); j++) { + if (numSampledList.count(diversity[mGroups[j]].size()-1) == 0) { numSampledList.insert(diversity[mGroups[j]].size()-1); } } #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -484,6 +487,7 @@ int PhyloDiversityCommand::createProcesses(vector& procIters, Tree* t, map< int PhyloDiversityCommand::driver(Tree* t, map< string, vector >& div, map >& sumDiv, int numIters, int increment, vector& randomLeaf, set& numSampledList, ofstream& outCollect, ofstream& outSum, bool doSumCollect){ try { int numLeafNodes = randomLeaf.size(); + vector mGroups = m->getGroups(); for (int l = 0; l < numIters; l++) { random_shuffle(randomLeaf.begin(), randomLeaf.end()); @@ -491,7 +495,7 @@ int PhyloDiversityCommand::driver(Tree* t, map< string, vector >& div, ma //initialize counts map counts; map< string, set > countedBranch; - for (int j = 0; j < m->Groups.size(); j++) { counts[m->Groups[j]] = 0; countedBranch[m->Groups[j]].insert(-2); } //add dummy index to initialize countedBranch sets + for (int j = 0; j < mGroups.size(); j++) { counts[mGroups[j]] = 0; countedBranch[mGroups[j]].insert(-2); } //add dummy index to initialize countedBranch sets for(int k = 0; k < numLeafNodes; k++){ @@ -522,9 +526,9 @@ int PhyloDiversityCommand::driver(Tree* t, map< string, vector >& div, ma if (rarefy) { //add this diversity to the sum - for (int j = 0; j < m->Groups.size(); j++) { - for (int g = 0; g < div[m->Groups[j]].size(); g++) { - sumDiv[m->Groups[j]][g] += div[m->Groups[j]][g]; + for (int j = 0; j < mGroups.size(); j++) { + for (int g = 0; g < div[mGroups[j]].size(); g++) { + sumDiv[mGroups[j]][g] += div[mGroups[j]][g]; } } } @@ -550,15 +554,16 @@ void PhyloDiversityCommand::printSumData(map< string, vector >& div, ofst out << "Groups\tnumSampled\tphyloDiversity" << endl; out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); - - for (int j = 0; j < m->Groups.size(); j++) { - int numSampled = (div[m->Groups[j]].size()-1); - out << m->Groups[j] << '\t' << numSampled << '\t'; + + vector mGroups = m->getGroups(); + for (int j = 0; j < mGroups.size(); j++) { + int numSampled = (div[mGroups[j]].size()-1); + out << mGroups[j] << '\t' << numSampled << '\t'; float score; - if (scale) { score = (div[m->Groups[j]][numSampled] / (float)numIters) / (float)numSampled; } - else { score = div[m->Groups[j]][numSampled] / (float)numIters; } + if (scale) { score = (div[mGroups[j]][numSampled] / (float)numIters) / (float)numSampled; } + else { score = div[mGroups[j]][numSampled] / (float)numIters; } out << setprecision(4) << score << endl; } @@ -577,7 +582,8 @@ void PhyloDiversityCommand::printData(set& num, map< string, vector try { out << "numSampled\t"; - for (int i = 0; i < m->Groups.size(); i++) { out << m->Groups[i] << '\t'; } + vector mGroups = m->getGroups(); + for (int i = 0; i < mGroups.size(); i++) { out << mGroups[i] << '\t'; } out << endl; out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); @@ -586,12 +592,12 @@ void PhyloDiversityCommand::printData(set& num, map< string, vector int numSampled = *it; out << numSampled << '\t'; - - for (int j = 0; j < m->Groups.size(); j++) { - if (numSampled < div[m->Groups[j]].size()) { + + for (int j = 0; j < mGroups.size(); j++) { + if (numSampled < div[mGroups[j]].size()) { float score; - if (scale) { score = (div[m->Groups[j]][numSampled] / (float)numIters) / (float)numSampled; } - else { score = div[m->Groups[j]][numSampled] / (float)numIters; } + if (scale) { score = (div[mGroups[j]][numSampled] / (float)numIters) / (float)numSampled; } + else { score = div[mGroups[j]][numSampled] / (float)numIters; } out << setprecision(4) << score << '\t'; }else { out << "NA" << '\t'; }