From: westcott Date: Tue, 8 Dec 2009 17:20:43 +0000 (+0000) Subject: added list parameter to get.seqs and remove.seqs and added readline library for inter... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=4ba6188707e67c638ea5ee3c787d5d07ccd07e3e added list parameter to get.seqs and remove.seqs and added readline library for interact engine --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 5dc0ea9..1c2e31e 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -180,6 +180,7 @@ A7B0450E106CEEC90046FC83 /* slayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7B0450D106CEEC90046FC83 /* slayer.cpp */; }; A7E4A783106913F900688F62 /* getsharedotucommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E4A782106913F900688F62 /* getsharedotucommand.cpp */; }; A7E4A824106A9AD700688F62 /* maligner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E4A823106A9AD700688F62 /* maligner.cpp */; }; + A7F5759710CEBC0600E20E47 /* libreadline.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A7F5759610CEBC0600E20E47 /* libreadline.a */; }; EB1216880F619B83004A865F /* bergerparker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB1216870F619B83004A865F /* bergerparker.cpp */; }; EB1216E50F61ACFB004A865F /* bstick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB1216E40F61ACFB004A865F /* bstick.cpp */; }; EB1217230F61C9AC004A865F /* sharedkstest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB1217220F61C9AC004A865F /* sharedkstest.cpp */; }; @@ -567,6 +568,7 @@ A7E4A782106913F900688F62 /* getsharedotucommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getsharedotucommand.cpp; sourceTree = SOURCE_ROOT; }; A7E4A822106A9AD700688F62 /* maligner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = maligner.h; sourceTree = SOURCE_ROOT; }; A7E4A823106A9AD700688F62 /* maligner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = maligner.cpp; sourceTree = SOURCE_ROOT; }; + A7F5759610CEBC0600E20E47 /* libreadline.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libreadline.a; path = "../readline-6.0/libreadline.a"; sourceTree = SOURCE_ROOT; }; C6859E8B029090EE04C91782 /* Mothur.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Mothur.1; sourceTree = ""; }; EB1216860F619B83004A865F /* bergerparker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bergerparker.h; sourceTree = SOURCE_ROOT; }; EB1216870F619B83004A865F /* bergerparker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bergerparker.cpp; sourceTree = SOURCE_ROOT; }; @@ -589,6 +591,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + A7F5759710CEBC0600E20E47 /* libreadline.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -681,6 +684,7 @@ 37D928490F21331F001D4494 /* summarydisplay.h */, 37519AB30F810FAE00FED5E8 /* venn.h */, 37519AB40F810FAE00FED5E8 /* venn.cpp */, + A7F5759610CEBC0600E20E47 /* libreadline.a */, ); name = Source; sourceTree = ""; @@ -1302,6 +1306,10 @@ "_GLIBCXX_DEBUG_PEDANTIC=1", ); INSTALL_PATH = /usr/local/bin; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/../readline-6.0\"", + ); PRODUCT_NAME = mothur; ZERO_LINK = YES; }; @@ -1313,6 +1321,10 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_MODEL_TUNING = G5; INSTALL_PATH = /usr/local/bin; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/../readline-6.0\"", + ); PRODUCT_NAME = mothur; }; name = Release; @@ -1355,6 +1367,7 @@ "-ansi", "-pedantic", "-wall", + "-lreadline", ); PREBINDING = NO; SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; diff --git a/collect.cpp b/collect.cpp index c270ae1..34191a0 100644 --- a/collect.cpp +++ b/collect.cpp @@ -106,7 +106,6 @@ try { break; } } - //calculate at 0 and the given increment if((i == 0) || (i+1) % increment == 0){ diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index a772eb1..4254950 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -229,7 +229,7 @@ int CollectSharedCommand::execute(){ //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; - + //set users groups util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect"); util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex); diff --git a/engine.cpp b/engine.cpp index 371bda8..8112360 100644 --- a/engine.cpp +++ b/engine.cpp @@ -14,6 +14,7 @@ #include "engine.hpp" + /***********************************************************************/ InteractEngine::InteractEngine(string path){ @@ -36,53 +37,13 @@ bool InteractEngine::getInput(){ string options = ""; int quitCommandCalled = 0; - while(quitCommandCalled != 1){ mothurOutEndLine(); - mothurOut("mothur > "); - - //get input char by char so you can check for use of arrow keys - //if (_kbhit()){ - // _getch(); // edit : if you want to check the arrow-keys you must call getch twice because special-keys have two values - // return _getch(); - //} - //return 0; // if no key is pressed - //setbuf(stdin, NULL); //no buffering -/*if(ch==0) -{ -ch=getch(); -if(ch==72) cout<<"up"; -else if(ch==75) cout<<"left"; -else if(ch==77) cout<<"right"; -else if(ch==80) cout<<"down"; -cout< " + input); mothurOutEndLine(); //allow user to omit the () on the quit command @@ -90,7 +51,7 @@ return 0; CommandOptionParser parser(input); commandName = parser.getCommandString(); - //cout << " command = " << commandName << endl; + options = parser.getOptionString(); if (commandName != "") { @@ -112,13 +73,28 @@ return 0; } } /***********************************************************************/ +string Engine::getCommand() { + try { + char* nextCommand = NULL; + + nextCommand = readline("mothur > "); + if(nextCommand != NULL) { add_history(nextCommand); } + + return nextCommand; + } + catch(exception& e) { + errorOut(e, "Engine", "getCommand"); + exit(1); + } +} +/***********************************************************************/ void Engine::terminateCommand(int dummy) { try { mothurOut("Stopping command."); mothurOutEndLine(); cFactory->getCommand(); //terminates command } catch(exception& e) { - errorOut(e, "InteractEngine", "terminateCommand"); + errorOut(e, "Engine", "terminateCommand"); exit(1); } } diff --git a/engine.hpp b/engine.hpp index d4ec3b6..3aabf13 100644 --- a/engine.hpp +++ b/engine.hpp @@ -25,11 +25,10 @@ public: Engine() { cFactory = new CommandFactory(); } virtual ~Engine(){ delete cFactory; } virtual bool getInput() = 0; -// string getCommand() { return command; } + virtual string getCommand(); vector getOptions() { return options; } virtual void terminateCommand(int); protected: -// string command; vector options; CommandFactory* cFactory; }; @@ -57,8 +56,6 @@ public: virtual bool getInput(); private: GlobalData* globaldata; - vector previousInputs; //this is used to make the arrow keys work - }; diff --git a/getseqscommand.cpp b/getseqscommand.cpp index 315417a..03ccb82 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -9,6 +9,7 @@ #include "getseqscommand.h" #include "sequence.hpp" +#include "listvector.hpp" //********************************************************************************************************************** @@ -21,7 +22,7 @@ GetSeqsCommand::GetSeqsCommand(string option){ else { //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport", "accnos" }; + string Array[] = {"fasta","name", "group", "alignreport", "accnos", "list"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -55,9 +56,13 @@ GetSeqsCommand::GetSeqsCommand(string option){ if (alignfile == "not open") { abort = true; } else if (alignfile == "not found") { alignfile = ""; } - if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, alignreport."); mothurOutEndLine(); abort = true; } + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { abort = true; } + else if (listfile == "not found") { listfile = ""; } - if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport."); mothurOutEndLine(); abort = true; } + if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, alignreport or listfile."); mothurOutEndLine(); abort = true; } + + if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport or listfile."); mothurOutEndLine(); abort = true; } } } @@ -70,9 +75,9 @@ GetSeqsCommand::GetSeqsCommand(string option){ void GetSeqsCommand::help(){ try { - mothurOut("The get.seqs command reads an .accnos file and one of the following file types: fasta, name, group or alignreport file.\n"); + mothurOut("The get.seqs command reads an .accnos file and one of the following file types: fasta, name, group, list or alignreport file.\n"); mothurOut("It outputs a file containing only the sequences in the .accnos file.\n"); - mothurOut("The get.seqs command parameters are accnos, fasta, name, group and alignreport. You must provide accnos and one of the other parameters.\n"); + mothurOut("The get.seqs command parameters are accnos, fasta, name, group, list and alignreport. You must provide accnos and one of the other parameters.\n"); mothurOut("The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n"); mothurOut("Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"); mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); @@ -98,6 +103,7 @@ int GetSeqsCommand::execute(){ else if (namefile != "") { readName(); } else if (groupfile != "") { readGroup(); } else if (alignfile != "") { readAlign(); } + else if (listfile != "") { readList(); } return 0; } @@ -151,7 +157,70 @@ void GetSeqsCommand::readFasta(){ exit(1); } } +//********************************************************************************************************************** +void GetSeqsCommand::readList(){ + try { + string outputFileName = getRootName(listfile) + "pick" + getExtension(listfile); + ofstream out; + openOutputFile(outputFileName, out); + + ifstream in; + openInputFile(listfile, in); + + bool wroteSomething = false; + + while(!in.eof()){ + //read in list vector + ListVector list(in); + + //make a new list vector + ListVector newList; + newList.setLabel(list.getLabel()); + + //for each bin + for (int i = 0; i < list.getNumBins(); i++) { + + //parse out names that are in accnos file + string binnames = list.get(i); + + 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 + if (names.count(name) == 1) { newNames += name + ","; } + } + + //get last name + if (names.count(binnames) == 1) { newNames += binnames; } + + //if there are names in this bin add to new list + if (newNames != "") { newList.push_back(newNames); } + } + + //print new listvector + if (newList.getNumBins() != 0) { + wroteSomething = true; + newList.print(out); + } + + gobble(in); + } + in.close(); + out.close(); + + if (wroteSomething == false) { + mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + remove(outputFileName.c_str()); + } + } + catch(exception& e) { + errorOut(e, "GetSeqsCommand", "readList"); + exit(1); + } +} //********************************************************************************************************************** void GetSeqsCommand::readName(){ try { diff --git a/getseqscommand.h b/getseqscommand.h index 2bd0754..8b38a76 100644 --- a/getseqscommand.h +++ b/getseqscommand.h @@ -23,7 +23,7 @@ class GetSeqsCommand : public Command { private: set names; - string accnosfile, fastafile, namefile, groupfile, alignfile; + string accnosfile, fastafile, namefile, groupfile, alignfile, listfile; bool abort; void readFasta(); @@ -31,6 +31,7 @@ class GetSeqsCommand : public Command { void readGroup(); void readAlign(); void readAccnos(); + void readList(); }; diff --git a/heatmap.cpp b/heatmap.cpp index 52a29e7..e4e947e 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -231,7 +231,7 @@ void HeatMap::sortSharedVectors(vector& lookup){ //fill lookup for (int j = 0; j < looktemp.size(); j++) { //if they are not shared then push to back, if they are not insert in front - if (count < 2) { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); } + if (count < 2) { lookup[j]->push_back(looktemp[j]->getAbundance(i), looktemp[j]->getGroup()); } //they are shared by some else { lookup[j]->insert(looktemp[j]->getAbundance(i), place[count], looktemp[j]->getGroup()); updatePlace = true; } } diff --git a/mothur.cpp b/mothur.cpp index 4e064b1..5941663 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -41,9 +41,9 @@ int main(int argc, char *argv[]){ //header - mothurOut("mothur v.1.7.0"); + mothurOut("mothur v.1.7.2"); mothurOutEndLine(); - mothurOut("Last updated: 11/23/2009"); + mothurOut("Last updated: 12/04/2009"); mothurOutEndLine(); mothurOutEndLine(); mothurOut("by"); diff --git a/mothur.h b/mothur.h index 5c1880d..78ccf11 100644 --- a/mothur.h +++ b/mothur.h @@ -45,11 +45,16 @@ #include #include #include +#include +#include +/***********************************************************************/ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) #include #include +#else + #include //allows unbuffered screen capture from stdin #endif using namespace std; @@ -481,6 +486,16 @@ inline int getNumSeqs(ifstream& file){ return numSeqs; } +/***********************************************************************/ + +inline bool inVector(string member, vector group){ + + for (int i = 0; i < group.size(); i++) { + if (group[i] == member) { return true; } + } + + return false; +} /***********************************************************************/ diff --git a/readotu.cpp b/readotu.cpp index 1f64919..84132ae 100644 --- a/readotu.cpp +++ b/readotu.cpp @@ -64,6 +64,9 @@ void ReadOTUFile::read(GlobalData* globaldata){ //memory leak prevention //if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList; } globaldata->gSharedList = SharedList; + delete inputSabund; + delete inputRabund; + delete inputList; } } catch(exception& e) { diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 28f8cf7..790cf79 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -9,6 +9,7 @@ #include "removeseqscommand.h" #include "sequence.hpp" +#include "listvector.hpp" //********************************************************************************************************************** @@ -21,7 +22,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){ else { //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport", "accnos" }; + string Array[] = {"fasta","name", "group", "alignreport", "accnos", "list" }; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -55,9 +56,13 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){ if (alignfile == "not open") { abort = true; } else if (alignfile == "not found") { alignfile = ""; } - if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, alignreport."); mothurOutEndLine(); abort = true; } + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { abort = true; } + else if (listfile == "not found") { listfile = ""; } - if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport."); mothurOutEndLine(); abort = true; } + if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, alignreport or list."); mothurOutEndLine(); abort = true; } + + if (parameters.size() > 2) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport, or list."); mothurOutEndLine(); abort = true; } } } @@ -70,9 +75,9 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){ void RemoveSeqsCommand::help(){ try { - mothurOut("The remove.seqs command reads an .accnos file and one of the following file types: fasta, name, group or alignreport file.\n"); + mothurOut("The remove.seqs command reads an .accnos file and one of the following file types: fasta, name, group, list or alignreport file.\n"); mothurOut("It outputs a file containing the sequences NOT in the .accnos file.\n"); - mothurOut("The remove.seqs command parameters are accnos, fasta, name, group and alignreport. You must provide accnos and one of the other parameters.\n"); + mothurOut("The remove.seqs command parameters are accnos, fasta, name, group, list and alignreport. You must provide accnos and one of the other parameters.\n"); mothurOut("The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n"); mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"); mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); @@ -98,6 +103,7 @@ int RemoveSeqsCommand::execute(){ else if (namefile != "") { readName(); } else if (groupfile != "") { readGroup(); } else if (alignfile != "") { readAlign(); } + else if (listfile != "") { readList(); } return 0; } @@ -149,7 +155,70 @@ void RemoveSeqsCommand::readFasta(){ exit(1); } } +//********************************************************************************************************************** +void RemoveSeqsCommand::readList(){ + try { + string outputFileName = getRootName(listfile) + "pick" + getExtension(listfile); + ofstream out; + openOutputFile(outputFileName, out); + + ifstream in; + openInputFile(listfile, in); + + bool wroteSomething = false; + + while(!in.eof()){ + //read in list vector + ListVector list(in); + + //make a new list vector + ListVector newList; + newList.setLabel(list.getLabel()); + + //for each bin + for (int i = 0; i < list.getNumBins(); i++) { + + //parse out names that are in accnos file + string binnames = list.get(i); + + 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 + if (names.count(name) == 0) { newNames += name + ","; } + } + + //get last name + if (names.count(binnames) == 0) { newNames += binnames; } + + //if there are names in this bin add to new list + if (newNames != "") { newList.push_back(newNames); } + } + + //print new listvector + if (newList.getNumBins() != 0) { + wroteSomething = true; + newList.print(out); + } + + gobble(in); + } + in.close(); + out.close(); + + if (wroteSomething == false) { + mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine(); + remove(outputFileName.c_str()); + } + } + catch(exception& e) { + errorOut(e, "RemoveSeqsCommand", "readList"); + exit(1); + } +} //********************************************************************************************************************** void RemoveSeqsCommand::readName(){ try { diff --git a/removeseqscommand.h b/removeseqscommand.h index 434983e..1ad1eee 100644 --- a/removeseqscommand.h +++ b/removeseqscommand.h @@ -23,7 +23,7 @@ class RemoveSeqsCommand : public Command { private: set names; - string accnosfile, fastafile, namefile, groupfile, alignfile; + string accnosfile, fastafile, namefile, groupfile, alignfile, listfile; bool abort; void readFasta(); @@ -31,6 +31,7 @@ class RemoveSeqsCommand : public Command { void readGroup(); void readAlign(); void readAccnos(); + void readList(); }; diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 0dcdfc0..c827207 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -20,6 +20,7 @@ SharedCommand::SharedCommand(){ filename = getRootName(filename); filename = filename + "shared"; openOutputFile(filename, out); + pickedGroups = false; groupMap = globaldata->gGroupmap; @@ -28,6 +29,7 @@ SharedCommand::SharedCommand(){ groups = groupMap->namesOfGroups; }else{ //they have specified groups groups = globaldata->Groups; + pickedGroups = true; } //fill filehandles with neccessary ofstreams @@ -114,12 +116,15 @@ int SharedCommand::execute(){ //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 = globaldata->labels; - + while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) { - + if(globaldata->allLines == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){ lookup = SharedList->getSharedRAbundVector(); + if (pickedGroups) { //check for otus with no seqs in them + eliminateZeroOTUS(lookup); + } mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); printSharedData(lookup); //prints info to the .shared file @@ -136,6 +141,9 @@ int SharedCommand::execute(){ SharedList = input->getSharedListVector(lastLabel); //get new list vector to process lookup = SharedList->getSharedRAbundVector(); + if (pickedGroups) { //check for otus with no seqs in them + eliminateZeroOTUS(lookup); + } mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); printSharedData(lookup); //prints info to the .shared file @@ -170,6 +178,9 @@ int SharedCommand::execute(){ SharedList = input->getSharedListVector(lastLabel); //get new list vector to process lookup = SharedList->getSharedRAbundVector(); + if (pickedGroups) { //check for otus with no seqs in them + eliminateZeroOTUS(lookup); + } mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); printSharedData(lookup); //prints info to the .shared file @@ -216,6 +227,46 @@ void SharedCommand::printSharedData(vector thislookup) { } } //********************************************************************************************************************** +void SharedCommand::eliminateZeroOTUS(vector& thislookup) { + try { + + vector newLookup; + for (int i = 0; i < thislookup.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(); + temp->setLabel(thislookup[i]->getLabel()); + temp->setGroup(thislookup[i]->getGroup()); + newLookup.push_back(temp); + } + + //for each bin + for (int i = 0; i < thislookup[0]->getNumBins(); i++) { + + //look at each sharedRabund and make sure they are not all zero + bool allZero = true; + for (int j = 0; j < thislookup.size(); j++) { + if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } + } + + //if they are not all zero add this bin + if (!allZero) { + for (int j = 0; j < thislookup.size(); j++) { + newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); + } + } + //else{ cout << "bin # " << i << " is all zeros" << endl; } + } + + for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } + thislookup = newLookup; + + + } + catch(exception& e) { + errorOut(e, "SharedCommand", "eliminateZeroOTUS"); + exit(1); + } +} +//********************************************************************************************************************** void SharedCommand::createMisMatchFile() { try { ofstream outMisMatch; diff --git a/sharedcommand.h b/sharedcommand.h index b305e9a..5b922b6 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -35,6 +35,7 @@ private: void printSharedData(vector); void createMisMatchFile(); bool isValidGroup(string, vector); + void eliminateZeroOTUS(vector&); GlobalData* globaldata; ReadOTUFile* read; @@ -44,7 +45,7 @@ private: vector groups; ofstream out; string filename, fileroot; - bool firsttime; + bool firsttime, pickedGroups; map filehandles; map::iterator it3; diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 6cac9b1..4303cfd 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -263,10 +263,8 @@ vector SharedListVector::getSharedRAbundVector() { try { SharedUtil* util; util = new SharedUtil(); - vector lookup; - vector lookup2; - map finder; - map::iterator it; + vector lookup; //contains just the groups the user selected + map finder; //contains all groups in groupmap string group, names, name; util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); @@ -277,10 +275,11 @@ vector SharedListVector::getSharedRAbundVector() { finder[globaldata->gGroupmap->namesOfGroups[i]] = temp; finder[globaldata->gGroupmap->namesOfGroups[i]]->setLabel(label); finder[globaldata->gGroupmap->namesOfGroups[i]]->setGroup(globaldata->gGroupmap->namesOfGroups[i]); - //*temp = getSharedRAbundVector(globaldata->Groups[i]); - lookup.push_back(finder[globaldata->gGroupmap->namesOfGroups[i]]); + if (inVector(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups)) { //if this group is in user groups + lookup.push_back(finder[globaldata->gGroupmap->namesOfGroups[i]]); + } } -//cout << "after blanks" << endl; + //fill vectors for(int i=0;i SharedListVector::getSharedRAbundVector() { name = names.substr(0,names.find_first_of(',')); names = names.substr(names.find_first_of(',')+1, names.length()); group = groupmap->getGroup(name); -//cout << i << '\t' << name << '\t' << group << endl; if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in } //get last name group = groupmap->getGroup(names); -//cout << i << '\t' << names << '\t' << group << endl; if(group == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in } - if (globaldata->Groups.size() == globaldata->gGroupmap->namesOfGroups.size()) { //no groups specified - lookup2 = lookup; - }else{ //delete unwanted groups - for (int i = 0; i < globaldata->Groups.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(*finder[globaldata->Groups[i]]); - lookup2.push_back(temp); - delete finder[globaldata->Groups[i]]; //so we don't get dup memory - } - } - - return lookup2; + return lookup; } catch(exception& e) { errorOut(e, "SharedListVector", "getSharedRAbundVector"); diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 142f787..25f9dd3 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -93,8 +93,8 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), for(int i=0;i> inputData; - lookup[0]->push_back(inputData, i, groupN); //abundance, bin, group - push_back(inputData, i, groupN); + lookup[0]->push_back(inputData, groupN); //abundance, bin, group + push_back(inputData, groupN); numSeqs += inputData; numBins++; if (inputData > maxRank) { maxRank = inputData; } @@ -125,7 +125,7 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), //fill vector. for(int i=0;i> inputData; - lookup[count]->push_back(inputData, i, groupN); //abundance, bin, group + lookup[count]->push_back(inputData, groupN); //abundance, bin, group } gobble(f); @@ -202,12 +202,12 @@ vector SharedRAbundVector::getData(){ } /***********************************************************************/ -void SharedRAbundVector::push_back(int binSize, int otu, string groupName){ +void SharedRAbundVector::push_back(int binSize, string groupName){ try { individual newGuy; newGuy.abundance = binSize; newGuy.group = groupName; - newGuy.bin = otu; + newGuy.bin = data.size(); data.push_back(newGuy); numBins++; diff --git a/sharedrabundvector.h b/sharedrabundvector.h index 14ec1b8..8f4227e 100644 --- a/sharedrabundvector.h +++ b/sharedrabundvector.h @@ -51,7 +51,7 @@ public: void sortD(); //Sorts the data in descending order. void push_front(int, int, string); //abundance, otu, groupname void insert(int, int, string); //abundance, otu, groupname - void push_back(int, int, string); //abundance, otu, groupname + void push_back(int, string); //abundance, groupname void pop_back(); void resize(int); int size(); diff --git a/sharedsabundvector.cpp b/sharedsabundvector.cpp index 8282f66..9b89921 100644 --- a/sharedsabundvector.cpp +++ b/sharedsabundvector.cpp @@ -191,11 +191,9 @@ SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){ try { SharedRAbundVector rav; - int binNumber = 0; for(int i=1;i<=data.size();i++){ for(int j=0;j lookup, vector vCalcs //merge BC and estimate with shared with A SharedRAbundVector* merge = new SharedRAbundVector(); for (int j = 0; j < lookup[1]->size(); j++) { - merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), j, ""); + merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), ""); } subset.clear(); @@ -243,7 +243,7 @@ void Venn::getPic(vector lookup, vector vCalcs //merge AC and estimate with shared with B merge = new SharedRAbundVector(); for (int j = 0; j < lookup[0]->size(); j++) { - merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), j, ""); + merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), ""); } subset.clear(); @@ -254,7 +254,7 @@ void Venn::getPic(vector lookup, vector vCalcs //merge AB and estimate with shared with C merge = new SharedRAbundVector(); for (int j = 0; j < lookup[0]->size(); j++) { - merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), j, ""); + merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), ""); } subset.clear();