From 6b32d112bb60e9f7eb6d4407a4eed4c49b67bced Mon Sep 17 00:00:00 2001 From: Sarah Westcott Date: Fri, 18 Oct 2013 14:34:29 -0400 Subject: [PATCH] modifications to commands to add headers to list file. --- Mothur.xcodeproj/project.pbxproj | 8 +- commandfactory.cpp | 2 +- commandfactory.hpp | 4 +- getotulabelscommand.cpp | 1 - getseqscommand.cpp | 4 +- makefile | 4 +- mothurout.cpp | 2 +- mothurout.h | 2 - parselistscommand.cpp | 79 +++++++++-------- parselistscommand.h | 3 - phylotypecommand.cpp | 4 +- primerdesigncommand.cpp | 70 ++++++++++----- primerdesigncommand.h | 15 ++-- removegroupscommand.cpp | 29 +++--- removelineagecommand.cpp | 32 +++++-- removeotulabelscommand.cpp | 17 ++-- removeotuscommand.cpp | 23 +++-- removerarecommand.cpp | 52 ++++++----- removeseqscommand.cpp | 47 ++++++---- sensspeccommand.cpp | 7 +- seqnoise.cpp | 147 ++++++++++++++++--------------- splitabundcommand.cpp | 35 ++++++-- subsamplecommand.cpp | 47 +++++----- subsamplecommand.h | 2 +- 24 files changed, 372 insertions(+), 264 deletions(-) diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index a26db61..2314b5d 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -2443,7 +2443,7 @@ GCC_ENABLE_SSE3_EXTENSIONS = NO; GCC_ENABLE_SSE41_EXTENSIONS = NO; GCC_ENABLE_SSE42_EXTENSIONS = NO; - GCC_OPTIMIZATION_LEVEL = s; + GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = ( "MOTHUR_FILES=\"\\\"../../release\\\"\"", "VERSION=\"\\\"1.31.0\\\"\"", @@ -2481,10 +2481,10 @@ GCC_C_LANGUAGE_STANDARD = gnu99; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_MODEL_TUNING = ""; - GCC_OPTIMIZATION_LEVEL = s; + GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = ( - "VERSION=\"\\\"1.32.0\\\"\"", - "RELEASE_DATE=\"\\\"10/01/2013\\\"\"", + "VERSION=\"\\\"1.32.1\\\"\"", + "RELEASE_DATE=\"\\\"10/16/2013\\\"\"", ); GCC_VERSION = ""; GCC_WARN_ABOUT_MISSING_NEWLINE = YES; diff --git a/commandfactory.cpp b/commandfactory.cpp index 8ab0a95..c247f90 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -408,7 +408,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else { optionString += "inputdir=" + inputDir; } } - if(commandName == "cluster") { command = new ClusterCommand(optionString); } + if(commandName == "cluster") { command = new ClusterCommand(optionString); } else if(commandName == "unique.seqs") { command = new DeconvoluteCommand(optionString); } else if(commandName == "parsimony") { command = new ParsimonyCommand(optionString); } else if(commandName == "help") { command = new HelpCommand(optionString); } diff --git a/commandfactory.hpp b/commandfactory.hpp index 36e8f46..eb85c68 100644 --- a/commandfactory.hpp +++ b/commandfactory.hpp @@ -27,8 +27,8 @@ public: bool isValidCommand(string, string); void printCommands(ostream&); void printCommandsCategories(ostream&); - void setOutputDirectory(string o) { outputDir = o; m->setOutputDir(o); } - void setInputDirectory(string i) { inputDir = i; } + void setOutputDirectory(string o) { if(m->dirCheck(o) || (o == "")) { outputDir = o; m->setOutputDir(o); } } + void setInputDirectory(string i) { if(m->dirCheck(i) || (i == "")) { inputDir = i; } } void setLogfileName(string n, bool a) { logFileName = n; append = a; } string getLogfileName() { return logFileName; } bool getAppend() { return append; } diff --git a/getotulabelscommand.cpp b/getotulabelscommand.cpp index 452d7f6..a1413d2 100644 --- a/getotulabelscommand.cpp +++ b/getotulabelscommand.cpp @@ -521,7 +521,6 @@ int GetOtuLabelsCommand::readList(){ newList.setLabel(list->getLabel()); int selectedCount = 0; bool wroteSomething = false; - string snumBins = toString(list->getNumBins()); vector binLabels = list->getLabels(); vector newLabels; diff --git a/getseqscommand.cpp b/getseqscommand.cpp index 44c4042..a1cf493 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -737,8 +737,8 @@ int GetSeqsCommand::readList(){ m->splitAtComma(binnames, bnames); string newNames = ""; - for (int i = 0; i < bnames.size(); i++) { - string name = bnames[i]; + for (int j = 0; j < bnames.size(); j++) { + string name = bnames[j]; //if that name is in the .accnos file, add it if (names.count(name) != 0) { newNames += name + ","; selectedCount++; if (m->debug) { sanity["list"].insert(name); } } } diff --git a/makefile b/makefile index 7fc8608..42e71a0 100644 --- a/makefile +++ b/makefile @@ -15,8 +15,8 @@ USEREADLINE ?= yes CYGWIN_BUILD ?= no USECOMPRESSION ?= no MOTHUR_FILES="\"Enter_your_default_path_here\"" -RELEASE_DATE = "\"10/01/2013\"" -VERSION = "\"1.32.0\"" +RELEASE_DATE = "\"10/16/2013\"" +VERSION = "\"1.32.1\"" FORTAN_COMPILER = gfortran FORTRAN_FLAGS = diff --git a/mothurout.cpp b/mothurout.cpp index 66ee704..e7f0c8e 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -797,7 +797,7 @@ bool MothurOut::dirCheck(string& dirName){ //test to make sure directory exists dirName = getFullPathName(dirName); - string outTemp = dirName + tag + "temp"; + string outTemp = dirName + tag + "temp"+ toString(time(NULL)); ofstream out; out.open(outTemp.c_str(), ios::trunc); if(!out) { diff --git a/mothurout.h b/mothurout.h index ee602f4..1caa1fe 100644 --- a/mothurout.h +++ b/mothurout.h @@ -66,11 +66,9 @@ class MothurOut { vector getAllGroups() { sort(namesOfGroups.begin(), namesOfGroups.end()); return namesOfGroups; } vector Treenames; - //map names; vector sharedBinLabelsInFile; vector currentSharedBinLabels; vector listBinLabelsInFile; - //vector currentListBinLabels; string saveNextLabel, argv, sharedHeaderMode, groupMode; bool printedSharedHeaders, printedListHeaders, commandInputsConvertError, changedSeqNames, modifyNames; diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 32a7e08..cfd1b6b 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -53,7 +53,7 @@ string ParseListCommand::getOutputPattern(string type) { try { string pattern = ""; - if (type == "list") { pattern = "[filename],[group],list"; } + if (type == "list") { pattern = "[filename],[group],[distance],list"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } return pattern; @@ -205,27 +205,6 @@ int ParseListCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - //set fileroot - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); - - //fill filehandles with neccessary ofstreams - int i; - ofstream* temp; - vector gGroups; - if (groupfile != "") { gGroups = groupMap->getNamesOfGroups(); } - else { gGroups = ct.getNamesOfGroups(); } - - for (i=0; iopenOutputFile(filename, *temp); - } - //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; @@ -236,16 +215,13 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete list; if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); - return 0; + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { delete list; if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -283,7 +259,6 @@ int ParseListCommand::execute(){ if (m->control_pressed) { if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -304,7 +279,6 @@ int ParseListCommand::execute(){ if (m->control_pressed) { if (groupfile != "") { delete groupMap; } - for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -320,11 +294,6 @@ int ParseListCommand::execute(){ delete list; } - for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { - (*(filehandles[it3->first])).close(); - delete it3->second; - } - if (groupfile != "") { delete groupMap; } if (m->control_pressed) { @@ -354,8 +323,33 @@ int ParseListCommand::execute(){ /**********************************************************************************************************************/ int ParseListCommand::parse(ListVector* thisList) { try { + map filehandles; + map::iterator it3; + + //set fileroot + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[distance]"] = thisList->getLabel(); + + //fill filehandles with neccessary ofstreams + ofstream* temp; + vector gGroups; + if (groupfile != "") { gGroups = groupMap->getNamesOfGroups(); } + else { gGroups = ct.getNamesOfGroups(); } + + for (int i=0; iopenOutputFile(filename, *temp); + outputNames.push_back(filename); outputTypes["list"].push_back(filename); + } + map groupVector; + map groupLabels; map::iterator itGroup; map groupNumBins; @@ -363,11 +357,12 @@ int ParseListCommand::parse(ListVector* thisList) { for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { groupNumBins[it3->first] = 0; groupVector[it3->first] = ""; + groupLabels[it3->first] = "label\tnumOtus\t"; } - + vector binLabels = thisList->getLabels(); for (int i = 0; i < thisList->getNumBins(); i++) { - if (m->control_pressed) { return 0; } + if (m->control_pressed) { break; } map groupBins; string bin = list->get(i); @@ -408,14 +403,26 @@ int ParseListCommand::parse(ListVector* thisList) { //print parsed bin info to files for (itGroup = groupBins.begin(); itGroup != groupBins.end(); itGroup++) { - groupVector[itGroup->first] += itGroup->second + '\t'; + groupVector[itGroup->first] += itGroup->second + '\t'; + groupLabels[itGroup->first] += binLabels[i] + '\t'; } } + if (m->control_pressed) { + for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { + (*(filehandles[it3->first])).close(); + delete it3->second; + } + return 0; + } + //end list vector for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { + (*(filehandles[it3->first])) << groupLabels[it3->first] << endl; (*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl; // label numBins listvector for that group + (*(filehandles[it3->first])).close(); + delete it3->second; } return 0; diff --git a/parselistscommand.h b/parselistscommand.h index 84abc85..48b53a6 100644 --- a/parselistscommand.h +++ b/parselistscommand.h @@ -47,9 +47,6 @@ private: set labels; bool abort, allLines; vector outputNames; - - map filehandles; - map::iterator it3; }; diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index 1611705..b21865a 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -303,7 +303,9 @@ int PhylotypeCommand::execute(){ } //print listvector - list.print(outList); + if (!m->printedListHeaders) { list.printHeaders(outList); } + list.print(outList); + if (countfile == "") { //print rabund list.getRAbundVector().print(outRabund); diff --git a/primerdesigncommand.cpp b/primerdesigncommand.cpp index 960da85..bd68e2c 100644 --- a/primerdesigncommand.cpp +++ b/primerdesigncommand.cpp @@ -20,7 +20,7 @@ vector PrimerDesignCommand::setParameters(){ CommandParameter pmintm("mintm", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmintm); CommandParameter pmaxtm("maxtm", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxtm); CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pprocessors); - CommandParameter potunumber("otunumber", "Number", "", "-1", "", "", "","",false,true,true); parameters.push_back(potunumber); + CommandParameter potunumber("otulabel", "String", "", "", "", "", "","",false,true,true); parameters.push_back(potunumber); CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs); CommandParameter pcutoff("cutoff", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pcutoff); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); @@ -40,13 +40,13 @@ string PrimerDesignCommand::getHelpString(){ try { string helpString = ""; helpString += "The primer.design allows you to identify sequence fragments that are specific to particular OTUs.\n"; - helpString += "The primer.design command parameters are: list, fasta, name, count, otunumber, cutoff, length, pdiffs, mintm, maxtm, processors and label.\n"; + helpString += "The primer.design command parameters are: list, fasta, name, count, otulabel, cutoff, length, pdiffs, mintm, maxtm, processors and label.\n"; helpString += "The list parameter allows you to provide a list file and is required.\n"; helpString += "The fasta parameter allows you to provide a fasta file and is required.\n"; helpString += "The name parameter allows you to provide a name file associated with your fasta file.\n"; helpString += "The count parameter allows you to provide a count file associated with your fasta file.\n"; helpString += "The label parameter is used to indicate the label you want to use from your list file.\n"; - helpString += "The otunumber parameter is used to indicate the otu you want to use from your list file. It is required.\n"; + helpString += "The otulabel parameter is used to indicate the otu you want to use from your list file. It is required.\n"; helpString += "The pdiffs parameter is used to specify the number of differences allowed in the primer. The default is 0.\n"; helpString += "The length parameter is used to indicate the length of the primer. The default is 18.\n"; helpString += "The mintm parameter is used to indicate minimum melting temperature.\n"; @@ -216,9 +216,8 @@ PrimerDesignCommand::PrimerDesignCommand(string option) { temp = validParameter.validFile(parameters, "maxtm", false); if (temp == "not found") { temp = "-1"; } m->mothurConvert(temp, maxTM); - temp = validParameter.validFile(parameters, "otunumber", false); if (temp == "not found") { temp = "-1"; } - m->mothurConvert(temp, otunumber); - if (otunumber < 1) { m->mothurOut("[ERROR]: You must provide an OTU number, aborting.\n"); abort = true; } + otulabel = validParameter.validFile(parameters, "otulabel", false); if (otulabel == "not found") { temp = ""; } + if (otulabel == "") { m->mothurOut("[ERROR]: You must provide an OTU label, aborting.\n"); abort = true; } temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); @@ -253,7 +252,9 @@ int PrimerDesignCommand::execute(){ //reads list file and selects the label the users specified or the first label getListVector(); - if (otunumber > list->getNumBins()) { m->mothurOut("[ERROR]: You selected an OTU number larger than the number of OTUs you have in your list file, quitting.\n"); return 0; } + vector binLabels = list->getLabels(); + int binIndex = findIndex(otulabel, binLabels); + if (binIndex == -1) { m->mothurOut("[ERROR]: You selected an OTU label that is not in your in your list file, quitting.\n"); return 0; } map nameMap; unsigned long int numSeqs; //used to sanity check the files. numSeqs = total seqs for namefile and uniques for count. @@ -293,7 +294,7 @@ int PrimerDesignCommand::execute(){ m->mothurOut("Done.\n\n"); - set primers = getPrimer(conSeqs[otunumber-1]); + set primers = getPrimer(conSeqs[binIndex]); if (m->control_pressed) { delete list; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -302,7 +303,7 @@ int PrimerDesignCommand::execute(){ ofstream outSum; m->openOutputFile(consSummaryFile, outSum); - outSum << "PrimerOtu: " << otunumber << " Members: " << list->get(otunumber-1) << endl << "Primers\tminTm\tmaxTm" << endl; + outSum << "PrimerOtu: " << otulabel << " Members: " << list->get(binIndex) << endl << "Primers\tminTm\tmaxTm" << endl; //find min and max melting points vector minTms; @@ -339,7 +340,7 @@ int PrimerDesignCommand::execute(){ outSum.close(); //check each otu's conseq for each primer in otunumber - set otuToRemove = createProcesses(consSummaryFile, minTms, maxTms, primers, conSeqs); + set otuToRemove = createProcesses(consSummaryFile, minTms, maxTms, primers, conSeqs, binIndex); if (m->control_pressed) { delete list; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -348,21 +349,29 @@ int PrimerDesignCommand::execute(){ mvariables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); mvariables["[extension]"] = m->getExtension(listfile); string newListFile = getOutputFileName("list", mvariables); - outputNames.push_back(newListFile); outputTypes["list"].push_back(newListFile); - ofstream outList; - m->openOutputFile(newListFile, outList); + ofstream outListTemp; + m->openOutputFile(newListFile+".temp", outListTemp); - outList << list->getLabel() << '\t' << (list->getNumBins()-otuToRemove.size()) << '\t'; + outListTemp << list->getLabel() << '\t' << (list->getNumBins()-otuToRemove.size()) << '\t'; + string headers = "label\tnumOtus\t"; for (int j = 0; j < list->getNumBins(); j++) { if (m->control_pressed) { break; } //good otus if (otuToRemove.count(j) == 0) { string bin = list->get(j); - if (bin != "") { outList << bin << '\t'; } + if (bin != "") { outListTemp << bin << '\t'; headers += binLabels[j] + '\t'; } } } - outList << endl; + outListTemp << endl; + outListTemp.close(); + + ofstream outList; + m->openOutputFile(newListFile, outList); + outList << headers << endl; outList.close(); + m->appendFiles(newListFile+".temp", newListFile); + m->mothurRemove(newListFile+".temp"); + outputNames.push_back(newListFile); outputTypes["list"].push_back(newListFile); if (m->control_pressed) { delete list; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -525,7 +534,7 @@ set PrimerDesignCommand::getPrimer(Sequence primerSeq){ } } /**************************************************************************************************/ -set PrimerDesignCommand::createProcesses(string newSummaryFile, vector& minTms, vector& maxTms, set& primers, vector& conSeqs) { +set PrimerDesignCommand::createProcesses(string newSummaryFile, vector& minTms, vector& maxTms, set& primers, vector& conSeqs, int binIndex) { try { vector processIDS; @@ -560,7 +569,7 @@ set PrimerDesignCommand::createProcesses(string newSummaryFile, vectormothurRemove(newSummaryFile + toString(getpid()) + ".temp"); - otusToRemove = driver(newSummaryFile + toString(getpid()) + ".temp", minTms, maxTms, primers, conSeqs, lines[process].start, lines[process].end, numBinsProcessed); + otusToRemove = driver(newSummaryFile + toString(getpid()) + ".temp", minTms, maxTms, primers, conSeqs, lines[process].start, lines[process].end, numBinsProcessed, binIndex); string tempFile = toString(getpid()) + ".otus2Remove.temp"; ofstream outTemp; @@ -580,7 +589,7 @@ set PrimerDesignCommand::createProcesses(string newSummaryFile, vector PrimerDesignCommand::createProcesses(string newSummaryFile, vectormothurRemove(newSummaryFile+extension); - primerDesignData* tempPrimer = new primerDesignData((newSummaryFile+extension), m, lines[i].start, lines[i].end, minTms, maxTms, primers, conSeqs, pdiffs, otunumber, length, i); + primerDesignData* tempPrimer = new primerDesignData((newSummaryFile+extension), m, lines[i].start, lines[i].end, minTms, maxTms, primers, conSeqs, pdiffs, binIndex, length, i); pDataArray.push_back(tempPrimer); processIDS.push_back(i); @@ -635,7 +644,7 @@ set PrimerDesignCommand::createProcesses(string newSummaryFile, vector PrimerDesignCommand::createProcesses(string newSummaryFile, vector PrimerDesignCommand::driver(string summaryFileName, vector& minTms, vector& maxTms, set& primers, vector& conSeqs, int start, int end, int& numBinsProcessed){ +set PrimerDesignCommand::driver(string summaryFileName, vector& minTms, vector& maxTms, set& primers, vector& conSeqs, int start, int end, int& numBinsProcessed, int binIndex){ try { set otuToRemove; @@ -679,7 +688,7 @@ set PrimerDesignCommand::driver(string summaryFileName, vector& min if (m->control_pressed) { break; } - if (i != (otunumber-1)) { + if (i != (binIndex)) { int primerIndex = 0; for (set::iterator it = primers.begin(); it != primers.end(); it++) { vector primerStarts; @@ -1236,6 +1245,21 @@ int PrimerDesignCommand::countDiffs(string oligo, string seq){ } } //********************************************************************************************************************** +int PrimerDesignCommand::findIndex(string binLabel, vector binLabels){ + try { + int index = -1; + for (int i = 0; i < binLabels.size(); i++){ + if (m->control_pressed) { return index; } + if (m->isLabelEquivalent(binLabel, binLabels[i])) { index = i; break; } + } + return index; + } + catch(exception& e) { + m->errorOut(e, "PrimerDesignCommand", "findIndex"); + exit(1); + } +} +//********************************************************************************************************************** diff --git a/primerdesigncommand.h b/primerdesigncommand.h index 2879d2b..ff1ddf2 100644 --- a/primerdesigncommand.h +++ b/primerdesigncommand.h @@ -50,8 +50,8 @@ private: }; bool abort, allLines, large; - int cutoff, pdiffs, length, otunumber, processors, alignedLength; - string outputDir, listfile, namefile, countfile, fastafile, label; + int cutoff, pdiffs, length, processors, alignedLength; + string outputDir, listfile, otulabel, namefile, countfile, fastafile, label; double minTM, maxTM; ListVector* list; vector outputNames; @@ -65,10 +65,11 @@ private: bool findPrimer(string, string, vector&, vector&, vector&); int findMeltingPoint(string primer, double&, double&); - set createProcesses(string, vector&, vector&, set&, vector&); - set driver(string, vector&, vector&, set&, vector&, int, int, int&); + set createProcesses(string, vector&, vector&, set&, vector&, int); + set driver(string, vector&, vector&, set&, vector&, int, int, int&, int); vector< vector< vector > > driverGetCounts(map&, unsigned long int&, vector&, unsigned long long&, unsigned long long&); vector createProcessesConSeqs(map&, unsigned long int&); + int findIndex(string binLabel, vector binLabels); }; @@ -81,7 +82,7 @@ struct primerDesignData { MothurOut* m; int start; int end; - int pdiffs, threadID, otunumber, length; + int pdiffs, threadID, length, binIndex; set primers; vector minTms, maxTms; set otusToRemove; @@ -99,7 +100,7 @@ struct primerDesignData { maxTms = max; primers = pri; consSeqs = seqs; - otunumber = otun; + binIndex = otun; length = l; threadID = tid; numBinsProcessed = 0; @@ -121,7 +122,7 @@ static DWORD WINAPI MyPrimerThreadFunction(LPVOID lpParam){ if (pDataArray->m->control_pressed) { break; } - if (i != (pDataArray->otunumber-1)) { + if (i != (pDataArray->binIndex)) { int primerIndex = 0; for (set::iterator it = pDataArray->primers.begin(); it != pDataArray->primers.end(); it++) { vector primerStarts; diff --git a/removegroupscommand.cpp b/removegroupscommand.cpp index 9db35cb..42f088b 100644 --- a/removegroupscommand.cpp +++ b/removegroupscommand.cpp @@ -70,7 +70,7 @@ string RemoveGroupsCommand::getOutputPattern(string type) { else if (type == "count") { pattern = "[filename],pick,[extension]"; } else if (type == "list") { pattern = "[filename],pick,[extension]"; } else if (type == "shared") { pattern = "[filename],[tag],pick,[extension]"; } - else if (type == "design") { pattern = "[filename],pick,[extension]"; } + else if (type == "design") { pattern = "[filename],[tag],pick,[extension]"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } return pattern; @@ -623,12 +623,7 @@ int RemoveGroupsCommand::readList(){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); variables["[extension]"] = m->getExtension(listfile); - string outputFileName = getOutputFileName("list", variables); - - - ofstream out; - m->openOutputFile(outputFileName, out); - + ifstream in; m->openInputFile(listfile, in); @@ -641,6 +636,16 @@ int RemoveGroupsCommand::readList(){ //read in list vector ListVector list(in); + + variables["[tag]"] = list.getLabel(); + string outputFileName = getOutputFileName("list", variables); + + ofstream out; + m->openOutputFile(outputFileName, out); + outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + + vector binLabels = list.getLabels(); + vector newBinLabels; //make a new list vector ListVector newList; @@ -681,24 +686,26 @@ int RemoveGroupsCommand::readList(){ //if there are names in this bin add to new list if (newNames != "") { newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma - newList.push_back(newNames); + newList.push_back(newNames); + newBinLabels.push_back(binLabels[i]); } } //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newBinLabels); + newList.printHeaders(out); newList.print(out); } m->gobble(in); + out.close(); } in.close(); - out.close(); - if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the groups you wish to remove."); m->mothurOutEndLine(); } - outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the groups you wish to remove."); m->mothurOutEndLine(); } m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine(); return 0; diff --git a/removelineagecommand.cpp b/removelineagecommand.cpp index 761de14..7349203 100644 --- a/removelineagecommand.cpp +++ b/removelineagecommand.cpp @@ -75,7 +75,7 @@ string RemoveLineageCommand::getOutputPattern(string type) { else if (type == "name") { pattern = "[filename],pick,[extension]"; } else if (type == "group") { pattern = "[filename],pick,[extension]"; } else if (type == "count") { pattern = "[filename],pick,[extension]"; } - else if (type == "list") { pattern = "[filename],pick,[extension]-[filename],[distance],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],[distance],pick,[extension]"; } else if (type == "shared") { pattern = "[filename],[distance],pick,[extension]"; } else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } @@ -481,9 +481,6 @@ int RemoveLineageCommand::readList(){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); variables["[extension]"] = m->getExtension(listfile); - string outputFileName = getOutputFileName("list", variables); - ofstream out; - m->openOutputFile(outputFileName, out); ifstream in; m->openInputFile(listfile, in); @@ -491,12 +488,25 @@ int RemoveLineageCommand::readList(){ bool wroteSomething = false; while(!in.eof()){ + //read in list vector ListVector list(in); //make a new list vector ListVector newList; newList.setLabel(list.getLabel()); + + variables["[distance]"] = list.getLabel(); + string outputFileName = getOutputFileName("list", variables); + + ofstream out; + m->openOutputFile(outputFileName, out); + outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + + if (m->control_pressed) { in.close(); out.close(); return 0; } + + vector binLabels = list.getLabels(); + vector newBinLabels; //for each bin for (int i = 0; i < list.getNumBins(); i++) { @@ -517,23 +527,26 @@ int RemoveLineageCommand::readList(){ //if there are names in this bin add to new list if (newNames != "") { newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma - newList.push_back(newNames); + newList.push_back(newNames); + newBinLabels.push_back(binLabels[i]); } } //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newBinLabels); + newList.printHeaders(out); newList.print(out); } m->gobble(in); + out.close(); } in.close(); - out.close(); + if (wroteSomething == false) { m->mothurOut("Your list file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName); return 0; @@ -692,6 +705,8 @@ int RemoveLineageCommand::readConsList(){ bool wroteSomething = false; string snumBins = toString(list->getNumBins()); + vector binLabels = list->getLabels(); + vector newBinLabels; for (int i = 0; i < list->getNumBins(); i++) { if (m->control_pressed) { delete list; return 0;} @@ -707,6 +722,7 @@ int RemoveLineageCommand::readConsList(){ if (names.count(m->getSimpleLabel(otuLabel)) == 0) { newList.push_back(list->get(i)); + newBinLabels.push_back(binLabels[i]); }else { removedCount++; } } @@ -724,6 +740,8 @@ int RemoveLineageCommand::readConsList(){ //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newBinLabels); + newList.printHeaders(out); newList.print(out); } out.close(); diff --git a/removeotulabelscommand.cpp b/removeotulabelscommand.cpp index a882f6b..18322f1 100644 --- a/removeotulabelscommand.cpp +++ b/removeotulabelscommand.cpp @@ -518,23 +518,16 @@ int RemoveOtuLabelsCommand::readList(){ newList.setLabel(list->getLabel()); int removedCount = 0; bool wroteSomething = false; - string snumBins = toString(list->getNumBins()); + vector binLabels = list->getLabels(); + vector newLabels; for (int i = 0; i < list->getNumBins(); i++) { if (m->control_pressed) { delete list; return 0;} - //create a label for this otu - string otuLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { otuLabel += "0"; } - } - otuLabel += sbinNumber; - - if (labels.count(m->getSimpleLabel(otuLabel)) == 0) { + if (labels.count(m->getSimpleLabel(binLabels[i])) == 0) { newList.push_back(list->get(i)); + newLabels.push_back(binLabels[i]); }else { removedCount++; } } @@ -552,6 +545,8 @@ int RemoveOtuLabelsCommand::readList(){ //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newLabels); + newList.printHeaders(out); newList.print(out); } out.close(); diff --git a/removeotuscommand.cpp b/removeotuscommand.cpp index 16fd8dc..a840bba 100644 --- a/removeotuscommand.cpp +++ b/removeotuscommand.cpp @@ -243,6 +243,13 @@ int RemoveOtusCommand::execute(){ //********************************************************************************************************************** int RemoveOtusCommand::readListGroup(){ try { + InputData* input = new InputData(listfile, "list"); + ListVector* list = input->getListVector(); + string lastLabel = list->getLabel(); + + //using first label seen if none is provided + if (label == "") { label = lastLabel; } + string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } map variables; @@ -263,13 +270,6 @@ int RemoveOtusCommand::readListGroup(){ ofstream outGroup; m->openOutputFile(outputGroupFileName, outGroup); - InputData* input = new InputData(listfile, "list"); - ListVector* list = input->getListVector(); - string lastLabel = list->getLabel(); - - //using first label seen if none is provided - if (label == "") { label = lastLabel; } - //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); set processedLabels; @@ -365,6 +365,8 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr int numOtus = 0; //for each bin + vector binLabels = list->getLabels(); + vector newBinLabels; for (int i = 0; i < list->getNumBins(); i++) { if (m->control_pressed) { return 0; } @@ -400,7 +402,8 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr if (!removeBin) { //if there are no sequences from the groups we want to remove in this bin add to new list, output to groupfile - newList.push_back(binnames); + newList.push_back(binnames); + newBinLabels.push_back(binLabels[i]); outGroup << groupFileOutput; }else { numOtus++; @@ -414,7 +417,9 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; - newList.print(out); + newList.setLabels(newBinLabels); + newList.printHeaders(out); + newList.print(out); } m->mothurOut(newList.getLabel() + " - removed " + toString(numOtus) + " of the " + toString(list->getNumBins()) + " OTUs."); m->mothurOutEndLine(); diff --git a/removerarecommand.cpp b/removerarecommand.cpp index c378e41..24d5bef 100644 --- a/removerarecommand.cpp +++ b/removerarecommand.cpp @@ -68,7 +68,7 @@ string RemoveRareCommand::getOutputPattern(string type) { else if (type == "sabund") { pattern = "[filename],pick,[extension]"; } else if (type == "group") { pattern = "[filename],pick,[extension]"; } else if (type == "count") { pattern = "[filename],pick,[extension]"; } - else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],[tag],pick,[extension]"; } else if (type == "shared") { pattern = "[filename],[tag],pick,[extension]"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } @@ -344,24 +344,7 @@ int RemoveRareCommand::execute(){ //********************************************************************************************************************** int RemoveRareCommand::processList(){ try { - string thisOutputDir = outputDir; - if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - map variables; - variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); - variables["[extension]"] = m->getExtension(listfile); - string outputFileName = getOutputFileName("list", variables); - variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); - variables["[extension]"] = m->getExtension(groupfile); - string outputGroupFileName = getOutputFileName("group", variables); - variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); - variables["[extension]"] = m->getExtension(countfile); - string outputCountFileName = getOutputFileName("count", variables); - - ofstream out, outGroup; - m->openOutputFile(outputFileName, out); - - bool wroteSomething = false; - + //you must provide a label because the names in the listfile need to be consistent string thisLabel = ""; if (allLines) { m->mothurOut("For the listfile you must select one label, using first label in your listfile."); m->mothurOutEndLine(); } @@ -400,6 +383,26 @@ int RemoveRareCommand::processList(){ list = input.getListVector(lastLabel); } } + + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + variables["[tag]"] = list->getLabel(); + string outputFileName = getOutputFileName("list", variables); + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputGroupFileName = getOutputFileName("group", variables); + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputCountFileName = getOutputFileName("count", variables); + + ofstream out, outGroup; + m->openOutputFile(outputFileName, out); + + bool wroteSomething = false; + //if groupfile is given then use it GroupMap* groupMap; @@ -420,7 +423,11 @@ int RemoveRareCommand::processList(){ } - if (list != NULL) { + if (list != NULL) { + + vector binLabels = list->getLabels(); + vector newLabels; + //make a new list vector ListVector newList; newList.setLabel(list->getLabel()); @@ -479,6 +486,7 @@ int RemoveRareCommand::processList(){ if (binsize > nseqs) { //keep bin newList.push_back(saveBinNames); + newLabels.push_back(binLabels[i]); if (groupfile != "") { for(int k = 0; k < newGroupFile.size(); k++) { outGroup << newGroupFile[k] << endl; } } else if (countfile != "") { for(int k = 0; k < newGroupFile.size(); k++) { ct.remove(newGroupFile[k]); } } }else { if (countfile != "") { for(int k = 0; k < names.size(); k++) { ct.remove(names[k]); } } } @@ -487,7 +495,9 @@ int RemoveRareCommand::processList(){ //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; - newList.print(out); + newList.setLabels(newLabels); + newList.printHeaders(out); + newList.print(out); } } diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 019a659..25d45a7 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -67,7 +67,7 @@ string RemoveSeqsCommand::getOutputPattern(string type) { else if (type == "name") { pattern = "[filename],pick,[extension]"; } else if (type == "group") { pattern = "[filename],pick,[extension]"; } else if (type == "count") { pattern = "[filename],pick,[extension]"; } - else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],[distance],pick,[extension]"; } else if (type == "qfile") { pattern = "[filename],pick,[extension]"; } else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } @@ -664,10 +664,7 @@ int RemoveSeqsCommand::readList(){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); variables["[extension]"] = m->getExtension(listfile); - string outputFileName = getOutputFileName("list", variables); - ofstream out; - m->openOutputFile(outputFileName, out); - + ifstream in; m->openInputFile(listfile, in); @@ -684,48 +681,60 @@ int RemoveSeqsCommand::readList(){ //make a new list vector ListVector newList; newList.setLabel(list.getLabel()); + + variables["[distance]"] = list.getLabel(); + string outputFileName = getOutputFileName("list", variables); + ofstream out; + m->openOutputFile(outputFileName, out); + outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + + vector binLabels = list.getLabels(); + vector newBinLabels; + + if (m->control_pressed) { in.close(); out.close(); return 0; } + //for each bin for (int i = 0; i < list.getNumBins(); i++) { if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } //parse out names that are in accnos file - string binnames = list.get(i); + string bin = list.get(i); + vector bnames; + m->splitAtComma(bin, bnames); string newNames = ""; - while (binnames.find_first_of(',') != -1) { - string name = binnames.substr(0,binnames.find_first_of(',')); - binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length()); - - //if that name is in the .accnos file, add it + for (int j = 0; j < bnames.size(); j++) { + string name = bnames[j]; + //if that name is in the .accnos file, add it if (names.count(name) == 0) { newNames += name + ","; } else { removedCount++; } - } - - //get last name - if (names.count(binnames) == 0) { newNames += binnames + ","; } - else { removedCount++; } + } //if there are names in this bin add to new list if (newNames != "") { newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma - newList.push_back(newNames); + newList.push_back(newNames); + newBinLabels.push_back(binLabels[i]); } } //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newBinLabels); + newList.printHeaders(out); newList.print(out); + } m->gobble(in); + out.close(); } in.close(); - out.close(); + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine(); diff --git a/sensspeccommand.cpp b/sensspeccommand.cpp index 12786ca..5746cda 100644 --- a/sensspeccommand.cpp +++ b/sensspeccommand.cpp @@ -793,6 +793,8 @@ string SensSpecCommand::preProcessList(){ //make a new list vector ListVector newList; newList.setLabel(list.getLabel()); + vector binLabels = list.getLabels(); + vector newLabels; //for each bin for (int i = 0; i < list.getNumBins(); i++) { @@ -812,13 +814,16 @@ string SensSpecCommand::preProcessList(){ //if there are names in this bin add to new list if (newNames != "") { newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma - newList.push_back(newNames); + newList.push_back(newNames); + newLabels.push_back(binLabels[i]); } } //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newLabels); + if (!m->printedListHeaders) { newList.printHeaders(out); } newList.print(out); } diff --git a/seqnoise.cpp b/seqnoise.cpp index 8e7a439..8c712c3 100644 --- a/seqnoise.cpp +++ b/seqnoise.cpp @@ -9,6 +9,8 @@ #include "seqnoise.h" #include "sequence.hpp" +#include "listvector.hpp" +#include "inputdata.h" #define MIN_DELTA 1.0e-6 #define MIN_ITER 20 @@ -138,91 +140,93 @@ int seqNoise::getListData(string listFileName, double cutOff, vector& otuDa ifstream listFile; m->openInputFile(listFileName, listFile); - double threshold; - int numOTUs; - string line = ""; - bool adjustCutoff = true; - - if(listFile.peek() == 'u'){ m->getline(listFile); } - while(listFile){ - listFile >> threshold; - - if(threshold < cutOff){ - line = m->getline(listFile); m->gobble(listFile); - } - else{ - adjustCutoff = false; - listFile >> numOTUs; - otuFreq.resize(numOTUs, 0); - - for(int i=0;icontrol_pressed) { return 0; } - - string otu; - listFile >> otu; - - int count = 0; - - string number = ""; - - for(int j=0;jcontrol_pressed) { return 0; } - otuBySeqLookUp[otuData[i]].push_back(i); - } - for(int i=0;icontrol_pressed) { return 0; } - for(int j=otuBySeqLookUp[i].size();jgobble(listFile); //10/18/13 - change to reading with listvector to accomodate changes to the listfiel format. ie. adding header labels. + + string thisLabel = list.getLabel(); + lastLabel = thisLabel; + + if (thisLabel == "unique") {} //skip to next label in listfile + else { + double threshold; + m->mothurConvert(thisLabel, threshold); + + if(threshold < cutOff){} //skip to next label in listfile + else{ + adjustCutoff = false; + int numOTUs = list.getNumBins(); + otuFreq.resize(numOTUs, 0); + + for(int i=0;icontrol_pressed) { return 0; } + + string otu = list.get(i); + int count = 0; + string number = ""; + + for(int j=0;jcontrol_pressed) { return 0; } + otuBySeqLookUp[otuData[i]].push_back(i); + } + for(int i=0;icontrol_pressed) { return 0; } + for(int j=otuBySeqLookUp[i].size();j> numOTUs; - otuFreq.resize(numOTUs, 0); + + InputData input(listFileName, "list"); + ListVector* list = input.getListVector(lastLabel); + + int numOTUs = list->getNumBins(); + otuFreq.resize(numOTUs, 0); for(int i=0;icontrol_pressed) { return 0; } - string otu; - iss >> otu; + string otu = list->get(i); int count = 0; - string number = ""; for(int j=0;j& otuDa } } + delete list; } return 0; diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index 0fff428..47372cc 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -501,17 +501,19 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi variables["[tag]"] = tag; variables["[tag2]"] = "rare"; string rare = getOutputFileName("list",variables); - m->openOutputFile(rare, rout); + m->openOutputFile(rare+".temp", rout); outputNames.push_back(rare); outputTypes["list"].push_back(rare); variables["[tag2]"] = "abund"; string abund = getOutputFileName("list",variables); - m->openOutputFile(abund, aout); + m->openOutputFile(abund+".temp", aout); outputNames.push_back(abund); outputTypes["list"].push_back(abund); if (rareNames.size() != 0) { rout << thisList->getLabel() << '\t' << numRareBins << '\t'; } if (abundNames.size() != 0) { aout << thisList->getLabel() << '\t' << numAbundBins << '\t'; } - + + vector binLabels = thisList->getLabels(); + string rareHeader = "label\tnumOtus\t"; string abundHeader = "label\tnumOtus\t"; for (int i = 0; i < thisList->getNumBins(); i++) { if (m->control_pressed) { break; } @@ -525,8 +527,8 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi for (int j = 0; j < names.size(); j++) { size += ct.getNumSeqs(names[j]); } } - if (size <= cutoff) { rout << bin << '\t'; } - else { aout << bin << '\t'; } + if (size <= cutoff) { rout << bin << '\t'; rareHeader += binLabels[i] + '\t'; } + else { aout << bin << '\t'; abundHeader += binLabels[i] + '\t'; } } if (rareNames.size() != 0) { rout << endl; } @@ -534,6 +536,21 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi rout.close(); aout.close(); + + //add headers + ofstream r; + m->openOutputFile(rare, r); + r << rareHeader << endl; + r.close(); + m->appendFiles(rare+".temp", rare); + m->mothurRemove(rare+".temp"); + + ofstream a; + m->openOutputFile(abund, a); + a << abundHeader << endl; + a.close(); + m->appendFiles(abund+".temp", abund); + m->mothurRemove(abund+".temp"); }else{ //parse names by abundance and group string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); @@ -564,14 +581,16 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi } map groupVector; + map groupLabels; map::iterator itGroup; map groupNumBins; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { groupNumBins[it3->first] = 0; groupVector[it3->first] = ""; + groupLabels[it3->first] = "label\tnumOtus\t"; } - + vector binLabels = thisList->getLabels(); for (int i = 0; i < thisList->getNumBins(); i++) { if (m->control_pressed) { break; } @@ -622,12 +641,14 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi for (itGroup = groupBins.begin(); itGroup != groupBins.end(); itGroup++) { - groupVector[itGroup->first] += itGroup->second + '\t'; + groupVector[itGroup->first] += itGroup->second + '\t'; + groupLabels[itGroup->first] += binLabels[i] + '\t'; } } //end list vector for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { + (*(filehandles[it3->first])) << groupLabels[it3->first] << endl; (*(filehandles[it3->first])) << thisList->getLabel() << '\t' << groupNumBins[it3->first] << '\t' << groupVector[it3->first] << endl; // label numBins listvector for that group (*(filehandles[it3->first])).close(); delete it3->second; diff --git a/subsamplecommand.cpp b/subsamplecommand.cpp index a89d191..3e95475 100644 --- a/subsamplecommand.cpp +++ b/subsamplecommand.cpp @@ -76,7 +76,7 @@ string SubSampleCommand::getOutputPattern(string type) { else if (type == "name") { pattern = "[filename],subsample,[extension]"; } else if (type == "group") { pattern = "[filename],subsample,[extension]"; } else if (type == "count") { pattern = "[filename],subsample,[extension]"; } - else if (type == "list") { pattern = "[filename],subsample,[extension]"; } + else if (type == "list") { pattern = "[filename],[distance],subsample,[extension]"; } else if (type == "taxonomy") { pattern = "[filename],subsample,[extension]"; } else if (type == "shared") { pattern = "[filename],[distance],subsample,[extension]"; } else if (type == "rabund") { pattern = "[filename],subsample,[extension]"; } @@ -993,16 +993,6 @@ int SubSampleCommand::getSubSampleList() { if (namefile != "") { m->readNames(namefile, nameMap); } - string thisOutputDir = outputDir; - if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - map variables; - variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); - variables["[extension]"] = m->getExtension(listfile); - string outputFileName = getOutputFileName("list", variables); - ofstream out; - m->openOutputFile(outputFileName, out); - outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); - InputData* input = new InputData(listfile, "list"); ListVector* list = input->getListVector(); string lastLabel = list->getLabel(); @@ -1029,7 +1019,7 @@ int SubSampleCommand::getSubSampleList() { //file mismatch quit if (list->getNumSeqs() != groupMap.getNumSeqs()) { m->mothurOut("[ERROR]: your list file contains " + toString(list->getNumSeqs()) + " sequences, and your groupfile contains " + toString(groupMap.getNumSeqs()) + ", please correct."); - m->mothurOutEndLine(); delete list; delete input; out.close(); outGroup.close(); return 0; + m->mothurOutEndLine(); delete list; delete input; outGroup.close(); return 0; } }else if (countfile != "") { if (ct.hasGroupInfo()) { @@ -1193,13 +1183,13 @@ int SubSampleCommand::getSubSampleList() { //as long as you are not at the end of the file or done wih the lines you want while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { delete list; delete input; out.close(); return 0; } + if (m->control_pressed) { delete list; delete input; return 0; } if(allLines == 1 || labels.count(list->getLabel()) == 1){ m->mothurOut(list->getLabel()); m->mothurOutEndLine(); - processList(list, out, subset); + processList(list, subset); processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -1213,7 +1203,7 @@ int SubSampleCommand::getSubSampleList() { list = input->getListVector(lastLabel); m->mothurOut(list->getLabel()); m->mothurOutEndLine(); - processList(list, out, subset); + processList(list, subset); processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -1231,7 +1221,7 @@ int SubSampleCommand::getSubSampleList() { } - if (m->control_pressed) { if (list != NULL) { delete list; } delete input; out.close(); return 0; } + if (m->control_pressed) { if (list != NULL) { delete list; } delete input; return 0; } //output error messages about any remaining user labels set::iterator it; @@ -1254,12 +1244,11 @@ int SubSampleCommand::getSubSampleList() { m->mothurOut(list->getLabel()); m->mothurOutEndLine(); - processList(list, out, subset); + processList(list, subset); delete list; list = NULL; } - out.close(); if (list != NULL) { delete list; } delete input; @@ -1336,14 +1325,26 @@ int SubSampleCommand::getSubSampleList() { } } //********************************************************************************************************************** -int SubSampleCommand::processList(ListVector*& list, ofstream& out, set& subset) { +int SubSampleCommand::processList(ListVector*& list, set& subset) { try { - + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + variables["[distance]"] = list->getLabel(); + string outputFileName = getOutputFileName("list", variables); + ofstream out; + m->openOutputFile(outputFileName, out); + outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + int numBins = list->getNumBins(); ListVector* temp = new ListVector(); temp->setLabel(list->getLabel()); + vector binLabels = list->getLabels(); + vector newLabels; for (int i = 0; i < numBins; i++) { if (m->control_pressed) { break; } @@ -1359,15 +1360,19 @@ int SubSampleCommand::processList(ListVector*& list, ofstream& out, set& if (newNames != "") { newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma temp->push_back(newNames); + newLabels.push_back(binLabels[i]); } } + temp->setLabels(newLabels); delete list; list = temp; - if (m->control_pressed) { return 0; } + if (m->control_pressed) { out.close(); return 0; } + list->printHeaders(out); list->print(out); + out.close(); return 0; diff --git a/subsamplecommand.h b/subsamplecommand.h index 7b251ee..db4001a 100644 --- a/subsamplecommand.h +++ b/subsamplecommand.h @@ -57,7 +57,7 @@ private: int processShared(vector&); int processRabund(RAbundVector*&, ofstream&); int processSabund(SAbundVector*&, ofstream&); - int processList(ListVector*&, ofstream&, set&); + int processList(ListVector*&, set&); int getNames(); int readNames(); int getTax(set&); -- 2.39.2