X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=summarysharedcommand.cpp;h=6147832f70a750e1424939c9928a50db643fb8b8;hb=9b53f130ac9af5e95444ce2e817fce25ed19ff03;hp=77961f1c807387080b914af5059fea03d3844ff4;hpb=05c52893c6c2467381fe7e7b769d86b6209af2e1;p=mothur.git diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 77961f1..6147832 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -64,12 +64,34 @@ string SummarySharedCommand::getHelpString(){ } } //********************************************************************************************************************** +string SummarySharedCommand::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 = "shared.summary"; } + else if (type == "phylip") { outputFileName = "dist"; } + 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, "SummarySharedCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** SummarySharedCommand::SummarySharedCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; outputTypes["summary"] = tempOutNames; + outputTypes["phylip"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand"); @@ -104,6 +126,7 @@ SummarySharedCommand::SummarySharedCommand(string option) { //initialize outputTypes vector tempOutNames; outputTypes["summary"] = tempOutNames; + outputTypes["phylip"] = tempOutNames; //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); @@ -294,7 +317,7 @@ int SummarySharedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } ofstream outputFileHandle, outAll; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "shared.summary"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary"); //if the users entered no valid calculators don't execute command if (sumCalculators.size() == 0) { return 0; } @@ -325,7 +348,7 @@ int SummarySharedCommand::execute(){ outputFileHandle.close(); //create file and put column headers for multiple groups file - string outAllFileName = ((m->getRootName(sharedfile)) + "sharedmultiple.summary"); + string outAllFileName = ((m->getRootName(sharedfile)) + "multiple." + getOutputFileNameTag("summary")); if (mult == true) { m->openOutputFile(outAllFileName, outAll); outputNames.push_back(outAllFileName); @@ -365,11 +388,38 @@ int SummarySharedCommand::execute(){ return 0; } /******************************************************/ - + if (subsample) { + if (subsampleSize == -1) { //user has not set size, set size = smallest samples size + subsampleSize = lookup[0]->getNumSeqs(); + for (int i = 1; i < lookup.size(); i++) { + int thisSize = lookup[i]->getNumSeqs(); + + if (thisSize < subsampleSize) { subsampleSize = thisSize; } + } + }else { + m->clearGroups(); + Groups.clear(); + vector temp; + for (int i = 0; i < lookup.size(); i++) { + if (lookup[i]->getNumSeqs() < subsampleSize) { + m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); + delete lookup[i]; + }else { + Groups.push_back(lookup[i]->getGroup()); + temp.push_back(lookup[i]); + } + } + 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; delete input; return 0; } + } + /******************************************************/ //comparison breakup to be used by different processes later - numGroups = m->getNumGroups(); + numGroups = lookup.size(); lines.resize(processors); for (int i = 0; i < processors; i++) { lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups); @@ -527,11 +577,11 @@ int SummarySharedCommand::process(vector thisLookup, string vector< vector< vector > > calcDistsTotals; //each iter, one for each calc, then each groupCombos dists. this will be used to make .dist files vector< vector > calcDists; calcDists.resize(sumCalculators.size()); - for (int thisIter = 0; thisIter < iters; thisIter++) { + for (int thisIter = 0; thisIter < iters+1; thisIter++) { vector thisItersLookup = thisLookup; - if (subsample) { + if (subsample && (thisIter != 0)) { //we want the summary results for the whole dataset, then the subsampling SubSample sample; vector tempLabels; //dont need since we arent printing the sampled sharedRabunds @@ -710,15 +760,45 @@ int SummarySharedCommand::process(vector thisLookup, string #endif } - calcDistsTotals.push_back(calcDists); - if (subsample) { + if (subsample && (thisIter != 0)) { //we want the summary results for the whole dataset, then the subsampling + calcDistsTotals.push_back(calcDists); //clean up memory for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; } thisItersLookup.clear(); - for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); } + }else { + if (createPhylip) { + for (int i = 0; i < calcDists.size(); i++) { + if (m->control_pressed) { break; } + + //initialize matrix + vector< vector > matrix; //square matrix to represent the distance + matrix.resize(thisLookup.size()); + for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } + + for (int j = 0; j < calcDists[i].size(); j++) { + int row = calcDists[i][j].seq1; + int column = calcDists[i][j].seq2; + double dist = calcDists[i][j].dist; + + matrix[row][column] = dist; + matrix[column][row] = dist; + } + + string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + "." + getOutputFileNameTag("phylip"); + outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); + ofstream outDist; + m->openOutputFile(distFileName, outDist); + outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint); + + printSims(outDist, matrix); + + outDist.close(); + } + } } + for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); } } if (iters != 1) { @@ -799,7 +879,7 @@ int SummarySharedCommand::process(vector thisLookup, string stdmatrix[column][row] = stdDist; } - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave.dist"; + string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave." + getOutputFileNameTag("phylip"); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outAve; m->openOutputFile(distFileName, outAve); @@ -809,7 +889,7 @@ int SummarySharedCommand::process(vector thisLookup, string outAve.close(); - distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std.dist"; + distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std." + getOutputFileNameTag("phylip"); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outSTD; m->openOutputFile(distFileName, outSTD); @@ -820,38 +900,8 @@ int SummarySharedCommand::process(vector thisLookup, string outSTD.close(); } - }else { - if (createPhylip) { - for (int i = 0; i < calcDists.size(); i++) { - if (m->control_pressed) { break; } - - //initialize matrix - vector< vector > matrix; //square matrix to represent the distance - matrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } - - for (int j = 0; j < calcDists[i].size(); j++) { - int row = calcDists[i][j].seq1; - int column = calcDists[i][j].seq2; - double dist = calcDists[i][j].dist; - - matrix[row][column] = dist; - matrix[column][row] = dist; - } - - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; - outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); - ofstream outDist; - m->openOutputFile(distFileName, outDist); - outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint); - - printSims(outDist, matrix); - - outDist.close(); - } - } } - + return 0; } catch(exception& e) {