TEST(Test_Container_SharedRabundVector, GetRabundVector) { vector<int> abunds(10, 10); SharedRAbundVector temp(abunds); EXPECT_EQ(temp.getNumBins(), 10); EXPECT_EQ(temp.getNumSeqs(), 100); EXPECT_EQ(temp.getMaxRank(), 10); RAbundVector rabund = temp.getRAbundVector(); EXPECT_EQ(rabund.getNumBins(), 10); EXPECT_EQ(rabund.getNumSeqs(), 100); EXPECT_EQ(rabund.getMaxRank(), 10); }
//********************************************************************************************************************** int RemoveRareCommand::processRabund(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); } string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "pick" + m->getExtension(rabundfile); outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. InputData input(rabundfile, "rabund"); RAbundVector* rabund = input.getRAbundVector(); string lastLabel = rabund->getLabel(); set<string> processedLabels; set<string> userLabels = labels; while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { delete rabund; out.close(); return 0; } if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); RAbundVector newRabund; newRabund.setLabel(rabund->getLabel()); for (int i = 0; i < rabund->getNumBins(); i++) { if (rabund->get(i) > nseqs) { newRabund.push_back(rabund->get(i)); } } if (newRabund.getNumBins() > 0) { newRabund.print(out); } } if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = rabund->getLabel(); delete rabund; rabund = input.getRAbundVector(lastLabel); m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); RAbundVector newRabund; newRabund.setLabel(rabund->getLabel()); for (int i = 0; i < rabund->getNumBins(); i++) { if (rabund->get(i) > nseqs) { newRabund.push_back(rabund->get(i)); } } if (newRabund.getNumBins() > 0) { newRabund.print(out); } //restore real lastlabel to save below rabund->setLabel(saveLabel); } lastLabel = rabund->getLabel(); delete rabund; rabund = input.getRAbundVector(); } if (m->control_pressed) { out.close(); return 0; } //output error messages about any remaining user labels set<string>::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } //run last label if you need to if (needToRun == true) { if (rabund != NULL) { delete rabund; } rabund = input.getRAbundVector(lastLabel); m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); RAbundVector newRabund; newRabund.setLabel(rabund->getLabel()); for (int i = 0; i < rabund->getNumBins(); i++) { if (rabund->get(i) > nseqs) { newRabund.push_back(rabund->get(i)); } } if (newRabund.getNumBins() > 0) { newRabund.print(out); } delete rabund; } return 0; } catch(exception& e) { m->errorOut(e, "RemoveRareCommand", "processRabund"); exit(1); } }