RAbundVector ListVector::getRAbundVector() { try { RAbundVector rav; for(int i=0; i<data.size(); i++) { int binSize = m->getNumNames(data[i]); rav.push_back(binSize); } // This was here before to output data in a nice format, but it screws up the name mapping steps // sort(rav.rbegin(), rav.rend()); // // for(int i=data.size()-1;i>=0;i--){ // if(rav.get(i) == 0){ rav.pop_back(); } // else{ // break; // } // } rav.setLabel(label); return rav; } catch(exception& e) { m->errorOut(e, "ListVector", "getRAbundVector"); exit(1); } }
RAbundVector SAbundVector::getRAbundVector(){ try { RAbundVector rav; for(int i=1;i < data.size();i++){ for(int j=0;j<data[i];j++){ rav.push_back(i); } } sort(rav.rbegin(), rav.rend()); rav.setLabel(label); return rav; } catch(exception& e) { m->errorOut(e, "SAbundVector", "getRAbundVector"); exit(1); } }
//********************************************************************************************************************** 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); } }