]> git.donarmstrong.com Git - mothur.git/blobdiff - seqsummarycommand.cpp
added warning about merging with something above cutoff to cluster. working on chimeras
[mothur.git] / seqsummarycommand.cpp
index 82a1d2473a0bc35282abd46a5998ae65fbcce1bf..8b07b857c73930bb24265c58da93b7702dccf42d 100644 (file)
@@ -21,24 +21,45 @@ SeqSummaryCommand::SeqSummaryCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"fasta"};
+                       string Array[] =  {"fasta","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string,string>::iterator it;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                       }
+                       
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
                        else if (fastafile == "not found") { fastafile = ""; mothurOut("fasta is a required parameter for the summary.seqs command."); mothurOutEndLine(); abort = true;  }     
                        
+                       //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 = ""; 
+                               outputDir += hasPath(fastafile); //if user entered a file with a path then preserve it  
+                       }
+
                }
        }
        catch(exception& e) {
@@ -78,7 +99,7 @@ int SeqSummaryCommand::execute(){
                int numSeqs = 0;
 
                ofstream outSummary;
-               string summaryFile = fastafile + ".summary";
+               string summaryFile = outputDir + getSimpleName(fastafile) + ".summary";
                openOutputFile(summaryFile, outSummary);
                
                vector<int> startPosition;
@@ -91,18 +112,20 @@ int SeqSummaryCommand::execute(){
 
                while(!inFASTA.eof()){
                        Sequence current(inFASTA);
-                       startPosition.push_back(current.getStartPos());
-                       endPosition.push_back(current.getEndPos());
-                       seqLength.push_back(current.getNumBases());
-                       ambigBases.push_back(current.getAmbigBases());
-                       longHomoPolymer.push_back(current.getLongHomoPolymer());
-
-                       outSummary << current.getName() << '\t';
-                       outSummary << current.getStartPos() << '\t' << current.getEndPos() << '\t';
-                       outSummary << current.getNumBases() << '\t' << current.getAmbigBases() << '\t';
-                       outSummary << current.getLongHomoPolymer() << endl;
-                       
-                       numSeqs++;
+                       if (current.getName() != "") {
+                               startPosition.push_back(current.getStartPos());
+                               endPosition.push_back(current.getEndPos());
+                               seqLength.push_back(current.getNumBases());
+                               ambigBases.push_back(current.getAmbigBases());
+                               longHomoPolymer.push_back(current.getLongHomoPolymer());
+                               
+                               outSummary << current.getName() << '\t';
+                               outSummary << current.getStartPos() << '\t' << current.getEndPos() << '\t';
+                               outSummary << current.getNumBases() << '\t' << current.getAmbigBases() << '\t';
+                               outSummary << current.getLongHomoPolymer() << endl;
+                               
+                               numSeqs++;
+                       }
                        gobble(inFASTA);
                }
                inFASTA.close();
@@ -120,6 +143,10 @@ int SeqSummaryCommand::execute(){
                int ptile97_5   = int(numSeqs * 0.975);
                int ptile100    = numSeqs - 1;
                
+               //to compensate for blank sequences that would result in startPosition and endPostion equalling -1
+               if (startPosition[0] == -1) {  startPosition[0] = 0;    }
+               if (endPosition[0] == -1)       {  endPosition[0] = 0;          }
+               
                mothurOutEndLine();
                mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer"); mothurOutEndLine();
                mothurOut("Minimum:\t" + toString(startPosition[0]) + "\t" + toString(endPosition[0]) + "\t" + toString(seqLength[0]) + "\t" + toString(ambigBases[0]) + "\t" + toString(longHomoPolymer[0])); mothurOutEndLine();