X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=secondarystructurecommand.cpp;h=c9002cab4a458c1ef9fbb3a2acb85706e01513dc;hb=c3396974063d6efc5e5850ddf4ed8ab65cc94bb9;hp=c2c104e71b1f535cd2a818afe268e5d7e1ed4c24;hpb=648ec37228eb16075ace911dd5a5773cdfe683da;p=mothur.git diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index c2c104e..c9002ca 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -10,44 +10,125 @@ #include "secondarystructurecommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector AlignCheckCommand::getValidParameters(){ + try { + string Array[] = {"fasta","map", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +AlignCheckCommand::AlignCheckCommand(){ + try { + abort = true; calledHelp = true; + vector tempOutNames; + outputTypes["aligncheck"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector AlignCheckCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","map"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector AlignCheckCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** -AlignCheckCommand::AlignCheckCommand(string option){ +AlignCheckCommand::AlignCheckCommand(string option) { try { - abort = false; - + abort = false; calledHelp = false; + haderror = 0; + //allow user to run help - if(option == "help") { help(); abort = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { //valid paramters for this command - string Array[] = {"fasta","map"}; + string Array[] = {"fasta","map", "outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); map parameters = parser.getParameters(); ValidParameters validParameter; + map::iterator it; //check to make sure all parameters are valid for command - for (map::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; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["aligncheck"] = tempOutNames; + + //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 = m->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; } + } + + it = parameters.find("map"); + //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["map"] = inputDir + it->second; } + } + } + //check for required parameters mapfile = validParameter.validFile(parameters, "map", true); if (mapfile == "not open") { abort = true; } - else if (mapfile == "not found") { mapfile = ""; mothurOut("You must provide an map file."); mothurOutEndLine(); abort = true; } + 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; } - else if (fastafile == "not found") { fastafile = ""; mothurOut("You must provide an fasta file."); mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { fastafile = ""; m->mothurOut("You must provide an fasta file."); 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 + } + } } catch(exception& e) { - errorOut(e, "AlignCheckCommand", "RemoveSeqsCommand"); + m->errorOut(e, "AlignCheckCommand", "RemoveSeqsCommand"); exit(1); } } @@ -55,15 +136,15 @@ AlignCheckCommand::AlignCheckCommand(string option){ void AlignCheckCommand::help(){ try { - mothurOut("The align.check command reads a fasta file and map file.\n"); - mothurOut("It outputs a file containing the secondary structure matches in the .align.check file.\n"); - mothurOut("The align.check command parameters are fasta and map, both are required.\n"); - mothurOut("The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"); - mothurOut("Example align.check(map=silva.ss.map, fasta=amazon.fasta).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + m->mothurOut("The align.check command reads a fasta file and map file.\n"); + m->mothurOut("It outputs a file containing the secondary structure matches in the .align.check file.\n"); + m->mothurOut("The align.check command parameters are fasta and map, both are required.\n"); + m->mothurOut("The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"); + m->mothurOut("Example align.check(map=silva.ss.map, 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) { - errorOut(e, "AlignCheckCommand", "help"); + m->errorOut(e, "AlignCheckCommand", "help"); exit(1); } } @@ -73,28 +154,31 @@ void AlignCheckCommand::help(){ int AlignCheckCommand::execute(){ try { - if (abort == true) { return 0; } + if (abort == true) { if (calledHelp) { return 0; } return 2; } //get secondary structure info. readMap(); ifstream in; - openInputFile(fastafile, in); + m->openInputFile(fastafile, in); ofstream out; - string outfile = getRootName(fastafile) + "align.check"; - openOutputFile(outfile, out); + string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "align.check"; + m->openOutputFile(outfile, out); out << "name" << '\t' << "pound" << '\t' << "dash" << '\t' << "plus" << '\t' << "equal" << '\t'; out << "loop" << '\t' << "tilde" << '\t' << "total" << endl; while(!in.eof()){ + if (m->control_pressed) { in.close(); out.close(); remove(outfile.c_str()); return 0; } - Sequence seq(in); gobble(in); + Sequence seq(in); m->gobble(in); if (seq.getName() != "") { statData data = getStats(seq.getAligned()); + if (haderror == 1) { break; } + out << seq.getName() << '\t' << data.pound << '\t' << data.dash << '\t' << data.plus << '\t' << data.equal << '\t'; out << data.loop << '\t' << data.tilde << '\t' << data.total << endl; } @@ -103,11 +187,18 @@ int AlignCheckCommand::execute(){ in.close(); out.close(); + if (m->control_pressed) { remove(outfile.c_str()); return 0; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outfile); m->mothurOutEndLine(); outputNames.push_back(outfile); outputTypes["aligncheck"].push_back(outfile); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "AlignCheckCommand", "execute"); + m->errorOut(e, "AlignCheckCommand", "execute"); exit(1); } } @@ -118,13 +209,13 @@ void AlignCheckCommand::readMap(){ structMap.resize(1, 0); ifstream in; - openInputFile(mapfile, in); + m->openInputFile(mapfile, in); while(!in.eof()){ int position; in >> position; structMap.push_back(position); - gobble(in); + m->gobble(in); } in.close(); @@ -135,7 +226,7 @@ void AlignCheckCommand::readMap(){ for(int i=0;imothurOut("Your map file contains an error: line " + toString(i) + " does not match line " + toString(structMap[i]) + "."); m->mothurOutEndLine(); } } } @@ -143,7 +234,7 @@ void AlignCheckCommand::readMap(){ } catch(exception& e) { - errorOut(e, "AlignCheckCommand", "readMap"); + m->errorOut(e, "AlignCheckCommand", "readMap"); exit(1); } } @@ -155,8 +246,11 @@ statData AlignCheckCommand::getStats(string sequence){ statData data; sequence = "*" + sequence; // need to pad the sequence so we can index it by 1 - int seqLength = sequence.length(); - for(int i=1;imothurOut("your sequences are " + toString(length) + " long, but your map file only contains " + toString(seqLength) + " entries. please correct."); m->mothurOutEndLine(); haderror = 1; return data; } + + for(int i=1;ierrorOut(e, "AlignCheckCommand", "getStats"); exit(1); } }