X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=subsample.cpp;h=261297df67cfc1c5a8933a72f8bba307defbef88;hb=2ecee16fec29d4c525f740ec19b27962ca09c050;hp=457b7b9d5f6a1273b57e898b3adec90dff5dd9f0;hpb=f6b5fea6e0fcc395235dfbfb466b9b6a031b540a;p=mothur.git diff --git a/subsample.cpp b/subsample.cpp index 457b7b9..261297d 100644 --- a/subsample.cpp +++ b/subsample.cpp @@ -250,7 +250,7 @@ vector SubSample::getSample(vector& thislookup, int //subsampling may have created some otus with no sequences in them eliminateZeroOTUS(thislookup); - + if (m->control_pressed) { return m->currentBinLabels; } //save mothurOut's binLabels to restore for next label @@ -322,8 +322,51 @@ int SubSample::eliminateZeroOTUS(vector& thislookup) { exit(1); } } +//********************************************************************************************************************** +int SubSample::getSample(SAbundVector*& sabund, int size) { + try { + + OrderVector* order = new OrderVector(); + *order = sabund->getOrderVector(NULL); + + int numBins = order->getNumBins(); + int thisSize = order->getNumSeqs(); + + if (thisSize > size) { + random_shuffle(order->begin(), order->end()); + + RAbundVector* rabund = new RAbundVector(numBins); + rabund->setLabel(order->getLabel()); - + for (int j = 0; j < size; j++) { + + if (m->control_pressed) { delete order; delete rabund; return 0; } + + int bin = order->get(j); + + int abund = rabund->get(bin); + rabund->set(bin, (abund+1)); + } + + delete sabund; + sabund = new SAbundVector(); + *sabund = rabund->getSAbundVector(); + delete rabund; + + }else if (thisSize < size) { m->mothurOut("[ERROR]: The size you requested is larger than the number of sequences in the sabund vector. You requested " + toString(size) + " and you only have " + toString(thisSize) + " seqs in your sabund vector.\n"); m->control_pressed = true; } + + if (m->control_pressed) { return 0; } + + delete order; + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "SubSampleCommand", "getSample"); + exit(1); + } +} //**********************************************************************************************************************