OrderVector SAbundVector::getOrderVector(map<string,int>* hold = NULL){ try { OrderVector ov; int binIndex = 0; for(int i=1;i<data.size();i++){ for(int j=0;j<data[i];j++){ for(int k=0;k<i;k++){ ov.push_back(binIndex); } binIndex++; } } random_shuffle(ov.begin(), ov.end()); ov.setLabel(label); ov.getNumBins(); return ov; } catch(exception& e) { m->errorOut(e, "SAbundVector", "getOrderVector"); exit(1); } }
OrderVector ListVector::getOrderVector(map<string,int>* orderMap = NULL) { try { if(orderMap == NULL) { OrderVector ov; for(int i=0; i<data.size(); i++) { int binSize = m->getNumNames(data[i]); for(int j=0; j<binSize; j++) { ov.push_back(i); } } random_shuffle(ov.begin(), ov.end()); ov.setLabel(label); ov.getNumBins(); return ov; } else { OrderVector ov(numSeqs); for(int i=0; i<data.size(); i++) { string listOTU = data[i]; int length = listOTU.size(); string seqName=""; for(int j=0; j<length; j++) { if(listOTU[j] != ',') { seqName += listOTU[j]; } else { if(orderMap->count(seqName) == 0) { m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } ov.set((*orderMap)[seqName], i); seqName = ""; } } if(orderMap->count(seqName) == 0) { m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } ov.set((*orderMap)[seqName], i); } ov.setLabel(label); ov.getNumBins(); return ov; } } catch(exception& e) { m->errorOut(e, "ListVector", "getOrderVector"); exit(1); } }
int RareFactCommand::execute(){ try { if (abort) { if (calledHelp) { return 0; } return 2; } long start = time(NULL); map<string, set<int> > labelToEnds; if ((format != "sharedfile")) { inputFileNames.push_back(inputfile); } else { inputFileNames = parseSharedFile(sharedfile, labelToEnds); format = "rabund"; } if (m->getControl_pressed()) { return 0; } map<int, string> file2Group; //index in outputNames[i] -> group for (int p = 0; p < inputFileNames.size(); p++) { string fileNameRoot = outputDir + util.getRootName(util.getSimpleName(inputFileNames[p])); if (m->getControl_pressed()) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; } if (inputFileNames.size() > 1) { m->mothurOutEndLine(); m->mothurOut("Processing group " + Groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); } int i; ValidCalculators validCalculator; map<string, string> variables; variables["[filename]"] = fileNameRoot; for (i=0; i<Estimators.size(); i++) { if (validCalculator.isValidCalculator("rarefaction", Estimators[i]) ) { if (Estimators[i] == "sobs") { rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(getOutputFileName("rarefaction",variables)))); outputNames.push_back(getOutputFileName("rarefaction",variables)); outputTypes["rarefaction"].push_back(getOutputFileName("rarefaction",variables)); }else if (Estimators[i] == "chao") { rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(getOutputFileName("r_chao",variables)))); outputNames.push_back(getOutputFileName("r_chao",variables)); outputTypes["r_chao"].push_back(getOutputFileName("r_chao",variables)); }else if (Estimators[i] == "ace") { if(abund < 5) abund = 10; rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(getOutputFileName("r_ace",variables)))); outputNames.push_back(getOutputFileName("r_ace",variables)); outputTypes["r_ace"].push_back(getOutputFileName("r_ace",variables)); }else if (Estimators[i] == "jack") { rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(getOutputFileName("r_jack",variables)))); outputNames.push_back(getOutputFileName("r_jack",variables)); outputTypes["r_jack"].push_back(getOutputFileName("r_jack",variables)); }else if (Estimators[i] == "shannon") { rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(getOutputFileName("r_shannon",variables)))); outputNames.push_back(getOutputFileName("r_shannon",variables)); outputTypes["r_shannon"].push_back(getOutputFileName("r_shannon",variables)); }else if (Estimators[i] == "shannoneven") { rDisplays.push_back(new RareDisplay(new ShannonEven(), new ThreeColumnFile(getOutputFileName("r_shannoneven",variables)))); outputNames.push_back(getOutputFileName("r_shannoneven",variables)); outputTypes["r_shannoneven"].push_back(getOutputFileName("r_shannoneven",variables)); }else if (Estimators[i] == "heip") { rDisplays.push_back(new RareDisplay(new Heip(), new ThreeColumnFile(getOutputFileName("r_heip",variables)))); outputNames.push_back(getOutputFileName("r_heip",variables)); outputTypes["r_heip"].push_back(getOutputFileName("r_heip",variables)); }else if (Estimators[i] == "r_shannonrange") { rDisplays.push_back(new RareDisplay(new RangeShannon(alpha), new ThreeColumnFile(getOutputFileName("r_shannonrange", variables)))); outputNames.push_back(getOutputFileName("r_shannonrange", variables)); outputTypes["r_shannoneven"].push_back(getOutputFileName("r_shannonrange", variables)); }else if (Estimators[i] == "smithwilson") { rDisplays.push_back(new RareDisplay(new SmithWilson(), new ThreeColumnFile(getOutputFileName("r_smithwilson",variables)))); outputNames.push_back(getOutputFileName("r_smithwilson",variables)); outputTypes["r_smithwilson"].push_back(getOutputFileName("r_smithwilson",variables)); }else if (Estimators[i] == "npshannon") { rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(getOutputFileName("r_npshannon",variables)))); outputNames.push_back(getOutputFileName("r_npshannon",variables)); outputTypes["r_npshannon"].push_back(getOutputFileName("r_npshannon",variables)); }else if (Estimators[i] == "simpson") { rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(getOutputFileName("r_simpson",variables)))); outputNames.push_back(getOutputFileName("r_simpson",variables)); outputTypes["r_simpson"].push_back(getOutputFileName("r_simpson",variables)); }else if (Estimators[i] == "simpsoneven") { rDisplays.push_back(new RareDisplay(new SimpsonEven(), new ThreeColumnFile(getOutputFileName("r_simpsoneven",variables)))); outputNames.push_back(getOutputFileName("r_simpsoneven",variables)); outputTypes["r_simpsoneven"].push_back(getOutputFileName("r_simpsoneven",variables)); }else if (Estimators[i] == "invsimpson") { rDisplays.push_back(new RareDisplay(new InvSimpson(), new ThreeColumnFile(getOutputFileName("r_invsimpson",variables)))); outputNames.push_back(getOutputFileName("r_invsimpson",variables)); outputTypes["r_invsimpson"].push_back(getOutputFileName("r_invsimpson",variables)); }else if (Estimators[i] == "bootstrap") { rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(getOutputFileName("r_bootstrap",variables)))); outputNames.push_back(getOutputFileName("r_bootstrap",variables)); outputTypes["r_bootstrap"].push_back(getOutputFileName("r_bootstrap",variables)); }else if (Estimators[i] == "coverage") { rDisplays.push_back(new RareDisplay(new Coverage(), new ThreeColumnFile(getOutputFileName("r_coverage",variables)))); outputNames.push_back(getOutputFileName("r_coverage",variables)); outputTypes["r_coverage"].push_back(getOutputFileName("r_coverage",variables)); }else if (Estimators[i] == "nseqs") { rDisplays.push_back(new RareDisplay(new NSeqs(), new ThreeColumnFile(getOutputFileName("r_nseqs",variables)))); outputNames.push_back(getOutputFileName("r_nseqs",variables)); outputTypes["r_nseqs"].push_back(getOutputFileName("r_nseqs",variables)); } if (inputFileNames.size() > 1) { file2Group[outputNames.size()-1] = Groups[p]; } } } //if the users entered no valid calculators don't execute command if (rDisplays.size() == 0) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } return 0; } InputData input(inputFileNames[p], format, nullVector); OrderVector* order = input.getOrderVector(); string lastLabel = order->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->getControl_pressed()) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete order; for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; } //as long as you are not at the end of the file or done wih the lines you want while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->getControl_pressed()) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } delete order; for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; } if(allLines == 1 || labels.count(order->getLabel()) == 1){ m->mothurOut(order->getLabel()); m->mothurOutEndLine(); map<string, set<int> >::iterator itEndings = labelToEnds.find(order->getLabel()); set<int> ends; if (itEndings != labelToEnds.end()) { ends = itEndings->second; } rCurve = new Rarefact(*order, rDisplays, ends, processors); rCurve->getCurve(freq, nIters); delete rCurve; processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); } if ((util.anyLabelsToProcess(order->getLabel(), userLabels, "") ) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = order->getLabel(); delete order; order = (input.getOrderVector(lastLabel)); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); map<string, set<int> >::iterator itEndings = labelToEnds.find(order->getLabel()); set<int> ends; if (itEndings != labelToEnds.end()) { ends = itEndings->second; } rCurve = new Rarefact(*order, rDisplays, ends, processors); rCurve->getCurve(freq, nIters); delete rCurve; processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); //restore real lastlabel to save below order->setLabel(saveLabel); } lastLabel = order->getLabel(); delete order; order = (input.getOrderVector()); } if (m->getControl_pressed()) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } 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(); } } if (m->getControl_pressed()) { for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; } //run last label if you need to if (needToRun ) { if (order != NULL) { delete order; } order = (input.getOrderVector(lastLabel)); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); map<string, set<int> >::iterator itEndings = labelToEnds.find(order->getLabel()); set<int> ends; if (itEndings != labelToEnds.end()) { ends = itEndings->second; } rCurve = new Rarefact(*order, rDisplays, ends, processors); rCurve->getCurve(freq, nIters); delete rCurve; delete order; } for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; } rDisplays.clear(); } if (m->getControl_pressed()) { for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; } //create summary file containing all the groups data for each label - this function just combines the info from the files already created. if ((sharedfile != "") && (groupMode)) { outputNames = createGroupFile(outputNames, file2Group); } if (m->getControl_pressed()) { for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; } m->mothurOut("\nIt took " + toString(time(NULL) - start) + " secs to run rarefaction.single.\n"); m->mothurOut("\nOutput File Names: \n"); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i] +"\n"); } m->mothurOutEndLine(); return 0; } catch(exception& e) { m->errorOut(e, "RareFactCommand", "execute"); exit(1); } }