X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=collect.cpp;h=9a89020efe91f8bdd2733a3de553611e86ee6da3;hp=2ed5ca7f10eeefdb860ae9fc7b5859b5eb239c0e;hb=615301e57c25e241356a9c2380648d117709458d;hpb=44c1323a88b2a697c7047df1b3bb8c59eadd15b1 diff --git a/collect.cpp b/collect.cpp index 2ed5ca7..9a89020 100644 --- a/collect.cpp +++ b/collect.cpp @@ -9,161 +9,215 @@ #include "collect.h" - /***********************************************************************/ -void Collect::getCurve(int increment = 1){ - try { - RAbundVector* lookup = new RAbundVector(order->getNumBins()); - SAbundVector* rank = new SAbundVector(order->getMaxRank()+1); - - CollectorsCurveData* ccd = new CollectorsCurveData(); - - for(int i=0;iregisterDisplay(displays[i]); //adds a display[i] to cdd - displays[i]->init(label); //sets displays label - } - for(int i=0;iget(i); - int abundance = lookup->get(binNumber); - - rank->set(abundance, rank->get(abundance)-1); - - abundance++; - - lookup->set(binNumber, abundance); - rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance) - - if((i == 0) || (i+1) % increment == 0){ - ccd->updateRankData(rank); - } - } - - if(numSeqs % increment != 0){ - ccd->updateRankData(rank); - } - - for(int i=0;ireset(); - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Collect class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - +int Collect::getCurve(float percentFreq = 0.01){ + try { + RAbundVector* lookup = new RAbundVector(order->getNumBins()); + SAbundVector* rank = new SAbundVector(order->getMaxRank()+1); + + CollectorsCurveData* ccd = new CollectorsCurveData(); + + for(int i=0;iregisterDisplay(displays[i]); //adds a display[i] to cdd + displays[i]->init(label); //sets displays label + } + + //convert freq percentage to number + int increment = 1; + if (percentFreq < 1.0) { increment = numSeqs * percentFreq; } + else { increment = percentFreq; } + + for(int i=0;icontrol_pressed) { delete lookup; delete rank; delete ccd; return 1; } + + int binNumber = order->get(i); + int abundance = lookup->get(binNumber); + + rank->set(abundance, rank->get(abundance)-1); + + abundance++; + + lookup->set(binNumber, abundance); + rank->set(abundance, rank->get(abundance)+1); //increment rank(abundance) + + if((i == 0) || (i+1) % increment == 0){ + ccd->updateRankData(rank); + } + } + + if(numSeqs % increment != 0){ + ccd->updateRankData(rank); + } + + for(int i=0;ireset(); + } + + delete lookup; + delete rank; + delete ccd; + + return 0; + } + catch(exception& e) { + m->errorOut(e, "Collect", "getCurve"); + exit(1); + } } /***********************************************************************/ -void Collect::getSharedCurve(int increment = 1){ +int Collect::getSharedCurve(float percentFreq = 0.01){ try { - globaldata = GlobalData::getInstance(); - vector lookup; - - //create and initialize vector of sharedvectors, one for each group - for (int i = 0; i < globaldata->gGroupmap->getNumGroups(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins()); - temp->setLabel(sharedorder->getLabel()); - temp->setGroup(globaldata->gGroupmap->namesOfGroups[i]); - temp->setGroupIndex(globaldata->gGroupmap->groupIndex[globaldata->gGroupmap->namesOfGroups[i]]); - lookup.push_back(temp); - } - - SharedCollectorsCurveData* ccd = new SharedCollectorsCurveData(); + vector lookup; + vector subset; + + //create and initialize vector of sharedvectors, one for each group + vector mGroups = m->getGroups(); + for (int i = 0; i < mGroups.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins()); + temp->setLabel(sharedorder->getLabel()); + temp->setGroup(mGroups[i]); + lookup.push_back(temp); + } - //initialize labels for output - //makes 'uniqueAB uniqueAC uniqueBC' if your groups are A, B, C - getGroupComb(); - groupLabel = ""; - for (int s = 0; s < groupComb.size(); s++) { - groupLabel = groupLabel + label + groupComb[s] + "\t"; - } - - for(int i=0;iregisterDisplay(displays[i]); //adds a display[i] to cdd - displays[i]->init(groupLabel); - } - - //sample all the members - for(int i=0;iget(i); - 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; - } - } - - //calculate at 0 and the given increment - if((i == 0) || (i+1) % increment == 0){ - //randomize group order - if (globaldata->getJumble() == "1") { random_shuffle(lookup.begin(), lookup.end()); } - //how many comparisons to make i.e. for group a, b, c = ab, ac, bc. - int n = 1; - for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare - for (int l = n; l < lookup.size(); l++) { - ccd->updateSharedData(lookup[k], lookup[l], i+1, globaldata->gGroupmap->namesOfGroups.size()); - } - n++; - } - } - totalNumSeq = i+1; - } - - //calculate last line if you haven't already - if(numSeqs % increment != 0){ - //how many comparisons to make i.e. for group a, b, c = ab, ac, bc. - int n = 1; - for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare - for (int l = n; l < lookup.size(); l++) { - ccd->updateSharedData(lookup[k], lookup[l], totalNumSeq, globaldata->gGroupmap->namesOfGroups.size()); + SharedCollectorsCurveData* ccd = new SharedCollectorsCurveData(); + + //initialize labels for output + //makes 'uniqueAB uniqueAC uniqueBC' if your groups are A, B, C + getGroupComb(); + + for(int i=0;iregisterDisplay(displays[i]); //adds a display[i] to cdd + bool hasLciHci = displays[i]->hasLciHci(); + groupLabel = ""; + for (int s = 0; s < groupComb.size(); s++) { + if (hasLciHci) { groupLabel = groupLabel + label + groupComb[s] + "\t" + label + groupComb[s] + "lci\t" + label + groupComb[s] + "hci\t"; } + else{ groupLabel = groupLabel + label + groupComb[s] + "\t"; } + } + + string groupLabelAll = groupLabel + label + "all\t"; + if ((displays[i]->isCalcMultiple() == true) && (displays[i]->getAll() == true)) { displays[i]->init(groupLabelAll); } + else { displays[i]->init(groupLabel); } + } + + //convert freq percentage to number + int increment = 1; + if (percentFreq < 1.0) { increment = numSeqs * percentFreq; } + else { increment = percentFreq; } + + //sample all the members + for(int i=0;icontrol_pressed) { for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } delete ccd; return 1; } + + //get first sample + individual chosen = sharedorder->get(i); + 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; + } + } + + //calculate at 0 and the given increment + if((i == 0) || (i+1) % increment == 0){ + + //how many comparisons to make i.e. for group a, b, c = ab, ac, bc. + + int n = 1; + bool pair = true; + for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare + for (int l = n; l < lookup.size(); l++) { + subset.clear(); //clear out old pair of sharedrabunds + //add new pair of sharedrabund vectors + subset.push_back(lookup[k]); subset.push_back(lookup[l]); + + //load subset with rest of lookup for those calcs that need everyone to calc for a pair + for (int w = 0; w < lookup.size(); w++) { + if ((w != k) && (w != l)) { subset.push_back(lookup[w]); } + } + + ccd->updateSharedData(subset, i+1, m->getNumGroups(), pair); + } + n++; + } + + //if this is a calculator that can do multiples then do them + pair = false; + ccd->updateSharedData(lookup, i+1, m->getNumGroups(), pair); + + } + totalNumSeq = i+1; + } + + //calculate last label if you haven't already + if(numSeqs % increment != 0){ + //how many comparisons to make i.e. for group a, b, c = ab, ac, bc. + int n = 1; + bool pair = true; + for (int k = 0; k < (lookup.size() - 1); k++) { // pass cdd each set of groups to commpare + for (int l = n; l < lookup.size(); l++) { + subset.clear(); //clear out old pair of sharedrabunds + //add new pair of sharedrabund vectors + subset.push_back(lookup[k]); subset.push_back(lookup[l]); + + //load subset with rest of lookup for those calcs that need everyone to calc for a pair + for (int w = 0; w < lookup.size(); w++) { + if ((w != k) && (w != l)) { subset.push_back(lookup[w]); } + } + + ccd->updateSharedData(subset, totalNumSeq, m->getNumGroups(), pair); + } + n++; + } + //if this is a calculator that can do multiples then do them + pair = false; + ccd->updateSharedData(lookup, totalNumSeq, m->getNumGroups(), pair); + } + + //resets output files + for(int i=0;ireset(); + } + + //memory cleanup + delete ccd; + for (int i = 0; i < lookup.size(); i++) { + delete lookup[i]; } - n++; - } - } - - //resets output files - for(int i=0;ireset(); - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Collect class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Collect class function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "Collect", "getSharedCurve"); + exit(1); + } } /**************************************************************************************/ void Collect::getGroupComb() { - string group; - - numGroupComb = 0; - - int n = 1; - for (int i = 0; i < (globaldata->gGroupmap->getNumGroups() - 1); i++) { - for (int l = n; l < globaldata->gGroupmap->getNumGroups(); l++) { - group = globaldata->gGroupmap->namesOfGroups[i] + globaldata->gGroupmap->namesOfGroups[l]; - groupComb.push_back(group); - numGroupComb++; - } - n++; + string group; + + numGroupComb = 0; + + int n = 1; + vector mGroups = m->getGroups(); + for (int i = 0; i < (m->getNumGroups() - 1); i++) { + for (int l = n; l < m->getNumGroups(); l++) { + group = mGroups[i] + mGroups[l]; + groupComb.push_back(group); + numGroupComb++; } + n++; + } }