]> git.donarmstrong.com Git - mothur.git/blobdiff - seqsummarycommand.cpp
1.21.0
[mothur.git] / seqsummarycommand.cpp
index 8c13e7fbbd76895b751ae982b8df9a093e1c1ca9..2fbf6d1ca616033f4fd52993412f0e720f8187af 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> SeqSummaryCommand::getValidParameters(){        
+vector<string> SeqSummaryCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta","name","processors","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta);
+               CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
+               CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
+               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);          }
                return myArray;
        }
        catch(exception& e) {
-               m->errorOut(e, "SeqSummaryCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-SeqSummaryCommand::SeqSummaryCommand(){        
-       try {
-               abort = true; calledHelp = true; 
-               vector<string> tempOutNames;
-               outputTypes["summary"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand");
+               m->errorOut(e, "SeqSummaryCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> SeqSummaryCommand::getRequiredParameters(){     
+string SeqSummaryCommand::getHelpString(){     
        try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               string helpString = "";
+               helpString += "The summary.seqs command reads a fastafile and summarizes the sequences.\n";
+               helpString += "The summary.seqs command parameters are fasta, name and processors, fasta is required, unless you have a valid current fasta file.\n";
+               helpString += "The name parameter allows you to enter a name file associated with your fasta file. \n";
+               helpString += "The summary.seqs command should be in the following format: \n";
+               helpString += "summary.seqs(fasta=yourFastaFile, processors=2) \n";
+               helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n";       
+               return helpString;
        }
        catch(exception& e) {
-               m->errorOut(e, "SeqSummaryCommand", "getRequiredParameters");
+               m->errorOut(e, "SeqSummaryCommand", "getHelpString");
                exit(1);
        }
 }
+
 //**********************************************************************************************************************
-vector<string> SeqSummaryCommand::getRequiredFiles(){  
+SeqSummaryCommand::SeqSummaryCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["summary"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "SeqSummaryCommand", "getRequiredFiles");
+               m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand");
                exit(1);
        }
 }
@@ -65,11 +67,10 @@ SeqSummaryCommand::SeqSummaryCommand(string option)  {
                
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
-                       //valid paramters for this command
-                       string Array[] =  {"fasta","name","processors","outputdir","inputdir"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
@@ -111,11 +112,16 @@ SeqSummaryCommand::SeqSummaryCommand(string option)  {
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
-                       else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the summary.seqs command."); m->mothurOutEndLine(); abort = true;  }       
+                       else if (fastafile == "not found") {                            
+                               fastafile = m->getFastaFile(); 
+                               if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
+                               else {  m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
+                       }else { m->setFastaFile(fastafile); }   
                        
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { namefile = ""; abort = true; }
                        else if (namefile == "not found") { namefile = "";  }   
+                       else { m->setNameFile(namefile); }
                        
                        //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"){  
@@ -123,8 +129,9 @@ SeqSummaryCommand::SeqSummaryCommand(string option)  {
                                outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it       
                        }
                        
-                       string temp = validParameter.validFile(parameters, "processors", false);        if (temp == "not found"){       temp = "1";                             }
-                       convert(temp, processors); 
+                       string temp = validParameter.validFile(parameters, "processors", false);        if (temp == "not found"){       temp = m->getProcessors();      }
+                       m->setProcessors(temp);
+                       convert(temp, processors);
 
 
                }
@@ -134,27 +141,6 @@ SeqSummaryCommand::SeqSummaryCommand(string option)  {
                exit(1);
        }
 }
-//**********************************************************************************************************************
-
-void SeqSummaryCommand::help(){
-       try {
-               m->mothurOut("The summary.seqs command reads a fastafile and summarizes the sequences.\n");
-               m->mothurOut("The summary.seqs command parameters are fasta, name and processors, fasta is required.\n");
-               m->mothurOut("The name parameter allows you to enter a name file associated with your fasta file. \n");
-               m->mothurOut("The summary.seqs command should be in the following format: \n");
-               m->mothurOut("summary.seqs(fasta=yourFastaFile, processors=2) \n");
-               m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");     
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SeqSummaryCommand", "help");
-               exit(1);
-       }
-}
-
-//***************************************************************************************************************
-
-SeqSummaryCommand::~SeqSummaryCommand(){       /*      do nothing      */      }
-
 //***************************************************************************************************************
 
 int SeqSummaryCommand::execute(){
@@ -162,6 +148,9 @@ int SeqSummaryCommand::execute(){
                
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
+               //set current fasta to fastafile
+               m->setFastaFile(fastafile);
+               
                string summaryFile = outputDir + m->getSimpleName(fastafile) + ".summary";
                                
                int numSeqs = 0;
@@ -308,7 +297,7 @@ int SeqSummaryCommand::execute(){
                                        //append files
                                        for(int i=1;i<processors;i++){
                                                m->appendFiles((summaryFile + toString(processIDS[i]) + ".temp"), summaryFile);
-                                               remove((summaryFile + toString(processIDS[i]) + ".temp").c_str());
+                                               m->mothurRemove((summaryFile + toString(processIDS[i]) + ".temp"));
                                        }
                                }
                                
@@ -341,7 +330,7 @@ int SeqSummaryCommand::execute(){
                if (startPosition[0] == -1) {  startPosition[0] = 0;    }
                if (endPosition[0] == -1)       {  endPosition[0] = 0;          }
                
-               if (m->control_pressed) {  remove(summaryFile.c_str()); return 0; }
+               if (m->control_pressed) {  m->mothurRemove(summaryFile); return 0; }
                
                m->mothurOutEndLine();
                m->mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer"); m->mothurOutEndLine();
@@ -355,7 +344,7 @@ int SeqSummaryCommand::execute(){
                if (namefile == "") {  m->mothurOut("# of Seqs:\t" + toString(numSeqs)); m->mothurOutEndLine(); }
                else { m->mothurOut("# of unique seqs:\t" + toString(numSeqs)); m->mothurOutEndLine(); m->mothurOut("total # of seqs:\t" + toString(startPosition.size())); m->mothurOutEndLine(); }
                
-               if (m->control_pressed) {  remove(summaryFile.c_str()); return 0; }
+               if (m->control_pressed) {  m->mothurRemove(summaryFile); return 0; }
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();
@@ -578,7 +567,7 @@ int SeqSummaryCommand::createProcessesCreateSummary(vector<int>& startPosition,
                        for (int k = 0; k < tempNum; k++)                       {               in >> temp; longHomoPolymer.push_back(temp);    }               m->gobble(in);
                                
                        in.close();
-                       remove(tempFilename.c_str());
+                       m->mothurRemove(tempFilename);
                }
                
                return num;