5 * Created by Pat Schloss on 12/19/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
10 #include "sequence.hpp"
12 #include "alignment.hpp"
13 #include "nastreport.hpp"
16 /******************************************************************************************************************/
18 NastReport::NastReport() {
20 m = MothurOut::getInstance();
24 m->errorOut(e, "NastReport", "NastReport");
28 /******************************************************************************************************************/
29 string NastReport::getHeaders() {
33 output += "QueryName\tQueryLength\tTemplateName\tTemplateLength\t";
34 output += "SearchMethod\tSearchScore\t";
35 output += "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t";
36 output += "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t";
37 output += "LongestInsert\t";
38 output += "SimBtwnQuery&Template\n";
43 m->errorOut(e, "NastReport", "getHeaders");
47 /******************************************************************************************************************/
49 NastReport::NastReport(string candidateReportFName) {
51 m = MothurOut::getInstance();
52 m->openOutputFile(candidateReportFName, candidateReportFile);
54 candidateReportFile << "QueryName\tQueryLength\tTemplateName\tTemplateLength\t";
55 candidateReportFile << "SearchMethod\tSearchScore\t";
56 candidateReportFile << "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t";
57 candidateReportFile << "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t";
58 candidateReportFile << "LongestInsert\t";
59 candidateReportFile << "SimBtwnQuery&Template" << endl;
62 m->errorOut(e, "NastReport", "NastReport");
67 /******************************************************************************************************************/
69 NastReport::~NastReport() {
71 candidateReportFile.close();
74 m->errorOut(e, "NastReport", "~NastReport");
79 /******************************************************************************************************************/
81 void NastReport::print(){
83 candidateReportFile << queryName << '\t' << queryLength << '\t' << templateName << '\t' << templateLength << '\t';
84 candidateReportFile << searchMethod << '\t' << setprecision(2) << fixed << searchScore << '\t';
86 candidateReportFile << alignmentMethod << '\t' << candidateStartPosition << "\t" << candidateEndPosition << '\t';
87 candidateReportFile << templateStartPosition << "\t" << templateEndPosition << '\t';
88 candidateReportFile << pairwiseAlignmentLength << '\t' << totalGapsInQuery << '\t' << totalGapsInTemplate << '\t';
89 candidateReportFile << longestInsert << '\t';
90 candidateReportFile << setprecision(2) << similarityToTemplate;
92 candidateReportFile << endl;
93 candidateReportFile.flush();
96 m->errorOut(e, "NastReport", "print");
100 /******************************************************************************************************************/
102 string NastReport::getReport(){
106 output += queryName + '\t' + toString(queryLength) + '\t' + templateName + '\t' + toString(templateLength) + '\t';
108 string temp = toString(searchScore);
109 int pos = temp.find_last_of('.'); //find deicmal point if their is one
111 //if there is a decimal
112 if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places
113 else{ temp += ".00"; }
115 output += searchMethod + '\t' + temp + '\t';
116 output += alignmentMethod + '\t' + toString(candidateStartPosition) + "\t" + toString(candidateEndPosition) + '\t';
117 output += toString(templateStartPosition) + "\t" + toString(templateEndPosition) + '\t';
118 output += toString(pairwiseAlignmentLength) + '\t' + toString(totalGapsInQuery) + '\t' + toString(totalGapsInTemplate) + '\t';
119 output += toString(longestInsert) + '\t';
121 temp = toString(similarityToTemplate);
122 pos = temp.find_last_of('.'); //find deicmal point if their is one
124 //if there is a decimal
125 if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places
126 else{ temp += ".00"; }
128 output += temp + '\n';
132 catch(exception& e) {
133 m->errorOut(e, "NastReport", "getReport");
138 /******************************************************************************************************************/
140 void NastReport::setCandidate(Sequence* candSeq){
142 queryName = candSeq->getName();
143 queryLength = candSeq->getNumBases();
145 catch(exception& e) {
146 m->errorOut(e, "NastReport", "setCandidate");
151 /******************************************************************************************************************/
153 void NastReport::setTemplate(Sequence* tempSeq){
155 templateName = tempSeq->getName();
156 templateLength = tempSeq->getNumBases();
158 catch(exception& e) {
159 m->errorOut(e, "NastReport", "setTemplate");
164 /******************************************************************************************************************/
166 void NastReport::setSearchParameters(string method, float score){
168 searchMethod = method;
171 catch(exception& e) {
172 m->errorOut(e, "NastReport", "setSearchParameters");
177 /******************************************************************************************************************/
179 void NastReport::setAlignmentParameters(string method, Alignment* align){
181 alignmentMethod = method;
183 candidateStartPosition = align->getCandidateStartPos();
184 candidateEndPosition = align->getCandidateEndPos();
185 templateStartPosition = align->getTemplateStartPos();
186 templateEndPosition = align->getTemplateEndPos();
187 pairwiseAlignmentLength = align->getPairwiseLength();
189 totalGapsInQuery = pairwiseAlignmentLength - (candidateEndPosition - candidateStartPosition + 1);
190 totalGapsInTemplate = pairwiseAlignmentLength - (templateEndPosition - templateStartPosition + 1);
192 catch(exception& e) {
193 m->errorOut(e, "NastReport", "setAlignmentParameters");
198 /******************************************************************************************************************/
200 void NastReport::setNastParameters(Nast nast){
203 longestInsert = nast.getMaxInsertLength();
204 similarityToTemplate = nast.getSimilarityScore();
206 catch(exception& e) {
207 m->errorOut(e, "NastReport", "setNastParameters");
212 /******************************************************************************************************************/