X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=listseqscommand.cpp;h=d60470cdebcc70114afcb79cc08edbb333816292;hb=4160a27002f4a3ca436fcd62eca0366b09f8e901;hp=360e1955bab31055c4ad06f71c933a4228058386;hpb=c69e2e9749626cfbf1d6cb0125ae94f869e00b18;p=mothur.git diff --git a/listseqscommand.cpp b/listseqscommand.cpp index 360e195..d60470c 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -11,50 +11,55 @@ #include "sequence.hpp" #include "listvector.hpp" + //********************************************************************************************************************** -vector ListSeqsCommand::getValidParameters(){ +vector ListSeqsCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(palignreport); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -ListSeqsCommand::ListSeqsCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["accnos"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); + m->errorOut(e, "ListSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ListSeqsCommand::getRequiredParameters(){ +string ListSeqsCommand::getHelpString(){ try { - string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The list.seqs command reads a fasta, name, group, list, taxonomy or alignreport file and outputs a .accnos file containing sequence names.\n"; + helpString += "The list.seqs command parameters are fasta, name, group, list, taxonomy and alignreport. You must provide one of these parameters.\n"; + helpString += "The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n"; + helpString += "Example list.seqs(fasta=amazon.fasta).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "getRequiredParameters"); + m->errorOut(e, "ListSeqsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector ListSeqsCommand::getRequiredFiles(){ +ListSeqsCommand::ListSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["accnos"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); exit(1); } } @@ -68,9 +73,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -186,22 +189,6 @@ ListSeqsCommand::ListSeqsCommand(string option) { } //********************************************************************************************************************** -void ListSeqsCommand::help(){ - try { - m->mothurOut("The list.seqs command reads a fasta, name, group, list, taxonomy or alignreport file and outputs a .accnos file containing sequence names.\n"); - m->mothurOut("The list.seqs command parameters are fasta, name, group, list, taxonomy and alignreport. You must provide one of these parameters.\n"); - m->mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n"); - m->mothurOut("Example list.seqs(fasta=amazon.fasta).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int ListSeqsCommand::execute(){ try { @@ -226,6 +213,7 @@ int ListSeqsCommand::execute(){ ofstream out; m->openOutputFile(outputFileName, out); + outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); //output to .accnos file for (int i = 0; i < names.size(); i++) { @@ -237,12 +225,21 @@ int ListSeqsCommand::execute(){ out.close(); if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0; } - + + m->setAccnosFile(outputFileName); + m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); + m->mothurOut(outputFileName); m->mothurOutEndLine(); m->mothurOutEndLine(); + //set accnos file as new current accnosfile + string current = ""; + itTypes = outputTypes.find("accnos"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); } + } + return 0; } @@ -259,19 +256,33 @@ int ListSeqsCommand::readFasta(){ ifstream in; m->openInputFile(fastafile, in); string name; - + + //ofstream out; + //string newFastaName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "numsAdded.fasta"; + //m->openOutputFile(newFastaName, out); + //int count = 1; + //string lastName = ""; + while(!in.eof()){ if (m->control_pressed) { in.close(); return 0; } Sequence currSeq(in); name = currSeq.getName(); + //if (lastName == "") { lastName = name; } + //if (name != lastName) { count = 1; } + // lastName = name; + + //Sequence newSeq(name+"_"+toString(count), currSeq.getAligned()); + //newSeq.printSequence(out); if (name != "") { names.push_back(name); } m->gobble(in); + //count++; } in.close(); + //out.close(); return 0; @@ -444,6 +455,7 @@ int ListSeqsCommand::readTax(){ names.push_back(firstCol); m->gobble(in); + } in.close();