X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=countseqscommand.cpp;h=8a18fc755e66a04d6013ecbf7dd088821088501a;hb=49d2b7459c5027557564b21e9487dadafbbbdc96;hp=a4464692607df14d08384f3cfdf112a4e18debb8;hpb=75962c819c16814e5c2340d99af1aa62e564dc20;p=mothur.git diff --git a/countseqscommand.cpp b/countseqscommand.cpp index a446469..8a18fc7 100644 --- a/countseqscommand.cpp +++ b/countseqscommand.cpp @@ -46,7 +46,26 @@ string CountSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string CountSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "summary") { outputFileName = "seq.count"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "CountSeqsCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** CountSeqsCommand::CountSeqsCommand(){ try { @@ -117,11 +136,12 @@ CountSeqsCommand::CountSeqsCommand(string option) { namefile = m->getNameFile(); if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current namefile and the name parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setNameFile(namefile); } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } else if (groupfile == "not found") { groupfile = ""; } + else { m->setGroupFile(groupfile); } groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = "all"; } @@ -146,9 +166,9 @@ int CountSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } ofstream out; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + ".seq.count"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("summary"); m->openOutputFile(outputFileName, out); outputTypes["summary"].push_back(outputFileName); - out << "Representative Sequence\t total\t"; + out << "Representative_Sequence\ttotal\t"; GroupMap* groupMap; if (groupfile != "") { @@ -156,7 +176,8 @@ int CountSeqsCommand::execute(){ //make sure groups are valid. takes care of user setting groupNames that are invalid or setting groups=all SharedUtil* util = new SharedUtil(); - util->setGroups(Groups, groupMap->namesOfGroups); + vector nameGroups = groupMap->getNamesOfGroups(); + util->setGroups(Groups, nameGroups); delete util; //sort groupNames so that the group title match the counts below, this is needed because the map object automatically sorts @@ -172,7 +193,8 @@ int CountSeqsCommand::execute(){ //open input file ifstream in; m->openInputFile(namefile, in); - + + int total = 0; while (!in.eof()) { if (m->control_pressed) { break; } @@ -215,14 +237,16 @@ int CountSeqsCommand::execute(){ out << firstCol << '\t' << names.size() << endl; } - + total += names.size(); } in.close(); if (groupfile != "") { delete groupMap; } - if (m->control_pressed) { remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { m->mothurRemove(outputFileName); return 0; } + m->mothurOutEndLine(); + m->mothurOut("Total number of sequences: " + toString(total)); m->mothurOutEndLine(); m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); m->mothurOut(outputFileName); m->mothurOutEndLine();