]> git.donarmstrong.com Git - mothur.git/blobdiff - seqsummarycommand.cpp
added chimera.uchime
[mothur.git] / seqsummarycommand.cpp
index c0f91969eda2277e4c8b02c3a78db2a7390716fe..620de95c333cdee1360157f7aa7068f3ce1f1f62 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,7 +112,11 @@ 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; }
+                       }       
                        
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { namefile = ""; abort = true; }
@@ -123,8 +128,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 +140,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 +147,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;
@@ -328,13 +316,14 @@ int SeqSummaryCommand::execute(){
                sort(seqLength.begin(), seqLength.end());
                sort(ambigBases.begin(), ambigBases.end());
                sort(longHomoPolymer.begin(), longHomoPolymer.end());
-               
-               int ptile0_25   = int(numSeqs * 0.025);
-               int ptile25             = int(numSeqs * 0.250);
-               int ptile50             = int(numSeqs * 0.500);
-               int ptile75             = int(numSeqs * 0.750);
-               int ptile97_5   = int(numSeqs * 0.975);
-               int ptile100    = numSeqs - 1;
+               int size = startPosition.size();
+                               
+               int ptile0_25   = int(size * 0.025);
+               int ptile25             = int(size * 0.250);
+               int ptile50             = int(size * 0.500);
+               int ptile75             = int(size * 0.750);
+               int ptile97_5   = int(size * 0.975);
+               int ptile100    = size - 1;
                
                //to compensate for blank sequences that would result in startPosition and endPostion equalling -1
                if (startPosition[0] == -1) {  startPosition[0] = 0;    }