]> git.donarmstrong.com Git - mothur.git/commitdiff
added list parameter to get.seqs and remove.seqs and added readline library for inter...
authorwestcott <westcott>
Tue, 8 Dec 2009 17:20:43 +0000 (17:20 +0000)
committerwestcott <westcott>
Tue, 8 Dec 2009 17:20:43 +0000 (17:20 +0000)
20 files changed:
Mothur.xcodeproj/project.pbxproj
collect.cpp
collectsharedcommand.cpp
engine.cpp
engine.hpp
getseqscommand.cpp
getseqscommand.h
heatmap.cpp
mothur.cpp
mothur.h
readotu.cpp
removeseqscommand.cpp
removeseqscommand.h
sharedcommand.cpp
sharedcommand.h
sharedlistvector.cpp
sharedrabundvector.cpp
sharedrabundvector.h
sharedsabundvector.cpp
venn.cpp

index 5dc0ea90e1cc5d932d128d2ec885505ffb5d47b7..1c2e31e9c5f37f61b624d71fb781be1bb7ed409c 100644 (file)
                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 */; };
                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 = "<group>"; };
                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; };
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               A7F5759710CEBC0600E20E47 /* libreadline.a in Frameworks */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                37D928490F21331F001D4494 /* summarydisplay.h */,
                                37519AB30F810FAE00FED5E8 /* venn.h */,
                                37519AB40F810FAE00FED5E8 /* venn.cpp */,
+                               A7F5759610CEBC0600E20E47 /* libreadline.a */,
                        );
                        name = Source;
                        sourceTree = "<group>";
                                        "_GLIBCXX_DEBUG_PEDANTIC=1",
                                );
                                INSTALL_PATH = /usr/local/bin;
+                               LIBRARY_SEARCH_PATHS = (
+                                       "$(inherited)",
+                                       "\"$(SRCROOT)/../readline-6.0\"",
+                               );
                                PRODUCT_NAME = mothur;
                                ZERO_LINK = YES;
                        };
                                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;
                                        "-ansi",
                                        "-pedantic",
                                        "-wall",
+                                       "-lreadline",
                                );
                                PREBINDING = NO;
                                SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
index c270ae1f525606d0b6f37e7eb1ffacecd2a0f47c..34191a07a324fb255120b02bfabba4b56c9d0c48 100644 (file)
@@ -106,7 +106,6 @@ try {
                                                                break;
                                                        }
                         }
-                        
        
                         //calculate at 0 and the given increment
                         if((i == 0) || (i+1) % increment == 0){
index a772eb18354fcbd109f2bcf258fad1d445a7f5e6..4254950ba8560efe2b8714b77f8905228ce8d92e 100644 (file)
@@ -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<string> processedLabels;
                set<string> userLabels = labels;
-                               
+                       
                //set users groups
                util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
                util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
index 371bda8fb83f2b8ceb4793c49f067ed5987f2094..811236003b5089171536c7e075b10b506baf670a 100644 (file)
@@ -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<<endl;
-}
-else break;
-}
-delay(2000);
-return 0;
-}*/
-                       
-                       //int letter = 0;
-                       //while ((letter != 10) && (letter != 13)) {
-                       //      letter = getch();
-                               
-                       //      cout << "char code = " << letter << endl;
-                               
-                       //      input += char(letter);
-                       //}
-               //      input = input.substr(0, input.length()-1); //cut off newline char
-               
-       //cout << input << endl;                
-                       
-                       getline(cin, input);
-                       if (cin.eof()) { input = "quit()"; }
                        
-                       //save command
-                       //previousInputs.push_back(input);
+                       input = getCommand();                   
                        
-                       mothurOutJustToLog(input);
+                       mothurOutJustToLog("mothur > " + 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);
        }
 }
index d4ec3b65a5cdd428c44967ed66ea454d7bc5b2f8..3aabf13de009dac3205d00c130d734d98de88dda 100644 (file)
@@ -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<string> getOptions() {   return options;         }
        virtual void terminateCommand(int);
 protected:
-//     string command;
        vector<string> options;
        CommandFactory* cFactory;
 };
@@ -57,8 +56,6 @@ public:
        virtual bool getInput();
 private:
        GlobalData* globaldata;
-       vector<string> previousInputs; //this is used to make the arrow keys work
-       
 };
 
 
index 315417a30586d290b2a692e04b2e0afacb1e6fb3..03ccb82f6ef5c9c437942420163ac286fa35c203 100644 (file)
@@ -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<string> 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 {
index 2bd0754b93715a347e517d7b11be3bf8f478e944..8b38a76f4a3c2bdcfbd0855d6a8be0ff3bad1714 100644 (file)
@@ -23,7 +23,7 @@ class GetSeqsCommand : public Command {
                
        private:
                set<string> 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();
                
 };
 
index 52a29e79e70dde14806e79960de618b7c3b4e4bf..e4e947ef6970787a5c05d340006f595dfe3830c5 100644 (file)
@@ -231,7 +231,7 @@ void HeatMap::sortSharedVectors(vector<SharedRAbundVector*>& 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; }
                        }
