X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=rarefactcommand.cpp;h=612e3b4d2a8d1632e1c0f44937be52ce84d28fec;hb=ce8794490ab1d83adcdb2b92e0302a1e43e17adf;hp=b3d359ca53aa31fa10fe209cf0cd52946c2fd79b;hpb=a5d3e10e24e503483d8e85b54f0fd34b9308d31b;p=mothur.git diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index b3d359c..612e3b4 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -74,6 +74,39 @@ string RareFactCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string RareFactCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "rarefaction") { outputFileName = "rarefaction"; } + else if (type == "r_chao") { outputFileName = "r_chao"; } + else if (type == "r_ace") { outputFileName = "r_ace"; } + else if (type == "r_jack") { outputFileName = "r_jack"; } + else if (type == "r_shannon") { outputFileName = "r_shannon"; } + else if (type == "r_shannoneven") { outputFileName = "r_shannoneven"; } + else if (type == "r_smithwilson") { outputFileName = "r_smithwilson"; } + else if (type == "r_npshannon") { outputFileName = "r_npshannon"; } + else if (type == "r_simpson") { outputFileName = "r_simpson"; } + else if (type == "r_simpsoneven") { outputFileName = "r_simpsoneven"; } + else if (type == "r_invsimpson") { outputFileName = "r_invsimpson"; } + else if (type == "r_bootstrap") { outputFileName = "r_bootstrap"; } + else if (type == "r_coverage") { outputFileName = "r_coverage"; } + else if (type == "r_nseqs") { outputFileName = "r_nseqs"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "RareFactCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** RareFactCommand::RareFactCommand(){ @@ -282,10 +315,11 @@ int RareFactCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } + map > labelToEnds; if ((format != "sharedfile")) { inputFileNames.push_back(inputfile); } - else { inputFileNames = parseSharedFile(sharedfile); format = "rabund"; } - - if (m->control_pressed) { return 0; } + else { inputFileNames = parseSharedFile(sharedfile, labelToEnds); format = "rabund"; } + + if (m->control_pressed) { return 0; } map file2Group; //index in outputNames[i] -> group for (int p = 0; p < inputFileNames.size(); p++) { @@ -304,52 +338,52 @@ int RareFactCommand::execute(){ for (i=0; i 1) { file2Group[outputNames.size()-1] = groups[p]; } } @@ -378,7 +412,10 @@ int RareFactCommand::execute(){ if(allLines == 1 || labels.count(order->getLabel()) == 1){ m->mothurOut(order->getLabel()); m->mothurOutEndLine(); - rCurve = new Rarefact(order, rDisplays, processors); + map >::iterator itEndings = labelToEnds.find(order->getLabel()); + set ends; + if (itEndings != labelToEnds.end()) { ends = itEndings->second; } + rCurve = new Rarefact(order, rDisplays, processors, ends); rCurve->getCurve(freq, nIters); delete rCurve; @@ -393,7 +430,11 @@ int RareFactCommand::execute(){ order = (input->getOrderVector(lastLabel)); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); - rCurve = new Rarefact(order, rDisplays, processors); + map >::iterator itEndings = labelToEnds.find(order->getLabel()); + set ends; + if (itEndings != labelToEnds.end()) { ends = itEndings->second; } + rCurve = new Rarefact(order, rDisplays, processors, ends); + rCurve->getCurve(freq, nIters); delete rCurve; @@ -433,7 +474,11 @@ int RareFactCommand::execute(){ order = (input->getOrderVector(lastLabel)); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); - rCurve = new Rarefact(order, rDisplays, processors); + map >::iterator itEndings = labelToEnds.find(order->getLabel()); + set ends; + if (itEndings != labelToEnds.end()) { ends = itEndings->second; } + rCurve = new Rarefact(order, rDisplays, processors, ends); + rCurve->getCurve(freq, nIters); delete rCurve; @@ -625,7 +670,7 @@ vector RareFactCommand::createGroupFile(vector& outputNames, map } } //********************************************************************************************************************** -vector RareFactCommand::parseSharedFile(string filename) { +vector RareFactCommand::parseSharedFile(string filename, map >& label2Ends) { try { vector filenames; @@ -657,6 +702,7 @@ vector RareFactCommand::parseSharedFile(string filename) { m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()])); rav.print(*(filehandles[lookup[i]->getGroup()])); (*(filehandles[lookup[i]->getGroup()])).close(); + label2Ends[lookup[i]->getLabel()].insert(rav.getNumSeqs()); } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }