X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=phylotypecommand.cpp;h=38d3bdf929f4ffc110f76ab0a55b12d66ef4ad08;hb=e10c72304ee071c0c40e0218a06d89dc4731cbc2;hp=e7d12969a73a1a2d6576593fc36ec8eb5a9b1d2a;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;p=mothur.git diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index e7d1296..38d3bdf 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -45,7 +45,7 @@ string PhylotypeCommand::getHelpString(){ helpString += "For the label parameter, levels count down from the root to keep the output similiar to mothur's other commands which report information from finer resolution to coarser resolutions.\n"; helpString += "The phylotype command should be in the following format: \n"; helpString += "phylotype(taxonomy=yourTaxonomyFile, cutoff=yourCutoff, label=yourLabels) \n"; - helpString += "Eaxample: phylotype(taxonomy=amazon.taxonomy, cutoff=5, label=1-3-5).\n\n"; + helpString += "Eaxample: phylotype(taxonomy=amazon.taxonomy, cutoff=5, label=1-3-5).\n"; return helpString; } catch(exception& e) { @@ -53,7 +53,28 @@ string PhylotypeCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string PhylotypeCommand::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 == "list") { outputFileName = "list"; } + else if (type == "rabund") { outputFileName = "rabund"; } + else if (type == "sabund") { outputFileName = "sabund"; } + 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, "PhylotypeCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** PhylotypeCommand::PhylotypeCommand(){ try { @@ -76,6 +97,7 @@ PhylotypeCommand::PhylotypeCommand(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(); @@ -127,12 +149,13 @@ PhylotypeCommand::PhylotypeCommand(string option) { m->mothurOut("No valid current files. taxonomy is a required parameter."); m->mothurOutEndLine(); abort = true; } - }else if (taxonomyFileName == "not open") { abort = true; } + }else if (taxonomyFileName == "not open") { taxonomyFileName = ""; abort = true; } + else { m->setTaxonomyFile(taxonomyFileName); } namefile = validParameter.validFile(parameters, "name", true); - if (namefile == "not open") { abort = true; } + if (namefile == "not open") { namefile = ""; abort = true; } else if (namefile == "not found") { namefile = ""; } - else { readNamesFile(); } + else { readNamesFile(); m->setNameFile(namefile); } //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"){ @@ -142,7 +165,7 @@ PhylotypeCommand::PhylotypeCommand(string option) { string temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "-1"; } - convert(temp, cutoff); + m->mothurConvert(temp, cutoff); label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; allLines = 1; } @@ -151,6 +174,11 @@ PhylotypeCommand::PhylotypeCommand(string option) { else { allLines = 1; } } + if (namefile == "") { + vector files; files.push_back(taxonomyFileName); + parser.getNameFile(files); + } + } } catch(exception& e) { @@ -191,13 +219,13 @@ int PhylotypeCommand::execute(){ string fileroot = outputDir + m->getRootName(m->getSimpleName(taxonomyFileName)); ofstream outList; - string outputListFile = fileroot + "tx.list"; + string outputListFile = fileroot + "tx." + getOutputFileNameTag("list"); m->openOutputFile(outputListFile, outList); ofstream outSabund; - string outputSabundFile = fileroot + "tx.sabund"; + string outputSabundFile = fileroot + "tx." + getOutputFileNameTag("sabund"); m->openOutputFile(outputSabundFile, outSabund); ofstream outRabund; - string outputRabundFile = fileroot + "tx.rabund"; + string outputRabundFile = fileroot + "tx." + getOutputFileNameTag("rabund"); m->openOutputFile(outputRabundFile, outRabund); outputNames.push_back(outputListFile); outputTypes["list"].push_back(outputListFile); @@ -213,7 +241,7 @@ int PhylotypeCommand::execute(){ if (m->control_pressed) { outRabund.close(); outSabund.close(); outList.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete tree; return 0; } @@ -225,6 +253,7 @@ int PhylotypeCommand::execute(){ ListVector list; list.setLabel(level); + //go through nodes and build listvector for (itCurrent = currentNodes.begin(); itCurrent != currentNodes.end(); itCurrent++) { @@ -237,18 +266,20 @@ int PhylotypeCommand::execute(){ //make the names compatable with listvector string name = ""; for (int i = 0; i < names.size(); i++) { - if (namefile != "") { - map::iterator itNames = namemap.find(names[i]); //make sure this name is in namefile - - if (itNames != namemap.end()) { name += namemap[names[i]] + ","; } //you found it in namefile - else { m->mothurOut(names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); exit(1); } - - }else{ name += names[i] + ","; } + + if (names[i] != "unknown") { + if (namefile != "") { + map::iterator itNames = namemap.find(names[i]); //make sure this name is in namefile + + if (itNames != namemap.end()) { name += namemap[names[i]] + ","; } //you found it in namefile + else { m->mothurOut(names[i] + " is not in your namefile, please correct."); m->mothurOutEndLine(); exit(1); } + + }else{ name += names[i] + ","; } + } } name = name.substr(0, name.length()-1); //rip off extra ',' - //add bin to list vector - list.push_back(name); + if (name != "") { list.push_back(name); } //caused by unknown } //print listvector @@ -284,7 +315,7 @@ int PhylotypeCommand::execute(){ delete tree; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }