]> git.donarmstrong.com Git - mothur.git/blobdiff - removerarecommand.cpp
fixed io
[mothur.git] / removerarecommand.cpp
index 255448ece9d1ed6eb5c8d65b4d562644ddf73051..923ca72eccbd2f88bad0b36b0c15fba58f1b829c 100644 (file)
@@ -58,6 +58,31 @@ string RemoveRareCommand::getHelpString(){
                exit(1);
        }
 }
+//**********************************************************************************************************************
+string RemoveRareCommand::getOutputFileNameTag(string type, string inputName=""){      
+       try {
+        string outputFileName = "";
+               map<string, vector<string> >::iterator it;
+        
+        //is this a type this command creates
+        it = outputTypes.find(type);
+        if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+        else {
+            if (type == "rabund")            {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "sabund")    {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "shared")        {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "group")       {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "list")        {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
+        }
+        return outputFileName;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveRareCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
+
 //**********************************************************************************************************************
 RemoveRareCommand::RemoveRareCommand(){        
        try {
@@ -160,23 +185,28 @@ RemoveRareCommand::RemoveRareCommand(string option)  {
                        //check for file parameters
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { abort = true; }
-                       else if (listfile == "not found") {  listfile = "";  }  
+                       else if (listfile == "not found") {  listfile = "";  }
+                       else { m->setListFile(listfile); }
                        
                        sabundfile = validParameter.validFile(parameters, "sabund", true);
                        if (sabundfile == "not open") { abort = true; }
                        else if (sabundfile == "not found") {  sabundfile = "";  }      
+                       else { m->setSabundFile(sabundfile); }
                        
                        rabundfile = validParameter.validFile(parameters, "rabund", true);
                        if (rabundfile == "not open") { abort = true; }
                        else if (rabundfile == "not found") {  rabundfile = "";  }                              
+                       else { m->setRabundFile(rabundfile); }
                        
                        groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { groupfile = ""; abort = true; }
                        else if (groupfile == "not found") {  groupfile = "";  }        
+                       else { m->setGroupFile(groupfile); }
                        
                        sharedfile = validParameter.validFile(parameters, "shared", true);
                        if (sharedfile == "not open") { sharedfile = "";  abort = true; }
                        else if (sharedfile == "not found") {  sharedfile = "";  }
+                       else { m->setSharedFile(sharedfile); }
                        
                        if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { 
                                //is there are current file available for any of these?
@@ -215,7 +245,7 @@ RemoveRareCommand::RemoveRareCommand(string option)  {
                        
                        string temp = validParameter.validFile(parameters, "nseqs", false);      
                        if (temp == "not found") { m->mothurOut("nseqs is a required parameter."); m->mothurOutEndLine(); abort = true; }
-                       else { convert(temp, nseqs); }
+                       else { m->mothurConvert(temp, nseqs); }
                        
                        temp = validParameter.validFile(parameters, "bygroup", false);   if (temp == "not found") { temp = "f"; }
                        byGroup = m->isTrue(temp);
@@ -246,7 +276,7 @@ int RemoveRareCommand::execute(){
                if (listfile != "")                     {               processList();          }
                if (sharedfile != "")           {               processShared();        }
                
-               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str()); } return 0; }
+               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        m->mothurRemove(outputNames[i]); } return 0; }
                        
                if (outputNames.size() != 0) {
                        m->mothurOutEndLine();
@@ -296,9 +326,8 @@ int RemoveRareCommand::processList(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
-               string outputGroupFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" +  m->getExtension(groupfile);
-               
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile);
+               string outputGroupFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile);            
                ofstream out, outGroup;
                m->openOutputFile(outputFileName, out);
                
@@ -348,7 +377,8 @@ int RemoveRareCommand::processList(){
                if (groupfile != "") { 
                        groupMap = new GroupMap(groupfile); groupMap->readMap(); 
                        SharedUtil util;
-                       util.setGroups(Groups, groupMap->namesOfGroups);
+                       vector<string> namesGroups = groupMap->getNamesOfGroups();
+                       util.setGroups(Groups, namesGroups);
                        m->openOutputFile(outputGroupFileName, outGroup);
                }
                
@@ -360,7 +390,7 @@ int RemoveRareCommand::processList(){
                        
                        //for each bin
                        for (int i = 0; i < list->getNumBins(); i++) {
-                               if (m->control_pressed) {  if (groupfile != "") { delete groupMap; outGroup.close(); remove(outputGroupFileName.c_str()); } out.close();  remove(outputFileName.c_str());  return 0; }
+                               if (m->control_pressed) {  if (groupfile != "") { delete groupMap; outGroup.close(); m->mothurRemove(outputGroupFileName); } out.close();  m->mothurRemove(outputFileName);  return 0; }
                                
                                //parse out names that are in accnos file
                                string binnames = list->get(i);
@@ -417,7 +447,7 @@ int RemoveRareCommand::processSabund(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(sabundfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "pick" +  m->getExtension(sabundfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + getOutputFileNameTag("sabund", sabundfile);
                outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
 
                ofstream out;
@@ -516,7 +546,7 @@ int RemoveRareCommand::processRabund(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(rabundfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "pick" +  m->getExtension(rabundfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + getOutputFileNameTag("rabund", rabundfile);
                outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
                
                ofstream out;
@@ -619,11 +649,11 @@ int RemoveRareCommand::processRabund(){
 //**********************************************************************************************************************
 int RemoveRareCommand::processShared(){
        try {
-               m->Groups = Groups;
+               m->setGroups(Groups);
                
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(sharedfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "pick" +  m->getExtension(sharedfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("shared", sharedfile);
                outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
                
                ofstream out;