X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=rarefact.cpp;h=691d01708bab5b5bef4118ab38662819280b56de;hb=8ab46c171b45ae3782d839539792d049017a361b;hp=cb4bbbce9a4047ae08b5f37b807be3f78c255d89;hpb=599af78a6ea4916919d460a131e2d0dffa28d35e;p=mothur.git diff --git a/rarefact.cpp b/rarefact.cpp index cb4bbbc..691d017 100644 --- a/rarefact.cpp +++ b/rarefact.cpp @@ -12,13 +12,18 @@ /***********************************************************************/ -void Rarefact::getCurve(int increment = 1, int nIters = 1000){ +int Rarefact::getCurve(float percentFreq = 0.01, int nIters = 1000){ try { RarefactionCurveData* rcd = new RarefactionCurveData(); for(int i=0;iregisterDisplay(displays[i]); } - + + //convert freq percentage to number + int increment = 1; + if (percentFreq < 1.0) { increment = numSeqs * percentFreq; } + else { increment = percentFreq; } + for(int iter=0;itercontrol_pressed) { delete lookup; delete rank; delete rcd; return 0; } + int binNumber = order->get(i); int abundance = lookup->get(binNumber); @@ -61,73 +68,65 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){ displays[i]->close(); } delete rcd; + return 0; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Rarefact class function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "Rarefact", "getCurve"); exit(1); } } /***********************************************************************/ -void Rarefact::getSharedCurve(int increment = 1, int nIters = 1000){ +int Rarefact::getSharedCurve(float percentFreq = 0.01, int nIters = 1000){ try { - globaldata = GlobalData::getInstance(); SharedRarefactionCurveData* rcd = new SharedRarefactionCurveData(); + label = lookup[0]->getLabel(); + //register the displays for(int i=0;iregisterDisplay(displays[i]); } - + + //if jumble is false all iters will be the same + if (globaldata->jumble == false) { nIters = 1; } + + //convert freq percentage to number + int increment = 1; + if (percentFreq < 1.0) { increment = numSeqs * percentFreq; } + else { increment = percentFreq; } + for(int iter=0;iterGroups.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins()); - temp->setLabel(sharedorder->getLabel()); - temp->setGroup(globaldata->Groups[i]); - lookup.push_back(temp); - } - for(int i=0;iinit(label); } - - //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; - } - } + + if (globaldata->jumble == true) { + //randomize the groups + random_shuffle(lookup.begin(), lookup.end()); } - //randomize the groups - random_shuffle(lookup.begin(), lookup.end()); + //make merge the size of lookup[0] + SharedRAbundVector* merge = new SharedRAbundVector(lookup[0]->size()); + + //make copy of lookup zero + for(int i = 0; isize(); i++) { + merge->set(i, lookup[0]->getAbundance(i), "merge"); + } vector subset; //send each group one at a time for (int k = 0; k < lookup.size(); k++) { + if (m->control_pressed) { delete merge; delete rcd; return 0; } + subset.clear(); //clears out old pair of sharedrabunds //add in new pair of sharedrabunds - subset.push_back(lookup[0]); subset.push_back(lookup[k]); + subset.push_back(merge); subset.push_back(lookup[k]); rcd->updateSharedData(subset, k+1, numGroupComb); - mergeVectors(lookup[0], lookup[k]); + mergeVectors(merge, lookup[k]); } //resets output files @@ -135,9 +134,7 @@ try { displays[i]->reset(); } - for (int i = 0; i < lookup.size(); i++) { - delete lookup[i]; - } + delete merge; } for(int i=0;ierrorOut(e, "Rarefact", "getSharedCurve"); exit(1); } - } /**************************************************************************************/ @@ -162,18 +155,12 @@ void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* sha try{ for (int k = 0; k < shared1->size(); k++) { //merge new species into shared1 - if ((shared1->getAbundance(k) == 0) && (shared2->getAbundance(k) != 0)) { - shared1->set(k, shared2->getAbundance(k), "combo"); //set to 'combo' since this vector now contains multiple groups - } + shared1->set(k, (shared1->getAbundance(k) + shared2->getAbundance(k)), "combo"); //set to 'combo' since this vector now contains multiple groups } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "Rarefact", "mergeVectors"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the Rarefact class function mergeVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } }