]> git.donarmstrong.com Git - mothur.git/blobdiff - chimerauchimecommand.cpp
1.21.0
[mothur.git] / chimerauchimecommand.cpp
index 05ddaf6459959ad39bb83720547a1b458c7ae807..4c1db20ac23105ad29652a3f1feedfc38237c3a6 100644 (file)
@@ -11,6 +11,7 @@
 #include "deconvolutecommand.h"
 #include "uc.h"
 #include "sequence.hpp"
+#include "referencedb.h"
 
 
 //**********************************************************************************************************************
@@ -40,7 +41,7 @@ vector<string> ChimeraUchimeCommand::setParameters(){
                CommandParameter pmaxlen("maxlen", "Number", "", "10000", "", "", "",false,false); parameters.push_back(pmaxlen);
                CommandParameter pucl("ucl", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pucl);
                CommandParameter pqueryfract("queryfract", "Number", "", "0.5", "", "", "",false,false); parameters.push_back(pqueryfract);
-               
+
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
                return myArray;
@@ -112,7 +113,8 @@ ChimeraUchimeCommand::ChimeraUchimeCommand(){
 //***************************************************************************************************************
 ChimeraUchimeCommand::ChimeraUchimeCommand(string option)  {
        try {
-               abort = false; calledHelp = false;   
+               abort = false; calledHelp = false; 
+               ReferenceDB* rdb = ReferenceDB::getInstance();
                
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
@@ -300,7 +302,6 @@ ChimeraUchimeCommand::ChimeraUchimeCommand(string option)  {
                        //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 = ""; }
                        
-                       
                        string path;
                        it = parameters.find("reference");
                        //user has given a template file
@@ -313,12 +314,29 @@ ChimeraUchimeCommand::ChimeraUchimeCommand(string option)  {
                                        
                                        templatefile = validParameter.validFile(parameters, "reference", true);
                                        if (templatefile == "not open") { abort = true; }
-                                       else if (templatefile == "not found") { templatefile = "";  m->mothurOut("reference is a required parameter for the chimera.uchime command."); m->mothurOutEndLine(); abort = true;  }  
+                                       else if (templatefile == "not found") { //check for saved reference sequences
+                                               if (rdb->getSavedReference() != "") {
+                                                       templatefile = rdb->getSavedReference();
+                                                       m->mothurOutEndLine();  m->mothurOut("Using sequences from " + rdb->getSavedReference() + "."); m->mothurOutEndLine();
+                                               }else {
+                                                       m->mothurOut("[ERROR]: You don't have any saved reference sequences and the reference parameter is a required."); 
+                                                       m->mothurOutEndLine();
+                                                       abort = true; 
+                                               }
+                                       }
                                }
                        }else if (hasName) {  templatefile = "self"; }
-                       else { templatefile = "";  m->mothurOut("reference is a required parameter for the chimera.uchime command, unless you have a namefile."); m->mothurOutEndLine(); abort = true;  }       
-
-                       
+                       else { 
+                               if (rdb->getSavedReference() != "") {
+                                       templatefile = rdb->getSavedReference();
+                                       m->mothurOutEndLine();  m->mothurOut("Using sequences from " + rdb->getSavedReference() + "."); m->mothurOutEndLine();
+                               }else {
+                                       m->mothurOut("[ERROR]: You don't have any saved reference sequences and the reference parameter is a required."); 
+                                       m->mothurOutEndLine();
+                                       templatefile = ""; abort = true; 
+                               } 
+                       }
+                               
                        string temp = validParameter.validFile(parameters, "processors", false);        if (temp == "not found"){       temp = m->getProcessors();      }
                        m->setProcessors(temp);
                        convert(temp, processors);
@@ -353,7 +371,8 @@ ChimeraUchimeCommand::ChimeraUchimeCommand(string option)  {
 
                        temp = validParameter.validFile(parameters, "skipgaps2", false);                                if (temp == "not found") { temp = "t"; }
                        skipgaps2 = m->isTrue(temp); 
-
+                       
+                       if (hasName && (templatefile != "self")) { m->mothurOut("You have provided a namefile and the reference parameter is not set to self. I am not sure what reference you are trying to use, aborting."); m->mothurOutEndLine(); abort=true; }
                }
        }
        catch(exception& e) {
@@ -416,7 +435,7 @@ int ChimeraUchimeCommand::execute(){
                                
                                while (!in.eof()) {
                                        
-                                       if (m->control_pressed) { in.close(); for (int j = 0; j < outputNames.size(); j++) {    remove(outputNames[j].c_str()); }  return 0; }
+                                       if (m->control_pressed) { in.close(); for (int j = 0; j < outputNames.size(); j++) {    m->mothurRemove(outputNames[j]);        }  return 0; }
                                        
                                        Sequence seq(in); m->gobble(in);
                                        seqs[seq.getName()] = seq.getAligned();
@@ -427,10 +446,10 @@ int ChimeraUchimeCommand::execute(){
                                vector<seqPriorityNode> nameMapCount;
                                int error = m->readNames(nameFile, nameMapCount, seqs);
                                
-                               if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) {        remove(outputNames[j].c_str()); }  return 0; }
+                               if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) {        m->mothurRemove(outputNames[j]);        }  return 0; }
                                
-                               if (error == 1) { for (int j = 0; j < outputNames.size(); j++) {        remove(outputNames[j].c_str()); }  return 0; }
-                               if (seqs.size() != nameMapCount.size()) { m->mothurOut( "The number of sequences in your fastafile does not match the number of sequences in your namefile, aborting."); m->mothurOutEndLine(); for (int j = 0; j < outputNames.size(); j++) {  remove(outputNames[j].c_str()); }  return 0; }
+                               if (error == 1) { for (int j = 0; j < outputNames.size(); j++) {        m->mothurRemove(outputNames[j]);        }  return 0; }
+                               if (seqs.size() != nameMapCount.size()) { m->mothurOut( "The number of sequences in your fastafile does not match the number of sequences in your namefile, aborting."); m->mothurOutEndLine(); for (int j = 0; j < outputNames.size(); j++) {  m->mothurRemove(outputNames[j]);        }  return 0; }
                                
                                sort(nameMapCount.begin(), nameMapCount.end(), compareSeqPriorityNodes);
                                
@@ -449,7 +468,7 @@ int ChimeraUchimeCommand::execute(){
                                #ifdef USE_MPI  
                                        }
                                #endif
-                               if (m->control_pressed) {  for (int j = 0; j < outputNames.size(); j++) {       remove(outputNames[j].c_str()); }  return 0;    }                               
+                               if (m->control_pressed) {  for (int j = 0; j < outputNames.size(); j++) {       m->mothurRemove(outputNames[j]);        }  return 0;    }                               
                        }
                        
                        if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]);  }//if user entered a file with a path then preserve it                               
@@ -457,7 +476,7 @@ int ChimeraUchimeCommand::execute(){
                        string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s]))  + "uchime.accnos";
                        string alnsFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s]))  + "uchime.alns";
                        
-                       if (m->control_pressed) {  for (int j = 0; j < outputNames.size(); j++) {       remove(outputNames[j].c_str()); }  return 0;    }
+                       if (m->control_pressed) {  for (int j = 0; j < outputNames.size(); j++) {       m->mothurRemove(outputNames[j]);        }  return 0;    }
                        
                        int numSeqs = 0;
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
@@ -466,10 +485,10 @@ int ChimeraUchimeCommand::execute(){
 #else
                        numSeqs = driver(outputFileName, fastaFileNames[s], accnosFileName, alnsFileName);
 #endif
-                       if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) {        remove(outputNames[j].c_str()); } return 0; }
+                       if (m->control_pressed) { for (int j = 0; j < outputNames.size(); j++) {        m->mothurRemove(outputNames[j]);        } return 0; }
                        
                        //remove file made for uchime
-                       if (templatefile == "self") {  remove(fastaFileNames[s].c_str()); }
+                       if (templatefile == "self") {  m->mothurRemove(fastaFileNames[s]); }
                        
                        outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName);
                        outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName);
@@ -811,14 +830,14 @@ int ChimeraUchimeCommand::createProcesses(string outputFileName, string filename
                                        num += temp;
                                        
                                        m->appendFiles((outputFileName + toString(j) + ".temp"), outputFileName);
-                                       remove((outputFileName + toString(j) + ".temp").c_str());
+                                       m->mothurRemove((outputFileName + toString(j) + ".temp"));
                                        
                                        m->appendFiles((accnos + toString(j) + ".temp"), accnos);
-                                       remove((accnos + toString(j) + ".temp").c_str());
+                                       m->mothurRemove((accnos + toString(j) + ".temp"));
                                        
                                        if (chimealns) {
                                                m->appendFiles((alns + toString(j) + ".temp"), alns);
-                                               remove((alns + toString(j) + ".temp").c_str());
+                                               m->mothurRemove((alns + toString(j) + ".temp"));
                                        }
                                }
                        }
@@ -873,26 +892,26 @@ int ChimeraUchimeCommand::createProcesses(string outputFileName, string filename
                        string tempFile =  outputFileName + toString(processIDS[i]) + ".num.temp";
                        m->openInputFile(tempFile, in);
                        if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
-                       in.close(); remove(tempFile.c_str());
+                       in.close(); m->mothurRemove(tempFile);
                }
                
                
                //append output files
                for(int i=0;i<processIDS[i];i++){
                        m->appendFiles((outputFileName + toString(processIDS[i]) + ".temp"), outputFileName);
-                       remove((outputFileName + toString(processIDS[i]) + ".temp").c_str());
+                       m->mothurRemove((outputFileName + toString(processIDS[i]) + ".temp"));
                        
                        m->appendFiles((accnos + toString(processIDS[i]) + ".temp"), accnos);
-                       remove((accnos + toString(processIDS[i]) + ".temp").c_str());
+                       m->mothurRemove((accnos + toString(processIDS[i]) + ".temp"));
                        
                        if (chimealns) {
                                m->appendFiles((alns + toString(processIDS[i]) + ".temp"), alns);
-                               remove((alns + toString(processIDS[i]) + ".temp").c_str());
+                               m->mothurRemove((alns + toString(processIDS[i]) + ".temp"));
                        }
                }
 #endif         
                //get rid of the file pieces.
-               for (int i = 0; i < files.size(); i++) { remove(files[i].c_str()); }
+               for (int i = 0; i < files.size(); i++) { m->mothurRemove(files[i]); }
 #endif         
                return num;     
        }