X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=nastreport.cpp;h=95901a36e8576a01cdc3b313ef8d0b11dc0bd402;hp=799793ece4dda8567d1dcb5a9865a70c9dd45f3e;hb=d1c97b8c04bb75faca1e76ffad60b37a4d789d3d;hpb=5b7ac70116137b52dd7884b76c5bca660a5fea38 diff --git a/nastreport.cpp b/nastreport.cpp index 799793e..95901a3 100644 --- a/nastreport.cpp +++ b/nastreport.cpp @@ -7,86 +7,206 @@ * */ -using namespace std; - #include "sequence.hpp" #include "nast.hpp" #include "alignment.hpp" #include "nastreport.hpp" + +/******************************************************************************************************************/ + +NastReport::NastReport() { + try { + m = MothurOut::getInstance(); + output = ""; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "NastReport"); + exit(1); + } +} +/******************************************************************************************************************/ +string NastReport::getHeaders() { + try { + output = ""; + + output += "QueryName\tQueryLength\tTemplateName\tTemplateLength\t"; + output += "SearchMethod\tSearchScore\t"; + output += "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t"; + output += "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t"; + output += "LongestInsert\t"; + output += "SimBtwnQuery&Template\n"; + + return output; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "getHeaders"); + exit(1); + } +} /******************************************************************************************************************/ NastReport::NastReport(string candidateReportFName) { - openOutputFile(candidateReportFName, candidateReportFile); - - candidateReportFile << "QueryName\tQueryLength\tTemplateName\tTemplateLength\t"; - candidateReportFile << "SearchMethod\tSearchScore\t"; - candidateReportFile << "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t"; - candidateReportFile << "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t"; - candidateReportFile << "LongestInsert\t"; - candidateReportFile << "SimBtwnQuery&Template" << endl; + try { + m = MothurOut::getInstance(); + m->openOutputFile(candidateReportFName, candidateReportFile); + + candidateReportFile << "QueryName\tQueryLength\tTemplateName\tTemplateLength\t"; + candidateReportFile << "SearchMethod\tSearchScore\t"; + candidateReportFile << "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t"; + candidateReportFile << "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t"; + candidateReportFile << "LongestInsert\t"; + candidateReportFile << "SimBtwnQuery&Template" << endl; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "NastReport"); + exit(1); + } +} + +/******************************************************************************************************************/ + +NastReport::~NastReport() { + try { + candidateReportFile.close(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "~NastReport"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::print(){ - - candidateReportFile << queryName << '\t' << queryLength << '\t' << templateName << '\t' << templateLength << '\t'; - candidateReportFile << searchMethod << '\t' << setprecision(2) << fixed << searchScore << '\t'; - - candidateReportFile << alignmentMethod << '\t' << candidateStartPosition << "\t" << candidateEndPosition << '\t'; - candidateReportFile << templateStartPosition << "\t" << templateEndPosition << '\t'; - candidateReportFile << pairwiseAlignmentLength << '\t' << totalGapsInQuery << '\t' << totalGapsInTemplate << '\t'; - candidateReportFile << longestInsert << '\t';; - candidateReportFile << setprecision(2) << similarityToTemplate; - - candidateReportFile << endl; - candidateReportFile.flush(); + try { + candidateReportFile << queryName << '\t' << queryLength << '\t' << templateName << '\t' << templateLength << '\t'; + candidateReportFile << searchMethod << '\t' << setprecision(2) << fixed << searchScore << '\t'; + + candidateReportFile << alignmentMethod << '\t' << candidateStartPosition << "\t" << candidateEndPosition << '\t'; + candidateReportFile << templateStartPosition << "\t" << templateEndPosition << '\t'; + candidateReportFile << pairwiseAlignmentLength << '\t' << totalGapsInQuery << '\t' << totalGapsInTemplate << '\t'; + candidateReportFile << longestInsert << '\t'; + candidateReportFile << setprecision(2) << similarityToTemplate; + + candidateReportFile << endl; + candidateReportFile.flush(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "print"); + exit(1); + } +} +/******************************************************************************************************************/ + +string NastReport::getReport(){ + try { + output = ""; + + output += queryName + '\t' + toString(queryLength) + '\t' + templateName + '\t' + toString(templateLength) + '\t'; + + string temp = toString(searchScore); + int pos = temp.find_last_of('.'); //find deicmal point if their is one + + //if there is a decimal + if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places + else{ temp += ".00"; } + + output += searchMethod + '\t' + temp + '\t'; + output += alignmentMethod + '\t' + toString(candidateStartPosition) + "\t" + toString(candidateEndPosition) + '\t'; + output += toString(templateStartPosition) + "\t" + toString(templateEndPosition) + '\t'; + output += toString(pairwiseAlignmentLength) + '\t' + toString(totalGapsInQuery) + '\t' + toString(totalGapsInTemplate) + '\t'; + output += toString(longestInsert) + '\t'; + + temp = toString(similarityToTemplate); + pos = temp.find_last_of('.'); //find deicmal point if their is one + + //if there is a decimal + if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places + else{ temp += ".00"; } + + output += temp + '\n'; + + return output; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "getReport"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setCandidate(Sequence* candSeq){ - queryName = candSeq->getName(); - queryLength = candSeq->getNumBases(); + try { + queryName = candSeq->getName(); + queryLength = candSeq->getNumBases(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setCandidate"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setTemplate(Sequence* tempSeq){ - templateName = tempSeq->getName(); - templateLength = tempSeq->getNumBases(); + try { + templateName = tempSeq->getName(); + templateLength = tempSeq->getNumBases(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setTemplate"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setSearchParameters(string method, float score){ - searchMethod = method; - searchScore = score; + try { + searchMethod = method; + searchScore = score; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setSearchParameters"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setAlignmentParameters(string method, Alignment* align){ - alignmentMethod = method; - - candidateStartPosition = align->getCandidateStartPos(); - candidateEndPosition = align->getCandidateEndPos(); - templateStartPosition = align->getTemplateStartPos(); - templateEndPosition = align->getTemplateEndPos(); - pairwiseAlignmentLength = align->getPairwiseLength(); - - totalGapsInQuery = pairwiseAlignmentLength - (candidateEndPosition - candidateStartPosition + 1); - totalGapsInTemplate = pairwiseAlignmentLength - (templateEndPosition - templateStartPosition + 1); + try { + alignmentMethod = method; + + candidateStartPosition = align->getCandidateStartPos(); + candidateEndPosition = align->getCandidateEndPos(); + templateStartPosition = align->getTemplateStartPos(); + templateEndPosition = align->getTemplateEndPos(); + pairwiseAlignmentLength = align->getPairwiseLength(); + + totalGapsInQuery = pairwiseAlignmentLength - (candidateEndPosition - candidateStartPosition + 1); + totalGapsInTemplate = pairwiseAlignmentLength - (templateEndPosition - templateStartPosition + 1); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setAlignmentParameters"); + exit(1); + } } /******************************************************************************************************************/ void NastReport::setNastParameters(Nast nast){ - - longestInsert = nast.getMaxInsertLength(); - similarityToTemplate = nast.getSimilarityScore(); - + try { + + longestInsert = nast.getMaxInsertLength(); + similarityToTemplate = nast.getSimilarityScore(); + } + catch(exception& e) { + m->errorOut(e, "NastReport", "setNastParameters"); + exit(1); + } } /******************************************************************************************************************/