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); } }
RAbundVector Geom::getRAbundVector(SAbundVector* rank){ vector <int> rData; int mr = 1; int nb = 0; int ns = 0; for(int i = rank->size()-1; i > 0; i--) { int cur = rank->get(i); if(mr == 1 && cur > 0) mr = i; nb += cur; ns += i*cur; for(int j = 0; j < cur; j++) rData.push_back(i); } RAbundVector rav = RAbundVector(rData, mr, nb, ns); rav.setLabel(rank->getLabel()); return rav; }
int GetRAbundCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } map<string, string> variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); filename = getOutputFileName("rabund", variables); m->openOutputFile(filename, out); if (countfile != "") { processList(out); }else { InputData input(inputfile, format); RAbundVector* rabund = input.getRAbundVector(); string lastLabel = rabund->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set<string> processedLabels; set<string> userLabels = labels; if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; } while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); } 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(); if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); //restore real lastlabel to save below rabund->setLabel(saveLabel); } lastLabel = rabund->getLabel(); delete rabund; rabund = input.getRAbundVector(); } //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(); if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } delete rabund; } } if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["rabund"].push_back(filename); m->mothurOutEndLine(); out.close(); //set rabund file as new current rabundfile string current = ""; itTypes = outputTypes.find("rabund"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); } } return 0; } catch(exception& e) { m->errorOut(e, "GetRAbundCommand", "execute"); 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); } }