X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=summarycommand.cpp;h=7a167a6432015b41cbd2b8304aaa7c3415542624;hb=16f9c4ab6f39769856b13e048eae2c8eaa413c02;hp=85f0970f25930f563616c5fba9bc27fecda9cf98;hpb=36a6b02cf7f09d2bc34376b588944a9ca73429c5;p=mothur.git diff --git a/summarycommand.cpp b/summarycommand.cpp index 85f0970..7a167a6 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -84,7 +84,26 @@ string SummaryCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string SummaryCommand::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 = "summary"; } + 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, "SummaryCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** SummaryCommand::SummaryCommand(){ try { @@ -288,13 +307,10 @@ int SummaryCommand::execute(){ numLines = 0; numCols = 0; - string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "summary"; - string fileNameAve = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "ave"; - string fileNameSTD = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "std"; - outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot); + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + getOutputFileNameTag("summary"); + string fileNameAve = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "ave-std." + getOutputFileNameTag("summary"); + outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot); - - if (inputFileNames.size() > 1) { m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); groupIndex[fileNameRoot] = groups[p]; @@ -369,18 +385,14 @@ int SummaryCommand::execute(){ m->openOutputFile(fileNameRoot, outputFileHandle); outputFileHandle << "label"; - ofstream outAve, outSTD; + ofstream outAve; if (subsample) { m->openOutputFile(fileNameAve, outAve); - m->openOutputFile(fileNameSTD, outSTD); - outputNames.push_back(fileNameAve); outputTypes["ave"].push_back(fileNameAve); - outputNames.push_back(fileNameSTD); outputTypes["std"].push_back(fileNameSTD); - outAve << "label"; outSTD << "label"; + outputNames.push_back(fileNameAve); outputTypes["summary"].push_back(fileNameAve); + outAve << "label\tmethod"; outAve.setf(ios::fixed, ios::floatfield); outAve.setf(ios::showpoint); - outSTD.setf(ios::fixed, ios::floatfield); outSTD.setf(ios::showpoint); if (inputFileNames.size() > 1) { groupIndex[fileNameAve] = groups[p]; - groupIndex[fileNameSTD] = groups[p]; } } @@ -391,17 +403,17 @@ int SummaryCommand::execute(){ for(int i=0;igetCols() == 1){ outputFileHandle << '\t' << sumCalculators[i]->getName(); - if (subsample) { outAve << '\t' << sumCalculators[i]->getName(); outSTD << '\t' << sumCalculators[i]->getName(); } + if (subsample) { outAve << '\t' << sumCalculators[i]->getName(); } numCols++; } else{ outputFileHandle << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; - if (subsample) { outAve << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; outSTD << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; } + if (subsample) { outAve << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; } numCols += 3; } } outputFileHandle << endl; - if (subsample) { outSTD << endl; outAve << endl; } + if (subsample) { outAve << endl; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -409,11 +421,11 @@ int SummaryCommand::execute(){ - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetLabel()) == 1){ @@ -421,9 +433,9 @@ int SummaryCommand::execute(){ processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); - process(sabund, outputFileHandle, outAve, outSTD); + process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetLabel()); userLabels.erase(sabund->getLabel()); - process(sabund, outputFileHandle, outAve, outSTD); + process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetSAbundVector(); } - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i::iterator it; @@ -473,15 +485,15 @@ int SummaryCommand::execute(){ sabund = input->getSAbundVector(lastLabel); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); - process(sabund, outputFileHandle, outAve, outSTD); + process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i data -> values @@ -559,7 +571,7 @@ int SummaryCommand::process(SAbundVector*& sabund, ofstream& outputFileHandle, o outputFileHandle << endl; if (subsample) { - outAve << sabund->getLabel() << '\t'; outStd << sabund->getLabel() << '\t'; + outAve << sabund->getLabel() << '\t' << "ave\t"; //find ave and std for this label and output //will need to modify the createGroupSummary to combine results and not mess with the .summary file. @@ -594,14 +606,15 @@ int SummaryCommand::process(SAbundVector*& sabund, ofstream& outputFileHandle, o } } + outAve << endl << sabund->getLabel() << '\t' << "std\t"; for (int i = 0; i < stdDev.size(); i++) { //finds average. for (int j = 0; j < stdDev[i].size(); j++) { stdDev[i][j] /= (float) iters; stdDev[i][j] = sqrt(stdDev[i][j]); - outStd << stdDev[i][j] << '\t'; + outAve << stdDev[i][j] << '\t'; } } - outAve << endl; outStd << endl; + outAve << endl; } return 0; @@ -702,38 +715,37 @@ vector SummaryCommand::createGroupSummaryFile(int numLines, int numCols, //open each groups summary file vector newComboNames; - string newLabel = ""; + map > > files; + map filesTypesLabels; + map filesTypesNumLines; for (int i=0; igetExtension(outputNames[i]); - string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "groups" + extension; - m->mothurRemove(combineFileName); //remove old file - vector thisFilesLines; ifstream temp; m->openInputFile(outputNames[i], temp); //read through first line - labels - string tempLabel; - if (i == 0) { //we want to save the labels to output below - for (int j = 0; j < numCols+1; j++) { - temp >> tempLabel; - - if (j == 1) { newLabel += "group\t" + tempLabel + '\t'; - }else{ newLabel += tempLabel + '\t'; } - } - }else{ for (int j = 0; j < numCols+1; j++) { temp >> tempLabel; } } + string labelsLine = m->getline(temp); + vector theseLabels = m->splitWhiteSpace(labelsLine); + + string newLabel = ""; + for (int j = 0; j < theseLabels.size(); j++) { + if (j == 1) { newLabel += "group\t" + theseLabels[j] + '\t'; + }else{ newLabel += theseLabels[j] + '\t'; } + } m->gobble(temp); + int stop = numLines; + if (theseLabels.size() != numCols+1) { stop = numLines*2; } //for each label - for (int k = 0; k < numLines; k++) { + for (int k = 0; k < stop; k++) { string thisLine = ""; string tempLabel; - for (int j = 0; j < numCols+1; j++) { + for (int j = 0; j < theseLabels.size(); j++) { temp >> tempLabel; //save for later @@ -748,6 +760,13 @@ vector SummaryCommand::createGroupSummaryFile(int numLines, int numCols, m->gobble(temp); } + string extension = m->getExtension(outputNames[i]); + if (theseLabels.size() != numCols+1) { extension = ".ave-std" + extension; } + string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "groups" + extension; + m->mothurRemove(combineFileName); //remove old file + filesTypesLabels[extension] = newLabel; + filesTypesNumLines[extension] = stop; + map > >::iterator itFiles = files.find(extension); if (itFiles != files.end()) { //add new files info to existing type files[extension][outputNames[i]] = thisFilesLines; @@ -775,10 +794,10 @@ vector SummaryCommand::createGroupSummaryFile(int numLines, int numCols, m->openOutputFile(combineFileName, out); //output label line to new file - out << newLabel << endl; + out << filesTypesLabels[extension] << endl; //for each label - for (int k = 0; k < numLines; k++) { + for (int k = 0; k < filesTypesNumLines[extension]; k++) { //grab summary data for each group for (map >::iterator itType = thisType.begin(); itType != thisType.end(); itType++) {