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 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"; }
34 void help() { m->mothurOut(getHelpString()); }
38 string qualfile, outputDir, namefile, countfile;
39 vector<string> outputNames;
40 map<string, int> nameMap;
44 unsigned long long start;
45 unsigned long long end;
46 linePair(unsigned long long i, unsigned long long j) : start(i), end(j) {}
49 vector<linePair> lines;
50 vector<int> processIDS;
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> >&);
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 {
64 vector< vector<int> > scores;
66 unsigned long long start;
67 unsigned long long end;
71 map<string, int> nameMap;
74 seqSumQualData(string f, MothurOut* mout, unsigned long long st, unsigned long long en, bool n, map<string, int> nam) {
85 /**************************************************************************************************/
86 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
88 static DWORD WINAPI MySeqSumQualThreadFunction(LPVOID lpParam){
89 seqSumQualData* pDataArray;
90 pDataArray = (seqSumQualData*)lpParam;
94 pDataArray->m->openInputFile(pDataArray->filename, in);
96 //print header if you are process 0
97 if ((pDataArray->start == 0) || (pDataArray->start == 1)) {
99 }else { //this accounts for the difference in line endings.
100 in.seekg(pDataArray->start-1); pDataArray->m->gobble(in);
104 for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process
106 if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; }
108 QualityScores current(in); pDataArray->m->gobble(in);
110 if (current.getName() != "") {
113 if (pDataArray->hasNameMap) {
114 //make sure this sequence is in the namefile, else error
115 map<string, int>::iterator it = pDataArray->nameMap.find(current.getName());
117 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; }
118 else { num = it->second; }
121 vector<int> thisScores = current.getQualityScores();
123 //resize to num of positions setting number of seqs with that size to 1
124 if (pDataArray->position.size() < thisScores.size()) { pDataArray->position.resize(thisScores.size(), 0); }
125 if (pDataArray->averageQ.size() < thisScores.size()) { pDataArray->averageQ.resize(thisScores.size(), 0); }
126 if (pDataArray->scores.size() < thisScores.size()) {
127 pDataArray->scores.resize(thisScores.size());
128 for (int i = 0; i < pDataArray->scores.size(); i++) { pDataArray->scores.at(i).resize(41, 0); }
131 //increase counts of number of seqs with this position
132 //average is really the total, we will average in execute
133 for (int i = 0; i < thisScores.size(); i++) {
134 pDataArray->position.at(i) += num;
135 pDataArray->averageQ.at(i) += (thisScores[i] * num); //weighting for namesfile
136 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; }
137 else { pDataArray->scores.at(i)[thisScores[i]] += num; }
144 pDataArray->count = count;
150 catch(exception& e) {
151 pDataArray->m->errorOut(e, "SummaryQualCommand", "MySeqSumQualThreadFunction");
158 /**************************************************************************************************/