]> git.donarmstrong.com Git - mothur.git/blobdiff - removeotulabelscommand.cpp
added dereplicate parameter to chimera.slayer and chimera.persues. added minnumsample...
[mothur.git] / removeotulabelscommand.cpp
index 77305fb49babaa2640d6a69db0a25e0816ac6785..5359db8de28e3bfb6a0aa1611e6407e830ddd68b 100644 (file)
 //**********************************************************************************************************************
 vector<string> RemoveOtuLabelsCommand::setParameters(){        
        try {
-        CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos);
-        CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pconstaxonomy);
-               CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(potucorr);
-        CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pcorraxes);
-        CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+        CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(paccnos);
+        CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none","constaxonomy",false,false); parameters.push_back(pconstaxonomy);
+               CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none","otucorr",false,false); parameters.push_back(potucorr);
+        CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none","corraxes",false,false); parameters.push_back(pcorraxes);
+        CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -46,14 +46,31 @@ string RemoveOtuLabelsCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
+string RemoveOtuLabelsCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "constaxonomy")            {   pattern = "[filename],pick,[extension]";    }
+        else if (type == "otucorr")    {   pattern = "[filename],pick,[extension]";    }
+        else if (type == "corraxes")        {   pattern = "[filename],pick,[extension]";    }
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "RemoveOtuLabelsCommand", "getOutputPattern");
+        exit(1);
+    }
+}
+//**********************************************************************************************************************
 RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(){      
        try {
                abort = true; calledHelp = true;
                setParameters();
         vector<string> tempOutNames;
-               outputTypes["contaxonomy"] = tempOutNames; 
-        outputTypes["otu.corr"] = tempOutNames;
-        outputTypes["corr.axes"] = tempOutNames;
+               outputTypes["constaxonomy"] = tempOutNames; 
+        outputTypes["otucorr"] = tempOutNames;
+        outputTypes["corraxes"] = tempOutNames;
        }
        catch(exception& e) {
                m->errorOut(e, "RemoveOtuLabelsCommand", "RemoveOtuLabelsCommand");
@@ -126,9 +143,9 @@ RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(string option)  {
             }
             
             vector<string> tempOutNames;
-            outputTypes["contaxonomy"] = tempOutNames; 
-            outputTypes["otu.corr"] = tempOutNames;
-            outputTypes["corr.axes"] = tempOutNames;
+            outputTypes["constaxonomy"] = tempOutNames; 
+            outputTypes["otucorr"] = tempOutNames;
+            outputTypes["corraxes"] = tempOutNames;
             
                        //check for parameters
             accnosfile = validParameter.validFile(parameters, "accnos", true);
@@ -175,7 +192,7 @@ int RemoveOtuLabelsCommand::execute(){
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
         
         //get labels you want to keep
-               readAccnos();
+               labels = m->readAccnos(accnosfile);
                
                if (m->control_pressed) { return 0; }
                
@@ -204,7 +221,10 @@ int RemoveOtuLabelsCommand::readClassifyOtu(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(constaxonomyfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + "pick.taxonomy";
+               map<string, string> variables; 
+        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile));
+        variables["[extension]"] = m->getExtension(constaxonomyfile);
+               string outputFileName = getOutputFileName("constaxonomy", variables);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -253,7 +273,10 @@ int RemoveOtuLabelsCommand::readOtuAssociation(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(otucorrfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + "pick.corr";
+        map<string, string> variables; 
+        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile));
+        variables["[extension]"] = m->getExtension(otucorrfile);
+               string outputFileName = getOutputFileName("otucorr", variables);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -286,7 +309,7 @@ int RemoveOtuLabelsCommand::readOtuAssociation(){
         out.close();
                
                if (wroteSomething == false) { m->mothurOut("Your file only contains labels from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName);  outputTypes["otu.corr"].push_back(outputFileName);
+               outputNames.push_back(outputFileName);  outputTypes["otucorr"].push_back(outputFileName);
                
                m->mothurOut("Removed " + toString(removedCount) + " lines from your otu.corr file."); m->mothurOutEndLine();
                
@@ -303,7 +326,10 @@ int RemoveOtuLabelsCommand::readCorrAxes(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(corraxesfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + "pick.axes";
+        map<string, string> variables; 
+        variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile));
+        variables["[extension]"] = m->getExtension(corraxesfile);
+               string outputFileName = getOutputFileName("corraxes", variables);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -336,7 +362,7 @@ int RemoveOtuLabelsCommand::readCorrAxes(){
         out.close();
                
                if (wroteSomething == false) { m->mothurOut("Your file only contains labels from the .accnos file."); m->mothurOutEndLine();  }
-               outputNames.push_back(outputFileName);  outputTypes["corr.axes"].push_back(outputFileName);
+               outputNames.push_back(outputFileName);  outputTypes["corraxes"].push_back(outputFileName);
                
                m->mothurOut("Removed " + toString(removedCount) + " lines from your corr.axes file."); m->mothurOutEndLine();
                
@@ -348,32 +374,6 @@ int RemoveOtuLabelsCommand::readCorrAxes(){
                exit(1);
        }
 }
-
-//**********************************************************************************************************************
-int RemoveOtuLabelsCommand::readAccnos(){
-       try {
-               
-               ifstream in;
-               m->openInputFile(accnosfile, in);
-               string name;
-               
-               while(!in.eof()){
-                       in >> name;
-            
-                       labels.insert(name);
-                       
-                       m->gobble(in);
-               }
-               in.close();     
-               
-               return 0;
-        
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RemoveOtuLabelsCommand", "readAccnos");
-               exit(1);
-       }
-}
 //**********************************************************************************************************************