int Rarefact::driver(RarefactionCurveData* rcd, int increment, int nIters = 1000){ try { for(int iter=0;iter<nIters;iter++){ for(int i=0;i<displays.size();i++){ displays[i]->init(label); } RAbundVector* lookup = new RAbundVector(order->getNumBins()); SAbundVector* rank = new SAbundVector(order->getMaxRank()+1); random_shuffle(order->begin(), order->end()); for(int i=0;i<numSeqs;i++){ if (m->control_pressed) { delete lookup; delete rank; delete rcd; return 0; } 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); if((i == 0) || ((i+1) % increment == 0) || (ends.count(i+1) != 0)){ rcd->updateRankData(rank); } } if((numSeqs % increment != 0) || (ends.count(numSeqs) != 0)){ rcd->updateRankData(rank); } for(int i=0;i<displays.size();i++){ displays[i]->reset(); } delete lookup; delete rank; } return 0; } catch(exception& e) { m->errorOut(e, "Rarefact", "driver"); 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(); //sets displays label for(int i=0;i<displays.size();i++){ displays[i]->init(label); } ccd->registerDisplays(displays); //convert freq percentage to number int increment = 1; if (percentFreq < 1.0) { increment = numSeqs * percentFreq; } else { increment = percentFreq; } for(int i=0;i<numSeqs;i++){ if (m->getControl_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;i<displays.size();i++){ displays[i]->reset(); } delete lookup; delete rank; delete ccd; return 0; } catch(exception& e) { m->errorOut(e, "Collect", "getCurve"); exit(1); } }
TEST(Test_Container_SharedRabundVector, GetSabundVector) { vector<int> abunds(10, 5); SharedRAbundVector temp(abunds); EXPECT_EQ(temp.getNumBins(), 10); EXPECT_EQ(temp.getNumSeqs(), 50); EXPECT_EQ(temp.getMaxRank(), 5); SAbundVector sabund = temp.getSAbundVector(); EXPECT_EQ(sabund.getNumBins(), 10); EXPECT_EQ(sabund.getNumSeqs(), 50); EXPECT_EQ(sabund.getMaxRank(), 5); EXPECT_EQ(sabund.get(5), 10); }