]> git.donarmstrong.com Git - mothur.git/commitdiff
added count file to get.sabund and get.rabund commands. fixed bug in windows paralell...
authorSarahsWork <sarahswork@imac.westcotts.net>
Wed, 3 Apr 2013 15:03:57 +0000 (11:03 -0400)
committerSarahsWork <sarahswork@imac.westcotts.net>
Wed, 3 Apr 2013 15:03:57 +0000 (11:03 -0400)
getrabundcommand.cpp
getrabundcommand.h
getsabundcommand.cpp
getsabundcommand.h
pairwiseseqscommand.cpp
pairwiseseqscommand.h
preclustercommand.cpp
removerarecommand.cpp
removerarecommand.h
trimseqscommand.cpp

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