X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=treegroupscommand.cpp;h=888f50202e3443855a99d82d71b126cf715ee380;hb=f06b339c5fc4b6d1b9d2a08fe16bf7670bf7aeb4;hp=3eeeae292e674dbc7823522ce8e35d8d531ab70e;hpb=f55cf350ca6643f8eb070d8336e1957699a3f109;p=mothur.git diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 3eeeae2..888f502 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -27,7 +27,7 @@ vector TreeGroupCommand::setParameters(){ CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "",true,false); parameters.push_back(pcalc); CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput); +//CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); @@ -70,6 +70,26 @@ string TreeGroupCommand::getHelpString(){ } } //********************************************************************************************************************** +string TreeGroupCommand::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 { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "TreeGroupCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** TreeGroupCommand::TreeGroupCommand(){ try { abort = true; calledHelp = true; @@ -442,7 +462,7 @@ int TreeGroupCommand::execute(){ if (m->control_pressed) { return 0; } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); Tree* newTree = createTree(matrix); @@ -570,13 +590,6 @@ vector< vector > TreeGroupCommand::makeSimsDist() { int TreeGroupCommand::makeSimsShared() { try { - numGroups = lookup.size(); - lines.resize(processors); - for (int i = 0; i < processors; i++) { - lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups); - lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups); - } - if (subsample) { if (subsampleSize == -1) { //user has not set size, set size = smallest samples size subsampleSize = lookup[0]->getNumSeqs(); @@ -601,8 +614,17 @@ int TreeGroupCommand::makeSimsShared() { lookup = temp; m->setGroups(Groups); } + + if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } } + numGroups = lookup.size(); + lines.resize(processors); + for (int i = 0; i < processors; i++) { + lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups); + lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups); + } + set processedLabels; set userLabels = labels; @@ -894,7 +916,7 @@ int TreeGroupCommand::process(vector thisLookup) { } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave.tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave." + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); //creates tree from similarity matrix and write out file @@ -907,7 +929,7 @@ int TreeGroupCommand::process(vector thisLookup) { if (m->control_pressed) { break; } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".all.tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".all." + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream outAll; @@ -948,7 +970,7 @@ int TreeGroupCommand::process(vector thisLookup) { Tree* conTree = consensus.getTree(trees); //create a new filename - string conFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".cons.tre"; + string conFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".cons." + getOutputFileNameTag("tree"); outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); ofstream outTree; m->openOutputFile(conFile, outTree); @@ -976,7 +998,7 @@ int TreeGroupCommand::process(vector thisLookup) { } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); //creates tree from similarity matrix and write out file