X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=nastreport.cpp;h=95901a36e8576a01cdc3b313ef8d0b11dc0bd402;hp=132886bd55be4e9a57aa52816cfc49bcfb98eb42;hb=615301e57c25e241356a9c2380648d117709458d;hpb=fdc1f6eaf544f695fc1511f24bddd7e6069c33ba diff --git a/nastreport.cpp b/nastreport.cpp index 132886b..95901a3 100644 --- a/nastreport.cpp +++ b/nastreport.cpp @@ -16,132 +16,197 @@ /******************************************************************************************************************/ NastReport::NastReport() { - output = ""; + try { + m = MothurOut::getInstance(); + output = ""; + } + catch(exception& e) { + m->errorOut(e, "NastReport", "NastReport"); + exit(1); + } } /******************************************************************************************************************/ string NastReport::getHeaders() { - 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; + 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() { - candidateReportFile.close(); + 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(){ - - 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; + 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); + } } /******************************************************************************************************************/