X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=clearcutcommand.cpp;h=55fbe0a1dceb9a2d2c16e2f6936646d3e851ee19;hb=006601d68abe8d0061f77e8d28323b160750e343;hp=04dbc79aa15d3c4b6913a2e8131283b849dd90b9;hpb=e150b0b0664caec517485ee6d69dcdade6dcae77;p=mothur.git diff --git a/clearcutcommand.cpp b/clearcutcommand.cpp index 04dbc79..55fbe0a 100644 --- a/clearcutcommand.cpp +++ b/clearcutcommand.cpp @@ -86,7 +86,27 @@ string ClearcutCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ClearcutCommand::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 == "tree") { outputFileName = "tre"; } + else if (type == "matrixout") { outputFileName = ""; } + 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, "ClearcutCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** ClearcutCommand::ClearcutCommand(){ try { @@ -155,21 +175,21 @@ ClearcutCommand::ClearcutCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { fastafile = ""; abort = true; } else if (fastafile == "not found") { fastafile = ""; } - else { inputFile = fastafile; } + else { inputFile = fastafile; m->setFastaFile(fastafile); } phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { phylipfile = ""; abort = true; } else if (phylipfile == "not found") { phylipfile = ""; } - else { inputFile = phylipfile; } + else { inputFile = phylipfile; m->setPhylipFile(phylipfile); } if ((phylipfile == "") && (fastafile == "")) { //is there are current file available for either of these? //give priority to phylip, then fasta phylipfile = m->getPhylipFile(); - if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + if (phylipfile != "") { inputFile = phylipfile; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } else { fastafile = m->getFastaFile(); - if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + if (fastafile != "") { inputFile = fastafile; m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("No valid current files. You must provide a phylip or fasta file before you can use the clearcut command."); m->mothurOutEndLine(); abort = true; @@ -244,56 +264,55 @@ int ClearcutCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } //prepare filename - string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + "tre"; + string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + getOutputFileNameTag("tree"); outputNames.push_back(outputName); outputTypes["tree"].push_back(outputName); vector cPara; - char* tempClearcut = new char[8]; - strcpy(tempClearcut, "clearcut"); + char* tempClearcut = new char[9]; + *tempClearcut = '\0'; strncat(tempClearcut, "clearcut", 8); cPara.push_back(tempClearcut); //you gave us a distance matrix - if (phylipfile != "") { char* temp = new char[10]; strcpy(temp, "--distance"); cPara.push_back(temp); } + if (phylipfile != "") { char* temp = new char[11]; *temp = '\0'; strncat(temp, "--distance", 10); cPara.push_back(temp); } //you gave us a fastafile - if (fastafile != "") { char* temp = new char[11]; strcpy(temp, "--alignment"); cPara.push_back(temp); } + if (fastafile != "") { char* temp = new char[12]; *temp = '\0'; strncat(temp, "--alignment", 11); cPara.push_back(temp); } - if (version) { char* temp = new char[9]; strcpy(temp, "--version"); cPara.push_back(temp); } - if (verbose) { char* temp = new char[9]; strcpy(temp, "--verbose"); cPara.push_back(temp); } - if (quiet) { char* temp = new char[7]; strcpy(temp, "--quiet"); cPara.push_back(temp); } + if (version) { char* temp = new char[10]; *temp = '\0'; strncat(temp, "--version", 9); cPara.push_back(temp); } + if (verbose) { char* temp = new char[10]; *temp = '\0'; strncat(temp, "--verbose", 9); cPara.push_back(temp); } + if (quiet) { char* temp = new char[8]; *temp = '\0'; strncat(temp, "--quiet", 7); cPara.push_back(temp); } if (seed != "*") { string tempSeed = "--seed=" + seed; - char* temp = new char[tempSeed.length()]; - strcpy(temp, tempSeed.c_str()); + char* temp = new char[tempSeed.length()+1]; + *temp = '\0'; strncat(temp, tempSeed.c_str(), tempSeed.length()); cPara.push_back(temp); } - if (norandom) { char* temp = new char[10]; strcpy(temp, "--norandom"); cPara.push_back(temp); } - if (shuffle) { char* temp = new char[9]; strcpy(temp, "--shuffle"); cPara.push_back(temp); } - if (neighbor) { char* temp = new char[10]; strcpy(temp, "--neighbor"); cPara.push_back(temp); } + if (norandom) { char* temp = new char[11]; *temp = '\0'; strncat(temp, "--norandom", 10); cPara.push_back(temp); } + if (shuffle) { char* temp = new char[10]; *temp = '\0'; strncat(temp, "--shuffle", 9); cPara.push_back(temp); } + if (neighbor) { char* temp = new char[11]; *temp = '\0'; strncat(temp, "--neighbor", 10); cPara.push_back(temp); } string tempIn = "--in=" + inputFile; - char* tempI = new char[tempIn.length()]; - strcpy(tempI, tempIn.c_str()); + char* tempI = new char[tempIn.length()+1]; + *tempI = '\0'; strncat(tempI, tempIn.c_str(), tempIn.length()); cPara.push_back(tempI); - if (stdoutWanted) { char* temp = new char[8]; strcpy(temp, "--stdout"); cPara.push_back(temp); } + if (stdoutWanted) { char* temp = new char[9]; *temp = '\0'; strncat(temp, "--stdout", 8); cPara.push_back(temp); } else{ string tempOut = "--out=" + outputName; - - char* temp = new char[tempOut.length()]; - strcpy(temp, tempOut.c_str()); + char* temp = new char[tempOut.length()+1]; + *temp = '\0'; strncat(temp, tempOut.c_str(), tempOut.length()); cPara.push_back(temp); } - if (DNA) { char* temp = new char[5]; strcpy(temp, "--DNA"); cPara.push_back(temp); } - if (protein) { char* temp = new char[9]; strcpy(temp, "--protein"); cPara.push_back(temp); } - if (jukes) { char* temp = new char[7]; strcpy(temp, "--jukes"); cPara.push_back(temp); } - if (kimura) { char* temp = new char[8]; strcpy(temp, "--kimura"); cPara.push_back(temp); } + if (DNA) { char* temp = new char[6]; *temp = '\0'; strncat(temp, "--DNA", 5); cPara.push_back(temp); } + if (protein) { char* temp = new char[10]; *temp = '\0'; strncat(temp, "--protein", 9); cPara.push_back(temp); } + if (jukes) { char* temp = new char[8]; *temp = '\0'; strncat(temp, "--jukes", 7); cPara.push_back(temp); } + if (kimura) { char* temp = new char[9]; *temp = '\0'; strncat(temp, "--kimura", 8); cPara.push_back(temp); } if (matrixout != "") { string tempMatrix = "--matrixout=" + outputDir + matrixout; - char* temp = new char[tempMatrix.length()]; - strcpy(temp, tempMatrix.c_str()); + char* temp = new char[tempMatrix.length()+1]; + *temp = '\0'; strncat(temp, tempMatrix.c_str(), tempMatrix.length()); cPara.push_back(temp); outputNames.push_back((outputDir + matrixout)); outputTypes["matrixout"].push_back((outputDir + matrixout)); @@ -301,13 +320,13 @@ int ClearcutCommand::execute() { if (ntrees != "1") { string tempNtrees = "--ntrees=" + ntrees; - char* temp = new char[tempNtrees.length()]; - strcpy(temp, tempNtrees.c_str()); + char* temp = new char[tempNtrees.length()+1]; + *temp = '\0'; strncat(temp, tempNtrees.c_str(), tempNtrees.length()); cPara.push_back(temp); } - if (expblen) { char* temp = new char[9]; strcpy(temp, "--expblen"); cPara.push_back(temp); } - if (expdist) { char* temp = new char[9]; strcpy(temp, "--expdist"); cPara.push_back(temp); } + if (expblen) { char* temp = new char[10]; *temp = '\0'; strncat(temp, "--expblen", 9); cPara.push_back(temp); } + if (expdist) { char* temp = new char[10]; *temp = '\0'; strncat(temp, "--expdist", 9); cPara.push_back(temp); } char** clearcutParameters; clearcutParameters = new char*[cPara.size()];