1 #ifndef SCREENSEQSCOMMAND_H
2 #define SCREENSEQSCOMMAND_H
8 * Created by Pat Schloss on 6/3/09.
9 * Copyright 2009 Patrick D. Schloss. All rights reserved.
13 #include "command.hpp"
14 #include "sequence.hpp"
16 class ScreenSeqsCommand : public Command {
19 ScreenSeqsCommand(string);
21 ~ScreenSeqsCommand() {}
23 vector<string> setParameters();
24 string getCommandName() { return "screen.seqs"; }
25 string getCommandCategory() { return "Sequence Processing"; }
27 string getHelpString();
28 string getOutputPattern(string);
29 string getCitation() { return "http://www.mothur.org/wiki/Screen.seqs"; }
30 string getDescription() { return "enables you to keep sequences that fulfill certain user defined criteria"; }
33 void help() { m->mothurOut(getHelpString()); }
39 unsigned long long start;
40 unsigned long long end;
41 linePair(unsigned long long i, unsigned long long j) : start(i), end(j) {}
44 vector<linePair> lines;
46 int screenNameGroupFile(set<string>);
47 int screenGroupFile(set<string>);
48 int screenCountFile(set<string>);
49 int screenAlignReport(set<string>);
50 int screenQual(set<string>);
51 int screenTaxonomy(set<string>);
53 int driver(linePair, string, string, string, set<string>&);
54 int createProcesses(string, string, string, set<string>&);
57 int driverMPI(int, int, MPI_File&, MPI_File&, MPI_File&, vector<unsigned long long>&, set<string>&);
61 string fastafile, namefile, groupfile, alignreport, outputDir, qualfile, taxonomy, countfile;
62 int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength, processors, criteria;
63 vector<string> outputNames;
64 vector<string> optimize;
65 map<string, int> nameMap;
67 int getSummary(vector<unsigned long long>&);
68 int createProcessesCreateSummary(vector<int>&, vector<int>&, vector<int>&, vector<int>&, vector<int>&, string);
69 int driverCreateSummary(vector<int>&, vector<int>&, vector<int>&, vector<int>&, vector<int>&, string, linePair);
72 /**************************************************************************************************/
73 //custom data structure for threads to use.
74 // This is passed by void pointer so it can be any data type
75 // that can be passed using a single void pointer (LPVOID).
77 vector<int> startPosition;
78 vector<int> endPosition;
79 vector<int> seqLength;
80 vector<int> ambigBases;
81 vector<int> longHomoPolymer;
82 string filename, namefile;
83 unsigned long long start;
84 unsigned long long end;
87 map<string, int> nameMap;
91 sumData(string f, MothurOut* mout, unsigned long long st, unsigned long long en, string nf, map<string, int> nam) {
101 /**************************************************************************************************/
102 //custom data structure for threads to use.
103 // This is passed by void pointer so it can be any data type
104 // that can be passed using a single void pointer (LPVOID).
105 struct sumScreenData {
106 int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength;
107 unsigned long long start;
108 unsigned long long end;
111 string goodFName, badAccnosFName, filename;
112 set<string> badSeqNames;
116 sumScreenData(int s, int e, int a, int h, int minl, int maxl, string f, MothurOut* mout, unsigned long long st, unsigned long long en, string gf, string bf) {
134 /**************************************************************************************************/
135 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
137 static DWORD WINAPI MySumThreadFunction(LPVOID lpParam){
139 pDataArray = (sumData*)lpParam;
143 pDataArray->m->openInputFile(pDataArray->filename, in);
145 //print header if you are process 0
146 if ((pDataArray->start == 0) || (pDataArray->start == 1)) {
148 }else { //this accounts for the difference in line endings.
149 in.seekg(pDataArray->start-1); pDataArray->m->gobble(in);
153 for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process
157 if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; }
159 Sequence current(in); pDataArray->m->gobble(in);
161 if (current.getName() != "") {
164 if (pDataArray->namefile != "") {
165 //make sure this sequence is in the namefile, else error
166 map<string, int>::iterator it = pDataArray->nameMap.find(current.getName());
168 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; }
169 else { num = it->second; }
172 //for each sequence this sequence represents
173 for (int i = 0; i < num; i++) {
174 pDataArray->startPosition.push_back(current.getStartPos());
175 pDataArray->endPosition.push_back(current.getEndPos());
176 pDataArray->seqLength.push_back(current.getNumBases());
177 pDataArray->ambigBases.push_back(current.getAmbigBases());
178 pDataArray->longHomoPolymer.push_back(current.getLongHomoPolymer());
188 catch(exception& e) {
189 pDataArray->m->errorOut(e, "ScreenSeqsCommand", "MySumThreadFunction");
194 /**************************************************************************************************/
196 static DWORD WINAPI MySumScreenThreadFunction(LPVOID lpParam){
197 sumScreenData* pDataArray;
198 pDataArray = (sumScreenData*)lpParam;
203 pDataArray->m->openOutputFile(pDataArray->goodFName, goodFile);
205 ofstream badAccnosFile;
206 pDataArray->m->openOutputFile(pDataArray->badAccnosFName, badAccnosFile);
209 pDataArray->m->openInputFile(pDataArray->filename, in);
211 //print header if you are process 0
212 if ((pDataArray->start == 0) || (pDataArray->start == 1)) {
214 }else { //this accounts for the difference in line endings.
215 in.seekg(pDataArray->start-1); pDataArray->m->gobble(in);
218 for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process
222 if (pDataArray->m->control_pressed) { in.close(); badAccnosFile.close(); goodFile.close(); pDataArray->count = 1; return 1; }
224 Sequence currSeq(in); pDataArray->m->gobble(in);
226 if (currSeq.getName() != "") {
227 bool goodSeq = 1; // innocent until proven guilty
228 if(goodSeq == 1 && pDataArray->startPos != -1 && pDataArray->startPos < currSeq.getStartPos()) { goodSeq = 0; }
229 if(goodSeq == 1 && pDataArray->endPos != -1 && pDataArray->endPos > currSeq.getEndPos()) { goodSeq = 0; }
230 if(goodSeq == 1 && pDataArray->maxAmbig != -1 && pDataArray->maxAmbig < currSeq.getAmbigBases()) { goodSeq = 0; }
231 if(goodSeq == 1 && pDataArray->maxHomoP != -1 && pDataArray->maxHomoP < currSeq.getLongHomoPolymer()) { goodSeq = 0; }
232 if(goodSeq == 1 && pDataArray->minLength != -1 && pDataArray->minLength > currSeq.getNumBases()) { goodSeq = 0; }
233 if(goodSeq == 1 && pDataArray->maxLength != -1 && pDataArray->maxLength < currSeq.getNumBases()) { goodSeq = 0; }
236 currSeq.printSequence(goodFile);
239 badAccnosFile << currSeq.getName() << endl;
240 pDataArray->badSeqNames.insert(currSeq.getName());
245 if((i+1) % 100 == 0){ pDataArray->m->mothurOut("Processing sequence: " + toString(i+1)); pDataArray->m->mothurOutEndLine(); }
248 if((pDataArray->count) % 100 != 0){ pDataArray->m->mothurOut("Processing sequence: " + toString(pDataArray->count)); pDataArray->m->mothurOutEndLine(); }
254 badAccnosFile.close();
259 catch(exception& e) {
260 pDataArray->m->errorOut(e, "ScreenSeqsCommand", "MySumScreenThreadFunction");
267 /**************************************************************************************************/