]> git.donarmstrong.com Git - mothur.git/blob - summaryqualcommand.h
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / summaryqualcommand.h
1 #ifndef SUMMARYQUALCOMMAND_H
2 #define SUMMARYQUALCOMMAND_H
3
4 /*
5  *  summaryqualcommand.h
6  *  Mothur
7  *
8  *  Created by westcott on 11/28/11.
9  *  Copyright 2011 Schloss Lab. All rights reserved.
10  *
11  */
12
13
14 #include "command.hpp"
15 #include "qualityscores.h"
16
17 /**************************************************************************************************/
18
19 class SummaryQualCommand : public Command {
20 public:
21         SummaryQualCommand(string);
22         SummaryQualCommand();
23         ~SummaryQualCommand(){}
24         
25         vector<string> setParameters();
26         string getCommandName()                 { return "summary.qual";                        }
27         string getCommandCategory()             { return "Sequence Processing";         }
28         string getOutputFileNameTag(string, string);
29         string getHelpString(); 
30         string getCitation() { return "http://www.mothur.org/wiki/Summary.qual"; }
31         string getDescription()         { return "summarize the quality of a set of sequences"; }
32         
33         int execute(); 
34         void help() { m->mothurOut(getHelpString()); }  
35         
36 private:
37         bool abort;
38         string qualfile, outputDir, namefile;
39         vector<string> outputNames;
40         map<string, int> nameMap;
41         int processors;
42         
43         struct linePair {
44                 unsigned long long start;
45                 unsigned long long end;
46                 linePair(unsigned long long i, unsigned long long j) : start(i), end(j) {}
47         };
48         
49         vector<linePair> lines;
50         vector<int> processIDS;
51         
52         int createProcessesCreateSummary(vector<int>&, vector<int>&, vector< vector<int> >&, string);
53         int driverCreateSummary(vector<int>&, vector<int>&, vector< vector<int> >&, string, linePair);  
54         int printQual(string, vector<int>&, vector<int>&, vector< vector<int> >&);
55 };
56
57 /**************************************************************************************************/
58 //custom data structure for threads to use.
59 // This is passed by void pointer so it can be any data type
60 // that can be passed using a single void pointer (LPVOID).
61 struct seqSumQualData {
62         vector<int> position;
63         vector<int> averageQ;
64         vector< vector<int> > scores; 
65         string filename, namefile; 
66         unsigned long long start;
67         unsigned long long end;
68         int count;
69         MothurOut* m;
70         map<string, int> nameMap;
71         
72         ~seqSumQualData(){}
73         seqSumQualData(string f, MothurOut* mout, unsigned long long st, unsigned long long en, string n, map<string, int> nam) {
74                 filename = f;
75                 m = mout;
76                 start = st;
77                 end = en;
78                 namefile = n;
79                 nameMap = nam;
80                 count = 0;
81         }
82 };
83
84 /**************************************************************************************************/
85 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
86 #else
87 static DWORD WINAPI MySeqSumQualThreadFunction(LPVOID lpParam){ 
88         seqSumQualData* pDataArray;
89         pDataArray = (seqSumQualData*)lpParam;
90         
91         try {
92                 ifstream in;
93                 pDataArray->m->openInputFile(pDataArray->filename, in);
94                 
95                 //print header if you are process 0
96                 if ((pDataArray->start == 0) || (pDataArray->start == 1)) {
97                         in.seekg(0);
98                 }else { //this accounts for the difference in line endings. 
99                         in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); 
100                 }
101                 
102                 int count = 0;
103                 for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process
104                                 
105                         if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; }
106                         
107                         QualityScores current(in); pDataArray->m->gobble(in);
108                         
109                         if (current.getName() != "") {
110                         
111                                 int num = 1;
112                                 if (pDataArray->namefile != "") {
113                                         //make sure this sequence is in the namefile, else error 
114                                         map<string, int>::iterator it = pDataArray->nameMap.find(current.getName());
115                                         
116                                         if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " is not in your namefile, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; }
117                                         else { num = it->second; }
118                                 }
119                                 
120                                 vector<int> thisScores = current.getQualityScores();
121                                 
122                                 //resize to num of positions setting number of seqs with that size to 1
123                                 if (pDataArray->position.size() < thisScores.size()) { pDataArray->position.resize(thisScores.size(), 0); }
124                                 if (pDataArray->averageQ.size() < thisScores.size()) { pDataArray->averageQ.resize(thisScores.size(), 0); }
125                                 if (pDataArray->scores.size() < thisScores.size()) { 
126                                         pDataArray->scores.resize(thisScores.size()); 
127                                         for (int i = 0; i < pDataArray->scores.size(); i++) { pDataArray->scores.at(i).resize(41, 0); }
128                                 }
129                                 
130                                 //increase counts of number of seqs with this position
131                                 //average is really the total, we will average in execute
132                                 for (int i = 0; i < thisScores.size(); i++) { 
133                                         pDataArray->position.at(i) += num; 
134                                         pDataArray->averageQ.at(i) += (thisScores[i] * num); //weighting for namesfile
135                                         if (thisScores[i] > 40) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " has a quality scores of " + toString(thisScores[i]) + ", expecting values to be less than 40."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; }
136                                         else { pDataArray->scores.at(i)[thisScores[i]] += num; }  
137                                 }
138                                 
139                                 count += num;
140                         }
141                 }
142                 
143                 pDataArray->count = count;
144                 in.close();
145                 
146                 return 0;
147                 
148         }
149         catch(exception& e) {
150                 pDataArray->m->errorOut(e, "SummaryQualCommand", "MySeqSumQualThreadFunction");
151                 exit(1);
152         }
153
154 #endif
155
156
157 /**************************************************************************************************/
158
159
160 #endif
161