X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=otuhierarchycommand.cpp;h=e32e0b6c339c5b80108a3e874ce9c990ef5a2376;hb=01f8d2c7d982a6209211f5abbcf2a086fdf60d0a;hp=edfdaea6a1a5c02b1a8b0c96b10768be4770b1a5;hpb=1d898dc6edaf9e9f287fab53bf1f21fb29757a17;p=mothur.git diff --git a/otuhierarchycommand.cpp b/otuhierarchycommand.cpp index edfdaea..e32e0b6 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -46,7 +46,26 @@ string OtuHierarchyCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string OtuHierarchyCommand::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 == "otuheirarchy") { outputFileName = "otu.hierarchy"; } + 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, "OtuHierarchyCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** OtuHierarchyCommand::OtuHierarchyCommand(){ try { @@ -67,6 +86,7 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { vector myArray = setParameters(); @@ -109,6 +129,7 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { abort = true; } }else if (listFile == "not open") { abort = true; } + else { m->setListFile(listFile); } //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"){ @@ -178,13 +199,13 @@ int OtuHierarchyCommand::execute(){ } ofstream out; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + ".otu.hierarchy"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + "." + getOutputFileNameTag("otuheirarchy"); m->openOutputFile(outputFileName, out); //go through each bin in "big" otu and output the bins in "little" otu which created it for (int i = 0; i < lists[1].getNumBins(); i++) { - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(outputFileName); return 0; } string names = lists[1].get(i); @@ -217,7 +238,7 @@ int OtuHierarchyCommand::execute(){ out.close(); - if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(outputFileName); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine();