From: SarahsWork Date: Wed, 3 Apr 2013 15:03:57 +0000 (-0400) Subject: added count file to get.sabund and get.rabund commands. fixed bug in windows paralell... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=b740fb182372143e152143c6cc5b9ac8591f09b7 added count file to get.sabund and get.rabund commands. fixed bug in windows paralellization of pairwise.seqs - cutoff was not passed to thread. added otulabels to shared file in remove.rare command. added check to make sure reorient is only used when paired barcodes are provided. --- diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index d5f5a8b..4870a62 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -13,6 +13,7 @@ vector GetRAbundCommand::setParameters(){ try { CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","rabund",false,false, true); parameters.push_back(plist); + CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false, false); parameters.push_back(pcount); CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","rabund",false,false, true); parameters.push_back(psabund); CommandParameter psorted("sorted", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(psorted); CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); @@ -32,7 +33,8 @@ vector GetRAbundCommand::setParameters(){ string GetRAbundCommand::getHelpString(){ try { string helpString = ""; - helpString += "The get.rabund command parameters are list, sabund, label and sorted. list or sabund parameters are required, unless you have valid current files.\n"; + helpString += "The get.rabund command parameters are list, sabund, count, label and sorted. list or sabund parameters are required, unless you have valid current files.\n"; + helpString += "The count parameter allows you to provide a count file associated with your list file. If you clustered with a countfile the list file only contains the unique sequences and you will want to add the redundant counts into the rabund file, providing the count file allows you to do so.\n"; helpString += "The label parameter allows you to select what distance levels you would like included in your .rabund file, and are separated by dashes.\n"; helpString += "The sorted parameters allows you to print the rabund results sorted by abundance or not. The default is sorted.\n"; helpString += "The get.rabund command should be in the following format: get.rabund(label=yourLabels, sorted=yourSorted).\n"; @@ -124,6 +126,14 @@ GetRAbundCommand::GetRAbundCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["sabund"] = inputDir + it->second; } } + + it = parameters.find("count"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["count"] = inputDir + it->second; } + } } @@ -137,6 +147,11 @@ GetRAbundCommand::GetRAbundCommand(string option) { if (sabundfile == "not open") { sabundfile = ""; abort = true; } else if (sabundfile == "not found") { sabundfile = ""; } else { format = "sabund"; inputfile = sabundfile; m->setSabundFile(sabundfile); } + + countfile = validParameter.validFile(parameters, "count", true); + if (countfile == "not open") { countfile = ""; abort = true; } + else if (countfile == "not found") { countfile = ""; } + else { m->setCountTableFile(countfile); } //check for optional parameter and set defaults @@ -168,7 +183,8 @@ GetRAbundCommand::GetRAbundCommand(string option) { } } - + if ((countfile != "") && (listfile == "")) { m->mothurOut("[ERROR]: You can only use the count file with a list file, aborting.\n"); abort = true; } + //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(inputfile); } @@ -193,84 +209,90 @@ int GetRAbundCommand::execute(){ filename = getOutputFileName("rabund", variables); m->openOutputFile(filename, out); - input = new InputData(inputfile, format); - 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 processedLabels; - set userLabels = labels; - - if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; delete input; return 0; } - - while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - - if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ + 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 processedLabels; + set 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 input; delete rabund; return 0; } + 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)) { + } + + if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = rabund->getLabel(); delete rabund; - rabund = input->getRAbundVector(lastLabel); + rabund = input.getRAbundVector(lastLabel); m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; delete rabund; return 0; } + 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(); + } + + lastLabel = rabund->getLabel(); + + delete rabund; + rabund = input.getRAbundVector(); + } + + //output error messages about any remaining user labels + set::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; + } } - - //output error messages about any remaining user labels - set::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 input; 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); @@ -293,6 +315,135 @@ int GetRAbundCommand::execute(){ exit(1); } } +//********************************************************************************************************************** +int GetRAbundCommand::processList(ofstream& out){ + try { + CountTable ct; + ct.readTable(countfile); + + InputData input(inputfile, format); + ListVector* list = input.getListVector(); + string lastLabel = list->getLabel(); + + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. + set processedLabels; + set userLabels = labels; + + if (m->control_pressed) { delete list; return 0; } + + while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + + if(allLines == 1 || labels.count(list->getLabel()) == 1){ + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); + + if (m->control_pressed) { delete list; return 0; } + + RAbundVector* rabund = new RAbundVector(); + createRabund(ct, list, rabund); + + if(sorted) { rabund->print(out); } + else { rabund->nonSortedPrint(out); } + + delete rabund; + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); + } + + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = list->getLabel(); + + delete list; + list = input.getListVector(lastLabel); + + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); + + if (m->control_pressed) { delete list; return 0; } + + RAbundVector* rabund = new RAbundVector(); + createRabund(ct, list, rabund); + + if(sorted) { rabund->print(out); } + else { rabund->nonSortedPrint(out); } + + delete rabund; + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); + + //restore real lastlabel to save below + list->setLabel(saveLabel); + } + + lastLabel = list->getLabel(); + + delete list; + list = input.getListVector(); + } + + //output error messages about any remaining user labels + set::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 (list != NULL) { delete list; } + list = input.getListVector(lastLabel); + + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); + + if (m->control_pressed) { delete list; return 0; } + + RAbundVector* rabund = new RAbundVector(); + createRabund(ct, list, rabund); + + if(sorted) { rabund->print(out); } + else { rabund->nonSortedPrint(out); } + + delete rabund; + delete list; + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "processList"); + exit(1); + } +} +//********************************************************************************************************************** + +int GetRAbundCommand::createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund){ + try { + + rabund->setLabel(list->getLabel()); + for(int i = 0; i < list->getNumBins(); i++) { + if (m->control_pressed) { return 0; } + vector binNames; + string bin = list->get(i); + m->splitAtComma(bin, binNames); + int total = 0; + for (int j = 0; j < binNames.size(); j++) { + total += ct.getNumSeqs(binNames[j]); + } + rabund->push_back(total); + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "createRabund"); + exit(1); + } + +} //********************************************************************************************************************** diff --git a/getrabundcommand.h b/getrabundcommand.h index dcf8c68..fd7a6b0 100644 --- a/getrabundcommand.h +++ b/getrabundcommand.h @@ -38,17 +38,16 @@ public: private: - string filename, listfile, sabundfile, inputfile, format, outputDir; + string filename, listfile, sabundfile, inputfile, format, outputDir, countfile; ofstream out; - InputData* input; - RAbundVector* rabund; vector outputNames; bool abort, allLines, sorted; set labels; //holds labels to be used string label; - + int processList(ofstream& out); + int createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund); }; #endif diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index 237506e..d3fb529 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -13,6 +13,7 @@ vector GetSAbundCommand::setParameters(){ try { CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(plist); + CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false, false); parameters.push_back(pcount); CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(prabund); CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); @@ -31,7 +32,8 @@ vector GetSAbundCommand::setParameters(){ string GetSAbundCommand::getHelpString(){ try { string helpString = ""; - helpString += "The get.sabund command parameters is list, rabund and label. list or rabund is required unless a valid current file exists.\n"; + helpString += "The get.sabund command parameters is list, rabund, count and label. list or rabund is required unless a valid current file exists.\n"; + helpString += "The count parameter allows you to provide a count file associated with your list file. If you clustered with a countfile the list file only contains the unique sequences and you will want to add the redundant counts into the sabund file, providing the count file allows you to do so.\n"; helpString += "The label parameter allows you to select what distance levels you would like included in your .sabund file, and are separated by dashes.\n"; helpString += "The get.sabund command should be in the following format: get.sabund(label=yourLabels).\n"; helpString += "Example get.sabund().\n"; @@ -121,6 +123,14 @@ GetSAbundCommand::GetSAbundCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["rabund"] = inputDir + it->second; } } + + it = parameters.find("count"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["count"] = inputDir + it->second; } + } } @@ -135,7 +145,11 @@ GetSAbundCommand::GetSAbundCommand(string option) { else if (rabundfile == "not found") { rabundfile = ""; } else { format = "rabund"; inputfile = rabundfile; m->setRabundFile(rabundfile); } - + countfile = validParameter.validFile(parameters, "count", true); + if (countfile == "not open") { countfile = ""; abort = true; } + else if (countfile == "not found") { countfile = ""; } + else { m->setCountTableFile(countfile); } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... label = validParameter.validFile(parameters, "label", false); @@ -161,6 +175,7 @@ GetSAbundCommand::GetSAbundCommand(string option) { } } + if ((countfile != "") && (listfile == "")) { m->mothurOut("[ERROR]: You can only use the count file with a list file, aborting.\n"); abort = true; } //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(inputfile); } @@ -185,84 +200,88 @@ int GetSAbundCommand::execute(){ filename = getOutputFileName("sabund", variables); m->openOutputFile(filename, out); - input = new InputData(inputfile, format); - sabund = input->getSAbundVector(); - string lastLabel = sabund->getLabel(); - - - //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. - set processedLabels; - set userLabels = labels; - - if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; delete input; return 0; } - - - while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - - if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ + if (countfile != "") { + processList(out); + }else { + InputData input(inputfile, format); + SAbundVector* sabund = input.getSAbundVector(); + string lastLabel = sabund->getLabel(); + + + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. + set processedLabels; + set userLabels = labels; + + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; return 0; } + + + while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + + if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); sabund->print(out); - if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; delete input; return 0; } - + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; return 0; } + processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); - } - - if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + } + + if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = sabund->getLabel(); - delete sabund; - sabund = (input->getSAbundVector(lastLabel)); + delete sabund; + sabund = (input.getSAbundVector(lastLabel)); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); sabund->print(out); - if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; delete input; return 0; } - + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; return 0; } + processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); //restore real lastlabel to save below sabund->setLabel(saveLabel); - } - - - lastLabel = sabund->getLabel(); - - delete sabund; - sabund = (input->getSAbundVector()); - } - - //output error messages about any remaining user labels - set::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(); - } + } + + + lastLabel = sabund->getLabel(); + + delete sabund; + sabund = (input.getSAbundVector()); + } + + //output error messages about any remaining user labels + set::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 (sabund != NULL) { delete sabund; } + sabund = (input.getSAbundVector(lastLabel)); + + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); + sabund->print(out); + delete sabund; + + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); return 0; } + + } } - - //run last label if you need to - if (needToRun == true) { - if (sabund != NULL) { delete sabund; } - sabund = (input->getSAbundVector(lastLabel)); - - m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); - sabund->print(out); - delete sabund; - - if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; return 0; } - - } - out.close(); - delete input; + + if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(filename); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -284,7 +303,135 @@ int GetSAbundCommand::execute(){ exit(1); } } +//********************************************************************************************************************** +int GetSAbundCommand::processList(ofstream& out){ + try { + CountTable ct; + ct.readTable(countfile); + + InputData input(inputfile, format); + ListVector* list = input.getListVector(); + string lastLabel = list->getLabel(); + + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. + set processedLabels; + set userLabels = labels; + + if (m->control_pressed) { delete list; return 0; } + + while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + + if(allLines == 1 || labels.count(list->getLabel()) == 1){ + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); + + if (m->control_pressed) { delete list; return 0; } + + RAbundVector* rabund = new RAbundVector(); + createRabund(ct, list, rabund); + SAbundVector sabund = rabund->getSAbundVector(); + sabund.print(out); + delete rabund; + + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); + } + + if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = list->getLabel(); + + delete list; + list = input.getListVector(lastLabel); + + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); + + if (m->control_pressed) { delete list; return 0; } + + RAbundVector* rabund = new RAbundVector(); + createRabund(ct, list, rabund); + SAbundVector sabund = rabund->getSAbundVector(); + sabund.print(out); + delete rabund; + + processedLabels.insert(list->getLabel()); + userLabels.erase(list->getLabel()); + + //restore real lastlabel to save below + list->setLabel(saveLabel); + } + + lastLabel = list->getLabel(); + + delete list; + list = input.getListVector(); + } + + //output error messages about any remaining user labels + set::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 (list != NULL) { delete list; } + list = input.getListVector(lastLabel); + + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); + + if (m->control_pressed) { delete list; return 0; } + + RAbundVector* rabund = new RAbundVector(); + createRabund(ct, list, rabund); + SAbundVector sabund = rabund->getSAbundVector(); + sabund.print(out); + delete rabund; + + delete list; + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "processList"); + exit(1); + } +} +//********************************************************************************************************************** + +int GetSAbundCommand::createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund){ + try { + + rabund->setLabel(list->getLabel()); + for(int i = 0; i < list->getNumBins(); i++) { + if (m->control_pressed) { return 0; } + vector binNames; + string bin = list->get(i); + m->splitAtComma(bin, binNames); + int total = 0; + for (int j = 0; j < binNames.size(); j++) { + total += ct.getNumSeqs(binNames[j]); + } + rabund->push_back(total); + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "createRabund"); + exit(1); + } + +} //********************************************************************************************************************** + + diff --git a/getsabundcommand.h b/getsabundcommand.h index 685f039..7242342 100644 --- a/getsabundcommand.h +++ b/getsabundcommand.h @@ -34,15 +34,16 @@ public: void help() { m->mothurOut(getHelpString()); } private: - string filename, format, inputfile, listfile, rabundfile, outputDir; + string filename, format, inputfile, listfile, rabundfile, outputDir, countfile; ofstream out; - InputData* input; - SAbundVector* sabund; vector outputNames; bool abort, allLines; set labels; //holds labels to be used string label; + + int processList(ofstream& out); + int createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund); }; diff --git a/pairwiseseqscommand.cpp b/pairwiseseqscommand.cpp index e937b16..c9e5ecf 100644 --- a/pairwiseseqscommand.cpp +++ b/pairwiseseqscommand.cpp @@ -564,7 +564,7 @@ void PairwiseSeqsCommand::createProcesses(string filename) { string extension = toString(i) + ".temp"; // Allocate memory for thread data. - pairwiseData* tempDist = new pairwiseData((filename+extension), align, "square", Estimators[0], countends, output, alignDB, m, lines[i+1].start, lines[i+1].end, match, misMatch, gapOpen, gapExtend, longestBase, i); + pairwiseData* tempDist = new pairwiseData((filename+extension), align, "square", Estimators[0], countends, output, alignDB, m, lines[i+1].start, lines[i+1].end, match, misMatch, gapOpen, gapExtend, longestBase, cutoff, i); pDataArray.push_back(tempDist); processIDS.push_back(i); @@ -643,8 +643,7 @@ int PairwiseSeqsCommand::driver(int startLine, int endLine, string dFileName, fl outFile << setprecision(4); if((output == "lt") && startLine == 0){ outFile << alignDB.getNumSeqs() << endl; } - int countSmall = 0; - int countAll = 0; + for(int i=startLine;imothurOut(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine(); - cout << "num less than 0.01 = " << countSmall << " of " << countAll << endl; + outFile.close(); delete alignment; delete distCalculator; diff --git a/pairwiseseqscommand.h b/pairwiseseqscommand.h index 06dbad9..defccb5 100644 --- a/pairwiseseqscommand.h +++ b/pairwiseseqscommand.h @@ -95,7 +95,7 @@ struct pairwiseData { SequenceDB alignDB; pairwiseData(){} - pairwiseData(string ofn, string al, string sq, string di, bool co, string op, SequenceDB DB, MothurOut* mout, unsigned long long st, unsigned long long en, float ma, float misMa, float gapO, float gapE, int thr, int tid) { + pairwiseData(string ofn, string al, string sq, string di, bool co, string op, SequenceDB DB, MothurOut* mout, unsigned long long st, unsigned long long en, float ma, float misMa, float gapO, float gapE, int thr, float cu, int tid) { outputFileName = ofn; m = mout; start = st; @@ -112,6 +112,7 @@ struct pairwiseData { alignDB = DB; count = 0; output = op; + cutoff = cu; threadID = tid; } }; @@ -225,8 +226,6 @@ static DWORD WINAPI MyPairwiseThreadFunction(LPVOID lpParam){ ofstream outFile((pDataArray->outputFileName).c_str(), ios::trunc); outFile.setf(ios::fixed, ios::showpoint); outFile << setprecision(4); - - pDataArray->count = pDataArray->end; int startTime = time(NULL); @@ -259,7 +258,9 @@ static DWORD WINAPI MyPairwiseThreadFunction(LPVOID lpParam){ if((pDataArray->output == "lt") && pDataArray->start == 0){ outFile << pDataArray->alignDB.getNumSeqs() << endl; } + pDataArray->count = 0; for(int i=pDataArray->start;iend;i++){ + pDataArray->count++; if(pDataArray->output == "lt") { string name = pDataArray->alignDB.get(i).getName(); diff --git a/preclustercommand.cpp b/preclustercommand.cpp index c067915..c2564c1 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -44,7 +44,7 @@ string PreClusterCommand::getHelpString(){ helpString += "The group parameter allows you to provide a group file so you can cluster by group. \n"; helpString += "The count parameter allows you to provide a count file so you can cluster by group. \n"; helpString += "The diffs parameter allows you to specify maximum number of mismatched bases allowed between sequences in a grouping. The default is 1.\n"; - helpString += "The topdown parameter allows you to specify whether to cluster from largest abundance to smallest or smallest to largest. Default=T, meanging largest to smallest.\n"; + helpString += "The topdown parameter allows you to specify whether to cluster from largest abundance to smallest or smallest to largest. Default=T, meaning largest to smallest.\n"; helpString += "The pre.cluster command should be in the following format: \n"; helpString += "pre.cluster(fasta=yourFastaFile, names=yourNamesFile, diffs=yourMaxDiffs) \n"; helpString += "Example pre.cluster(fasta=amazon.fasta, diffs=2).\n"; diff --git a/removerarecommand.cpp b/removerarecommand.cpp index c069448..cf6674e 100644 --- a/removerarecommand.cpp +++ b/removerarecommand.cpp @@ -730,17 +730,6 @@ int RemoveRareCommand::processShared(){ try { m->setGroups(Groups); - string thisOutputDir = outputDir; - if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } - map variables; - variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[extension]"] = m->getExtension(sharedfile); - string outputFileName = getOutputFileName("shared", variables); - outputTypes["shared"].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(sharedfile, "sharedfile"); vector lookup = input.getSharedRAbundVectors(); @@ -750,7 +739,7 @@ int RemoveRareCommand::processShared(){ while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } out.close(); return 0; } + if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -758,8 +747,7 @@ int RemoveRareCommand::processShared(){ processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); - if (!m->printedHeaders) { lookup[0]->printHeaders(out); } - processLookup(lookup, out); + processLookup(lookup); } if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { @@ -772,8 +760,7 @@ int RemoveRareCommand::processShared(){ processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); - if (!m->printedHeaders) { lookup[0]->printHeaders(out); } - processLookup(lookup, out); + processLookup(lookup); //restore real lastlabel to save below lookup[0]->setLabel(saveLabel); @@ -785,7 +772,7 @@ int RemoveRareCommand::processShared(){ lookup = input.getSharedRAbundVectors(); } - if (m->control_pressed) { out.close(); return 0; } + if (m->control_pressed) { return 0; } //output error messages about any remaining user labels set::iterator it; @@ -806,9 +793,7 @@ int RemoveRareCommand::processShared(){ lookup = input.getSharedRAbundVectors(lastLabel); m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - - if (!m->printedHeaders) { lookup[0]->printHeaders(out); } - processLookup(lookup, out); + processLookup(lookup); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -821,10 +806,23 @@ int RemoveRareCommand::processShared(){ } } //********************************************************************************************************************** -int RemoveRareCommand::processLookup(vector& lookup, ofstream& out){ +int RemoveRareCommand::processLookup(vector& lookup){ try { + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[extension]"] = m->getExtension(sharedfile); + variables["[tag]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("shared", variables); + outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); + + ofstream out; + m->openOutputFile(outputFileName, out); + vector newRabunds; newRabunds.resize(lookup.size()); + vector headers; for (int i = 0; i < lookup.size(); i++) { newRabunds[i].setGroup(lookup[i]->getGroup()); newRabunds[i].setLabel(lookup[i]->getLabel()); @@ -836,7 +834,7 @@ int RemoveRareCommand::processLookup(vector& lookup, ofstre for (int i = 0; i < lookup[0]->getNumBins(); i++) { bool allZero = true; - if (m->control_pressed) { return 0; } + if (m->control_pressed) { out.close(); return 0; } //for each group for (int j = 0; j < lookup.size(); j++) { @@ -852,12 +850,13 @@ int RemoveRareCommand::processLookup(vector& lookup, ofstre //eliminates zero otus if (allZero) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } } + else { headers.push_back(m->currentBinLabels[i]); } } }else { //for each otu for (int i = 0; i < lookup[0]->getNumBins(); i++) { - if (m->control_pressed) { return 0; } + if (m->control_pressed) { out.close(); return 0; } int totalAbund = 0; //get total otu abundance @@ -868,17 +867,23 @@ int RemoveRareCommand::processLookup(vector& lookup, ofstre //eliminates otus below rare cutoff if (totalAbund <= nseqs) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } } + else { headers.push_back(m->currentBinLabels[i]); } } } //do we have any otus above the rare cutoff - if (newRabunds[0].getNumBins() != 0) { + if (newRabunds[0].getNumBins() != 0) { + out << "label\tGroup\tnumOtus\t"; + for (int j = 0; j < headers.size(); j++) { out << headers[j] << '\t'; } + out << endl; for (int j = 0; j < newRabunds.size(); j++) { out << newRabunds[j].getLabel() << '\t' << newRabunds[j].getGroup() << '\t'; newRabunds[j].print(out); } } + out.close(); + return 0; } catch(exception& e) { diff --git a/removerarecommand.h b/removerarecommand.h index 2cab7be..6a9f269 100644 --- a/removerarecommand.h +++ b/removerarecommand.h @@ -47,7 +47,7 @@ private: int processRabund(); int processList(); int processShared(); - int processLookup(vector&, ofstream&); + int processLookup(vector&); }; diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 2c88bef..5a5d445 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -1648,7 +1648,7 @@ bool TrimSeqsCommand::getOligos(vector >& fastaFileNames, vector< if (hasPairedBarcodes || hasPrimer) { pairedOligos = true; if ((primers.size() != 0) || (barcodes.size() != 0) || (linker.size() != 0) || (spacer.size() != 0) || (revPrimer.size() != 0)) { m->control_pressed = true; m->mothurOut("[ERROR]: cannot mix paired primers and barcodes with non paired or linkers and spacers, quitting."); m->mothurOutEndLine(); return 0; } - } + }else if (reorient) { m->mothurOut("[Warning]: cannot use checkorient without paired barcodes or primers, ignoring.\n"); m->mothurOutEndLine(); reorient = false; } if(barcodeNameVector.size() == 0 && primerNameVector[0] == ""){ allFiles = 0; }