]> git.donarmstrong.com Git - mothur.git/blob - nastreport.cpp
changing command name classify.shared to classifyrf.shared
[mothur.git] / nastreport.cpp
1 /*
2  *  nastreport.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 12/19/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "sequence.hpp"
11 #include "nast.hpp"
12 #include "alignment.hpp"
13 #include "nastreport.hpp"
14
15
16 /******************************************************************************************************************/
17
18 NastReport::NastReport() {
19         try {
20                 m = MothurOut::getInstance();
21                 output = "";
22         }
23         catch(exception& e) {
24                 m->errorOut(e, "NastReport", "NastReport");
25                 exit(1);
26         }
27 }
28 /******************************************************************************************************************/
29 string NastReport::getHeaders() {
30         try {
31                 output = "";
32                 
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";
39                 
40                 return output;
41         }
42         catch(exception& e) {
43                 m->errorOut(e, "NastReport", "getHeaders");
44                 exit(1);
45         }
46 }
47 /******************************************************************************************************************/
48
49 NastReport::NastReport(string candidateReportFName) {
50         try {
51                 m = MothurOut::getInstance();
52                 m->openOutputFile(candidateReportFName, candidateReportFile);
53                 
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;
60         }
61         catch(exception& e) {
62                 m->errorOut(e, "NastReport", "NastReport");
63                 exit(1);
64         }
65 }
66
67 /******************************************************************************************************************/
68
69 NastReport::~NastReport() {
70         try {
71                 candidateReportFile.close();
72         }
73         catch(exception& e) {
74                 m->errorOut(e, "NastReport", "~NastReport");
75                 exit(1);
76         }
77 }
78
79 /******************************************************************************************************************/
80
81 void NastReport::print(){
82         try {
83                 candidateReportFile << queryName << '\t' << queryLength << '\t' << templateName << '\t' << templateLength << '\t';
84                 candidateReportFile << searchMethod << '\t' << setprecision(2) << fixed << searchScore << '\t';
85
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;
91                 
92                 candidateReportFile << endl;
93                 candidateReportFile.flush();
94         }
95         catch(exception& e) {
96                 m->errorOut(e, "NastReport", "print");
97                 exit(1);
98         }
99 }
100 /******************************************************************************************************************/
101
102 string NastReport::getReport(){
103         try {
104                 output = "";
105                 
106                 output += queryName + '\t' + toString(queryLength) + '\t' + templateName + '\t' + toString(templateLength) + '\t';
107                 
108                 string temp = toString(searchScore);
109                 int pos = temp.find_last_of('.');  //find deicmal point if their is one
110                 
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";  }
114                 
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';
120                 
121                 temp = toString(similarityToTemplate);
122                 pos = temp.find_last_of('.');  //find deicmal point if their is one
123                 
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";  }
127                 
128                 output += temp + '\n';
129                 
130                 return output;
131         }
132         catch(exception& e) {
133                 m->errorOut(e, "NastReport", "getReport");
134                 exit(1);
135         }
136 }
137
138 /******************************************************************************************************************/
139
140 void NastReport::setCandidate(Sequence* candSeq){ 
141         try {
142                 queryName = candSeq->getName();
143                 queryLength = candSeq->getNumBases();
144         }
145         catch(exception& e) {
146                 m->errorOut(e, "NastReport", "setCandidate");
147                 exit(1);
148         }
149 }
150
151 /******************************************************************************************************************/
152
153 void NastReport::setTemplate(Sequence* tempSeq){ 
154         try {
155                 templateName = tempSeq->getName();
156                 templateLength = tempSeq->getNumBases();
157         }
158         catch(exception& e) {
159                 m->errorOut(e, "NastReport", "setTemplate");
160                 exit(1);
161         }
162 }
163
164 /******************************************************************************************************************/
165
166 void NastReport::setSearchParameters(string method, float score){
167         try {
168                 searchMethod = method;
169                 searchScore = score;
170         }
171         catch(exception& e) {
172                 m->errorOut(e, "NastReport", "setSearchParameters");
173                 exit(1);
174         }
175 }
176
177 /******************************************************************************************************************/
178
179 void NastReport::setAlignmentParameters(string method, Alignment* align){
180         try {
181                 alignmentMethod = method;
182                 
183                 candidateStartPosition = align->getCandidateStartPos();
184                 candidateEndPosition = align->getCandidateEndPos();
185                 templateStartPosition = align->getTemplateStartPos();
186                 templateEndPosition = align->getTemplateEndPos();
187                 pairwiseAlignmentLength = align->getPairwiseLength();
188
189                 totalGapsInQuery = pairwiseAlignmentLength - (candidateEndPosition - candidateStartPosition + 1);
190                 totalGapsInTemplate = pairwiseAlignmentLength - (templateEndPosition - templateStartPosition + 1);
191         }
192         catch(exception& e) {
193                 m->errorOut(e, "NastReport", "setAlignmentParameters");
194                 exit(1);
195         }
196 }
197
198 /******************************************************************************************************************/
199
200 void NastReport::setNastParameters(Nast nast){
201         try {
202
203                 longestInsert = nast.getMaxInsertLength();
204                 similarityToTemplate = nast.getSimilarityScore();
205         }
206         catch(exception& e) {
207                 m->errorOut(e, "NastReport", "setNastParameters");
208                 exit(1);
209         }
210 }
211
212 /******************************************************************************************************************/