File: nastreport.cpp

package info (click to toggle)
mothur 1.24.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,868 kB
  • sloc: cpp: 110,948; ansic: 2,037; fortran: 665; makefile: 74; sh: 59
file content (212 lines) | stat: -rw-r--r-- 6,823 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 *  nastreport.cpp
 *  
 *
 *  Created by Pat Schloss on 12/19/08.
 *  Copyright 2008 Patrick D. Schloss. All rights reserved.
 *
 */

#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) {
	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(){
	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){ 
	try {
		queryName = candSeq->getName();
		queryLength = candSeq->getNumBases();
	}
	catch(exception& e) {
		m->errorOut(e, "NastReport", "setCandidate");
		exit(1);
	}
}

/******************************************************************************************************************/

void NastReport::setTemplate(Sequence* tempSeq){ 
	try {
		templateName = tempSeq->getName();
		templateLength = tempSeq->getNumBases();
	}
	catch(exception& e) {
		m->errorOut(e, "NastReport", "setTemplate");
		exit(1);
	}
}

/******************************************************************************************************************/

void NastReport::setSearchParameters(string method, float score){
	try {
		searchMethod = method;
		searchScore = score;
	}
	catch(exception& e) {
		m->errorOut(e, "NastReport", "setSearchParameters");
		exit(1);
	}
}

/******************************************************************************************************************/

void NastReport::setAlignmentParameters(string method, Alignment* align){
	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){
	try {

		longestInsert = nast.getMaxInsertLength();
		similarityToTemplate = nast.getSimilarityScore();
	}
	catch(exception& e) {
		m->errorOut(e, "NastReport", "setNastParameters");
		exit(1);
	}
}

/******************************************************************************************************************/