]> git.donarmstrong.com Git - mothur.git/blobdiff - removeseqscommand.cpp
done testing 1.14.0
[mothur.git] / removeseqscommand.cpp
index b77e69f665b078c0bf52956099f455833eb81749..f1804ed8b826d00b4993a708804733335bb1b194 100644 (file)
 #include "listvector.hpp"
 
 //**********************************************************************************************************************
-
+vector<string> RemoveSeqsCommand::getValidParameters(){        
+       try {
+               string Array[] =  {"fasta","name", "group", "alignreport", "accnos", "list","taxonomy","outputdir","inputdir", "dups" };
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveSeqsCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+RemoveSeqsCommand::RemoveSeqsCommand(){        
+       try {
+               abort = true;
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["fasta"] = tempOutNames;
+               outputTypes["taxonomy"] = tempOutNames;
+               outputTypes["name"] = tempOutNames;
+               outputTypes["group"] = tempOutNames;
+               outputTypes["alignreport"] = tempOutNames;
+               outputTypes["list"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> RemoveSeqsCommand::getRequiredParameters(){     
+       try {
+               string Array[] =  {"accnos"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveSeqsCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> RemoveSeqsCommand::getRequiredFiles(){  
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveSeqsCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 RemoveSeqsCommand::RemoveSeqsCommand(string option)  {
        try {
                abort = false;
@@ -36,6 +88,15 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["fasta"] = tempOutNames;
+                       outputTypes["taxonomy"] = tempOutNames;
+                       outputTypes["name"] = tempOutNames;
+                       outputTypes["group"] = tempOutNames;
+                       outputTypes["alignreport"] = tempOutNames;
+                       outputTypes["list"] = tempOutNames;
+                       
                        //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 = "";         }
                        
@@ -210,8 +271,10 @@ int RemoveSeqsCommand::execute(){
 //**********************************************************************************************************************
 int RemoveSeqsCommand::readFasta(){
        try {
-               if (outputDir == "") {  outputDir += m->hasPath(fastafile);  }
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile);
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile);
+               
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -241,7 +304,7 @@ int RemoveSeqsCommand::readFasta(){
                out.close();
                
                if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName); 
+               outputTypes["fasta"].push_back(outputFileName); 
                
                return 0;
                
@@ -254,8 +317,10 @@ int RemoveSeqsCommand::readFasta(){
 //**********************************************************************************************************************
 int RemoveSeqsCommand::readList(){
        try {
-               if (outputDir == "") {  outputDir += m->hasPath(listfile);  }
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
+               
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -310,7 +375,7 @@ int RemoveSeqsCommand::readList(){
                out.close();
                
                if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName); 
+               outputTypes["list"].push_back(outputFileName); 
                                
                return 0;
 
@@ -323,8 +388,9 @@ int RemoveSeqsCommand::readList(){
 //**********************************************************************************************************************
 int RemoveSeqsCommand::readName(){
        try {
-               if (outputDir == "") {  outputDir += m->hasPath(namefile);  }
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile);
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile);
 
                ofstream out;
                m->openOutputFile(outputFileName, out);
@@ -338,7 +404,7 @@ int RemoveSeqsCommand::readName(){
                while(!in.eof()){
                        if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
 
-                       in >> firstCol;                         
+                       in >> firstCol;         m->gobble(in);          
                        in >> secondCol;                        
 
                        vector<string> parsedNames;
@@ -395,7 +461,7 @@ int RemoveSeqsCommand::readName(){
                out.close();
 
                if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName); 
+               outputTypes["name"].push_back(outputFileName);
                                
                return 0;
        }
@@ -408,8 +474,10 @@ int RemoveSeqsCommand::readName(){
 //**********************************************************************************************************************
 int RemoveSeqsCommand::readGroup(){
        try {
-               if (outputDir == "") {  outputDir += m->hasPath(groupfile);  }
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
+               
                ofstream out;
                m->openOutputFile(outputFileName, out);
 
@@ -437,7 +505,7 @@ int RemoveSeqsCommand::readGroup(){
                out.close();
                
                if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName); 
+               outputTypes["group"].push_back(outputFileName); 
                
                return 0;
        }
@@ -449,8 +517,9 @@ int RemoveSeqsCommand::readGroup(){
 //**********************************************************************************************************************
 int RemoveSeqsCommand::readTax(){
        try {
-               if (outputDir == "") {  outputDir += m->hasPath(taxfile);  }
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
 
@@ -478,7 +547,7 @@ int RemoveSeqsCommand::readTax(){
                out.close();
                
                if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName); 
+               outputTypes["taxonomy"].push_back(outputFileName);
                
                return 0;
        }
@@ -491,8 +560,10 @@ int RemoveSeqsCommand::readTax(){
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
 int RemoveSeqsCommand::readAlign(){
        try {
-               if (outputDir == "") {  outputDir += m->hasPath(alignfile);  }
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(alignfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
+               
                ofstream out;
                m->openOutputFile(outputFileName, out);
 
@@ -542,7 +613,7 @@ int RemoveSeqsCommand::readAlign(){
                out.close();
                
                if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName); 
+               outputTypes["alignreport"].push_back(outputFileName);
                
                return 0;