X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=secondarystructurecommand.cpp;h=3354665852ce1b5a95b9ecc7cc673d5083b25d8b;hp=2b84cc365d4796363bd3e4c5612abb246cfc5aab;hb=df7e3ff9f68ef157b0328a2d353c3258c5d45d89;hpb=e150b0b0664caec517485ee6d69dcdade6dcae77 diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index 2b84cc3..3354665 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -9,14 +9,17 @@ #include "secondarystructurecommand.h" #include "sequence.hpp" +#include "counttable.h" //********************************************************************************************************************** vector AlignCheckCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pmap("map", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pmap); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","aligncheck",false,true,true); parameters.push_back(pfasta); + CommandParameter pmap("map", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pmap); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pcount); + 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); } @@ -31,7 +34,7 @@ vector AlignCheckCommand::setParameters(){ string AlignCheckCommand::getHelpString(){ try { string helpString = ""; - helpString += "The align.check command reads a fasta file and map file.\n"; + helpString += "The align.check command reads a fasta file and map file as well as an optional name or count file.\n"; helpString += "It outputs a file containing the secondary structure matches in the .align.check file.\n"; helpString += "The align.check command parameters are fasta and map, both are required.\n"; helpString += "The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"; @@ -45,6 +48,21 @@ string AlignCheckCommand::getHelpString(){ } } //********************************************************************************************************************** +string AlignCheckCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "aligncheck") { pattern = "[filename],align.check"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getOutputPattern"); + exit(1); + } +} +//********************************************************************************************************************** AlignCheckCommand::AlignCheckCommand(){ try { abort = true; calledHelp = true; @@ -114,6 +132,14 @@ AlignCheckCommand::AlignCheckCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } + + it = parameters.find("count"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["count"] = inputDir + it->second; } + } } //check for required parameters @@ -122,23 +148,37 @@ AlignCheckCommand::AlignCheckCommand(string option) { else if (mapfile == "not found") { mapfile = ""; m->mothurOut("You must provide an map file."); m->mothurOutEndLine(); abort = true; } fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not open") { abort = true; } + if (fastafile == "not open") { fastafile = ""; 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); } + + countfile = validParameter.validFile(parameters, "count", true); + if (countfile == "not open") { abort = true; countfile = ""; } + else if (countfile == "not found") { countfile = ""; } + else { m->setCountTableFile(countfile); } + if ((countfile != "") && (namefile != "")) { m->mothurOut("You must enter ONLY ONE of the following: count or name."); m->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 += m->hasPath(fastafile); //if user entered a file with a path then preserve it } - + + if (countfile == "") { + if ((namefile == "") && (fastafile != "")){ + vector files; files.push_back(fastafile); + parser.getNameFile(files); + } + } } } @@ -158,6 +198,11 @@ int AlignCheckCommand::execute(){ readMap(); if (namefile != "") { nameMap = m->readNames(namefile); } + else if (countfile != "") { + CountTable ct; + ct.readTable(countfile, false); + nameMap = ct.getNameMap(); + } if (m->control_pressed) { return 0; } @@ -165,7 +210,9 @@ int AlignCheckCommand::execute(){ m->openInputFile(fastafile, in); ofstream out; - string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "align.check"; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outfile = getOutputFileName("aligncheck",variables); m->openOutputFile(outfile, out); @@ -182,7 +229,7 @@ int AlignCheckCommand::execute(){ int count = 0; while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outfile.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outfile); return 0; } Sequence seq(in); m->gobble(in); if (seq.getName() != "") { @@ -191,7 +238,7 @@ int AlignCheckCommand::execute(){ if (haderror == 1) { m->control_pressed = true; break; } int num = 1; - if (namefile != "") { + if ((namefile != "") || (countfile != "")) { //make sure this sequence is in the namefile, else error map::iterator it = nameMap.find(seq.getName()); @@ -219,7 +266,7 @@ int AlignCheckCommand::execute(){ in.close(); out.close(); - if (m->control_pressed) { remove(outfile.c_str()); return 0; } + if (m->control_pressed) { m->mothurRemove(outfile); return 0; } sort(pound.begin(), pound.end()); sort(dash.begin(), dash.end()); @@ -237,7 +284,7 @@ int AlignCheckCommand::execute(){ int ptile97_5 = int(size * 0.975); int ptile100 = size - 1; - if (m->control_pressed) { remove(outfile.c_str()); return 0; } + if (m->control_pressed) { m->mothurRemove(outfile); return 0; } m->mothurOutEndLine(); m->mothurOut("\t\tPound\tDash\tPlus\tEqual\tLoop\tTilde\tTotal"); m->mothurOutEndLine(); @@ -248,12 +295,12 @@ int AlignCheckCommand::execute(){ m->mothurOut("75%-tile:\t" + toString(pound[ptile75]) + "\t" + toString(dash[ptile75]) + "\t" + toString(plus[ptile75]) + "\t" + toString(equal[ptile75]) + "\t" + toString(loop[ptile75]) + "\t" + toString(tilde[ptile75]) + "\t" + toString(total[ptile75])); m->mothurOutEndLine(); m->mothurOut("97.5%-tile:\t" + toString(pound[ptile97_5]) + "\t" + toString(dash[ptile97_5]) + "\t" + toString(plus[ptile97_5]) + "\t" + toString(equal[ptile97_5]) + "\t" + toString(loop[ptile97_5]) + "\t" + toString(tilde[ptile97_5]) + "\t" + toString(total[ptile97_5])); m->mothurOutEndLine(); m->mothurOut("Maximum:\t" + toString(pound[ptile100]) + "\t" + toString(dash[ptile100]) + "\t" + toString(plus[ptile100]) + "\t" + toString(equal[ptile100]) + "\t" + toString(loop[ptile100]) + "\t" + toString(tilde[ptile100]) + "\t" + toString(total[ptile100])); m->mothurOutEndLine(); - if (namefile == "") { m->mothurOut("# of Seqs:\t" + toString(count)); m->mothurOutEndLine(); } + if ((namefile == "") && (countfile == "")) { m->mothurOut("# of Seqs:\t" + toString(count)); m->mothurOutEndLine(); } else { m->mothurOut("# of unique seqs:\t" + toString(count)); m->mothurOutEndLine(); m->mothurOut("total # of seqs:\t" + toString(size)); m->mothurOutEndLine(); } m->mothurOutEndLine(); - m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(outfile); m->mothurOutEndLine(); outputNames.push_back(outfile); outputTypes["aligncheck"].push_back(outfile); m->mothurOutEndLine();