index 4e064b142d896cb1060d98c9574e42a4355a9efb..5941663f8e063ba3ee6664ba47ee2cc3c7860522 100644 (file)
@@ -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");
index 5c1880d569eeb7f37089c1a2d418f8fadf7b4ab7..78ccf1105795ec6dd018ae5820c5ceca2110c505 100644 (file)
--- a/mothur.h
+++ b/mothur.h
 #include <cerrno>
 #include <ctime>
 #include <limits>
+#include <readline/readline.h>
+#include <readline/history.h>
 
+/***********************************************************************/
 
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
        #include <sys/wait.h>
        #include <unistd.h>
+#else
+       #include <conio.h> //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<string> group){
+       
+       for (int i = 0; i < group.size(); i++) {
+               if (group[i] == member) {  return true;         }
+       }
+       
+       return false;
+}
 
 /***********************************************************************/
 
index 1f64919825bbd8692043b4e8d16feaaf5e727e12..84132ae5bdecda6f1e967dffdbeb284cfd281f23 100644 (file)
@@ -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) {
index 28f8cf7a6d890b0c688c388b3a2c0e8c8438ba27..790cf79f43505ac56e52681ff86a572ab3453e79 100644 (file)
@@ -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<string> 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 {
index 434983e8e4c5909be8a083cf8251cee34b0d27ce..1ad1eee835e4ba0bf48e1be44b7c89631367f22e 100644 (file)
@@ -23,7 +23,7 @@ class RemoveSeqsCommand : public Command {
                
        private:
                set<string> 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();
                
 };
 
index 0dcdfc0143b12ae0c827086465a16bfb486dc66b..c827207f76529ebf79e8008deea7f245498a40b6 100644 (file)
@@ -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<string> processedLabels;
                set<string> 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<SharedRAbundVector*> thislookup) {
        }
 }
 //**********************************************************************************************************************
+void SharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
+       try {
+               
+               vector<SharedRAbundVector*> 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;
index b305e9a7d9f3256eef03cac34387caea99f4b4ae..5b922b6d6255eb993f8607fedc9696d4054f7caa 100644 (file)
@@ -35,6 +35,7 @@ private:
        void printSharedData(vector<SharedRAbundVector*>);
        void createMisMatchFile();
        bool isValidGroup(string, vector<string>);
+       void eliminateZeroOTUS(vector<SharedRAbundVector*>&);
        
        GlobalData* globaldata;
        ReadOTUFile* read;
@@ -44,7 +45,7 @@ private:
        vector<string> groups;
        ofstream out;
        string filename, fileroot;
-       bool firsttime;
+       bool firsttime, pickedGroups;
        map<string, ofstream*> filehandles;
        map<string, ofstream*>::iterator it3;
 
index 6cac9b1d9512a16d15eef553d351de0b16771b6e..4303cfde13d3c4250c8f952c7a6eeb4bd9a2553d 100644 (file)
@@ -263,10 +263,8 @@ vector<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
        try {
                SharedUtil* util;
                util = new SharedUtil();
-               vector<SharedRAbundVector*> lookup;
-               vector<SharedRAbundVector*> lookup2;
-               map<string, SharedRAbundVector*> finder;
-               map<string, SharedRAbundVector*>::iterator it;
+               vector<SharedRAbundVector*> lookup;  //contains just the groups the user selected
+               map<string, SharedRAbundVector*> finder;  //contains all groups in groupmap
                string group, names, name;
        
                util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups);
@@ -277,10 +275,11 @@ vector<SharedRAbundVector*> 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<numBins;i++){
                        names = get(i);  
@@ -288,30 +287,18 @@ vector<SharedRAbundVector*> 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");
index 142f787e24ac3663c19783874721299a071336cf..25f9dd3bea207be00b1b35e264d604dd1e9b3a54 100644 (file)
@@ -93,8 +93,8 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0),
                for(int i=0;i<num;i++){
                        f >> 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<num;i++){
                                f >> 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 <individual> 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++;
index 14ec1b8e95d1aebea828c804ea1abc2e75b27217..8f4227eebe0c21823a6f25d22ed3e29dbee79ab3 100644 (file)
@@ -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();
index 8282f66878e9f29324b136b243956c5a33f07243..9b89921ee0ff028dee0b75eb0453816015cdf094 100644 (file)
@@ -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<data[i].abundance;j++){
-                               rav.push_back(i, binNumber, data[i].group);
-                               binNumber++;
+                               rav.push_back(i, data[i].group);
                        }
                }
                sort(rav.rbegin(), rav.rend(), compareMembers);
index 3961cd7bde9394b6b4702c08b55c1b96f1db4fa1..8370701f9e4910fac97ff3849cd8a1c89ed28d0a 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -232,7 +232,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> 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<SharedRAbundVector*> lookup, vector<Calculator*> 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<SharedRAbundVector*> lookup, vector<Calculator*> 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();