]> git.donarmstrong.com Git - mothur.git/blob - nastreport.cpp
added MPI code, broke up chimera.seqs into 5 separated commands, added parse.sff...
[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         output = "";
20 }
21 /******************************************************************************************************************/
22 string NastReport::getHeaders() {
23         output = "";
24         
25         output += "QueryName\tQueryLength\tTemplateName\tTemplateLength\t";
26         output += "SearchMethod\tSearchScore\t";
27         output += "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t";
28         output += "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t";
29         output += "LongestInsert\t";
30         output += "SimBtwnQuery&Template\n";
31         
32         return output;
33 }
34 /******************************************************************************************************************/
35
36 NastReport::NastReport(string candidateReportFName) {
37         openOutputFile(candidateReportFName, candidateReportFile);
38         
39         candidateReportFile << "QueryName\tQueryLength\tTemplateName\tTemplateLength\t";
40         candidateReportFile << "SearchMethod\tSearchScore\t";
41         candidateReportFile << "AlignmentMethod\tQueryStart\tQueryEnd\tTemplateStart\tTemplateEnd\t";
42         candidateReportFile << "PairwiseAlignmentLength\tGapsInQuery\tGapsInTemplate\t";
43         candidateReportFile << "LongestInsert\t";
44         candidateReportFile << "SimBtwnQuery&Template" << endl;
45 }
46
47 /******************************************************************************************************************/
48
49 NastReport::~NastReport() {
50         candidateReportFile.close();
51 }
52
53 /******************************************************************************************************************/
54
55 void NastReport::print(){
56         
57         candidateReportFile << queryName << '\t' << queryLength << '\t' << templateName << '\t' << templateLength << '\t';
58         candidateReportFile << searchMethod << '\t' << setprecision(2) << fixed << searchScore << '\t';
59
60         candidateReportFile << alignmentMethod << '\t' << candidateStartPosition << "\t" << candidateEndPosition << '\t';
61         candidateReportFile << templateStartPosition << "\t" << templateEndPosition << '\t';
62         candidateReportFile << pairwiseAlignmentLength << '\t' << totalGapsInQuery << '\t' << totalGapsInTemplate << '\t';
63         candidateReportFile << longestInsert << '\t';
64         candidateReportFile << setprecision(2) << similarityToTemplate;
65         
66         candidateReportFile << endl;
67         candidateReportFile.flush();
68 }
69 /******************************************************************************************************************/
70
71 string NastReport::getReport(){
72         
73         output = "";
74         
75         output += queryName + '\t' + toString(queryLength) + '\t' + templateName + '\t' + toString(templateLength) + '\t';
76         
77         string temp = toString(searchScore);
78         int pos = temp.find_last_of('.');  //find deicmal point if their is one
79         
80         //if there is a decimal
81         if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places
82         else{   temp += ".00";  }
83         
84         output += searchMethod + '\t' + temp + '\t';
85         output += alignmentMethod + '\t' + toString(candidateStartPosition) + "\t" + toString(candidateEndPosition) + '\t';
86         output += toString(templateStartPosition) + "\t" + toString(templateEndPosition) + '\t';
87         output += toString(pairwiseAlignmentLength) + '\t' + toString(totalGapsInQuery) + '\t' + toString(totalGapsInTemplate) + '\t';
88         output += toString(longestInsert) + '\t';
89         
90         temp = toString(similarityToTemplate);
91         pos = temp.find_last_of('.');  //find deicmal point if their is one
92         
93         //if there is a decimal
94         if (pos != -1) { temp = temp.substr(0, pos+3); } //set precision to 2 places
95         else{   temp += ".00";  }
96         
97         output += temp + '\n';
98         
99         return output;
100 }
101
102 /******************************************************************************************************************/
103
104 void NastReport::setCandidate(Sequence* candSeq){ 
105         queryName = candSeq->getName();
106         queryLength = candSeq->getNumBases();
107 }
108
109 /******************************************************************************************************************/
110
111 void NastReport::setTemplate(Sequence* tempSeq){ 
112         templateName = tempSeq->getName();
113         templateLength = tempSeq->getNumBases();
114 }
115
116 /******************************************************************************************************************/
117
118 void NastReport::setSearchParameters(string method, float score){
119         searchMethod = method;
120         searchScore = score;
121 }
122
123 /******************************************************************************************************************/
124
125 void NastReport::setAlignmentParameters(string method, Alignment* align){
126         alignmentMethod = method;
127         
128         candidateStartPosition = align->getCandidateStartPos();
129         candidateEndPosition = align->getCandidateEndPos();
130         templateStartPosition = align->getTemplateStartPos();
131         templateEndPosition = align->getTemplateEndPos();
132         pairwiseAlignmentLength = align->getPairwiseLength();
133
134         totalGapsInQuery = pairwiseAlignmentLength - (candidateEndPosition - candidateStartPosition + 1);
135         totalGapsInTemplate = pairwiseAlignmentLength - (templateEndPosition - templateStartPosition + 1);
136 }
137
138 /******************************************************************************************************************/
139
140 void NastReport::setNastParameters(Nast nast){
141
142         longestInsert = nast.getMaxInsertLength();
143         similarityToTemplate = nast.getSimilarityScore();
144         
145 }
146
147 /******************************************************************************************************************/