1 #ifndef SUMMARYQUALCOMMAND_H
2 #define SUMMARYQUALCOMMAND_H
8 * Created by westcott on 11/28/11.
9 * Copyright 2011 Schloss Lab. All rights reserved.
14 #include "command.hpp"
15 #include "qualityscores.h"
17 /**************************************************************************************************/
19 class SummaryQualCommand : public Command {
21 SummaryQualCommand(string);
23 ~SummaryQualCommand(){}
25 vector<string> setParameters();
26 string getCommandName() { return "summary.qual"; }
27 string getCommandCategory() { return "Sequence Processing"; }
28 string getHelpString();
29 string getCitation() { return "http://www.mothur.org/wiki/Summary.qual"; }
30 string getDescription() { return "summarize the quality of a set of sequences"; }
33 void help() { m->mothurOut(getHelpString()); }
37 string qualfile, outputDir, namefile;
38 vector<string> outputNames;
39 map<string, int> nameMap;
43 unsigned long long start;
44 unsigned long long end;
45 linePair(unsigned long long i, unsigned long long j) : start(i), end(j) {}
48 vector<linePair> lines;
49 vector<int> processIDS;
51 int createProcessesCreateSummary(vector<int>&, vector<int>&, vector< vector<int> >&, string);
52 int driverCreateSummary(vector<int>&, vector<int>&, vector< vector<int> >&, string, linePair);
53 int printQual(string, vector<int>&, vector<int>&, vector< vector<int> >&);
56 /**************************************************************************************************/
57 //custom data structure for threads to use.
58 // This is passed by void pointer so it can be any data type
59 // that can be passed using a single void pointer (LPVOID).
60 struct seqSumQualData {
61 vector<int>* position;
62 vector<int>* averageQ;
63 vector< vector<int> >* scores;
64 string filename, namefile;
65 unsigned long long start;
66 unsigned long long end;
69 map<string, int> nameMap;
72 seqSumQualData(vector<int>* p, vector<int>* a, vector< vector<int> >* s, string f, MothurOut* mout, unsigned long long st, unsigned long long en, string n, map<string, int> nam) {
86 /**************************************************************************************************/
87 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
89 static DWORD WINAPI MySeqSumQualThreadFunction(LPVOID lpParam){
90 seqSumQualData* pDataArray;
91 pDataArray = (seqSumQualData*)lpParam;
95 pDataArray->m->openInputFile(pDataArray->filename, in);
97 //print header if you are process 0
98 if ((pDataArray->start == 0) || (pDataArray->start == 1)) {
100 }else { //this accounts for the difference in line endings.
101 in.seekg(pDataArray->start-1); pDataArray->m->gobble(in);
105 for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process
107 if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; }
109 QualityScores current(in); pDataArray->m->gobble(in);
111 if (current.getName() != "") {
114 if (pDataArray->namefile != "") {
115 //make sure this sequence is in the namefile, else error
116 map<string, int>::iterator it = pDataArray->nameMap.find(current.getName());
118 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; }
119 else { num = it->second; }
122 vector<int> thisScores = current.getQualityScores();
124 //resize to num of positions setting number of seqs with that size to 1
125 if (pDataArray->position->size() < thisScores.size()) { pDataArray->position->resize(thisScores.size(), 0); }
126 if (pDataArray->averageQ->size() < thisScores.size()) { pDataArray->averageQ->resize(thisScores.size(), 0); }
127 if (pDataArray->scores->size() < thisScores.size()) {
128 pDataArray->scores->resize(thisScores.size());
129 for (int i = 0; i < pDataArray->scores->size(); i++) { pDataArray->scores->at(i).resize(41, 0); }
132 //increase counts of number of seqs with this position
133 //average is really the total, we will average in execute
134 for (int i = 0; i < thisScores.size(); i++) {
135 pDataArray->position->at(i) += num;
136 pDataArray->averageQ->at(i) += (thisScores[i] * num); //weighting for namesfile
137 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; }
138 else { pDataArray->scores->at(i)[thisScores[i]] += num; }
145 pDataArray->count = count;
151 catch(exception& e) {
152 pDataArray->m->errorOut(e, "SummaryQualCommand", "MySeqSumQualThreadFunction");
159 /**************************************************************************************************/