]> git.donarmstrong.com Git - mothur.git/blobdiff - nastreport.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / nastreport.cpp
index d7be4dd57c272b69dc0aa09fd35b7d4c2f9d4f0b..95901a36e8576a01cdc3b313ef8d0b11dc0bd402 100644 (file)
 #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() {
-       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(){
+       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);
+       }
 }
 
 /******************************************************************************************************************/