#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");
+ m->errorOut(e, "SeqSummaryCommand", "setParameters");
exit(1);
}
}
//**********************************************************************************************************************
-SeqSummaryCommand::SeqSummaryCommand(){
+string SeqSummaryCommand::getHelpString(){
try {
- abort = true; calledHelp = true;
- vector<string> tempOutNames;
- outputTypes["summary"] = tempOutNames;
- }
- catch(exception& e) {
- m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand");
- exit(1);
- }
-}
-//**********************************************************************************************************************
-vector<string> SeqSummaryCommand::getRequiredParameters(){
- 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);
}
}
//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();
//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"){
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);
}
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(){
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;
vector<int> ambigBases;
vector<int> longHomoPolymer;
- if (namefile != "") { readNames(); }
+ if (namefile != "") { nameMap = m->readNames(namefile); }
if (m->control_pressed) { return 0; }
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; }
//make sure this sequence is in the namefile, else error
map<string, int>::iterator it = nameMap.find(current.getName());
- if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + current.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; }
+ if (it == nameMap.end()) { cout << "[ERROR]: " << current.getName() << " is not in your namefile, please correct." << endl; m->control_pressed = true; }
else { num = it->second; }
}
}
}
/**********************************************************************************************************************/
-int SeqSummaryCommand::readNames() {
- try {
- //open input file
- ifstream in;
- m->openInputFile(namefile, in);
-
- while (!in.eof()) {
- if (m->control_pressed) { break; }
-
- string firstCol, secondCol;
- in >> firstCol >> secondCol; m->gobble(in);
-
- int num = m->getNumNames(secondCol);
-
- nameMap[firstCol] = num;
- }
- in.close();
-
- return 0;
-
- }
- catch(exception& e) {
- m->errorOut(e, "SeqSummaryCommand", "readNames");
- exit(1);
- }
-}
-
-/**********************************************************************************************************************/