]> git.donarmstrong.com Git - mothur.git/blob - trimseqscommand.cpp
added set.dir command and modified commands to redirect input and output, removed...
[mothur.git] / trimseqscommand.cpp
1 /*
2  *  trimseqscommand.cpp
3  *  Mothur
4  *
5  *  Created by Pat Schloss on 6/6/09.
6  *  Copyright 2009 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 #include "trimseqscommand.h"
11
12 //***************************************************************************************************************
13
14 TrimSeqsCommand::TrimSeqsCommand(string option){
15         try {
16                 
17                 abort = false;
18                 
19                 //allow user to run help
20                 if(option == "help") { help(); abort = true; }
21                 
22                 else {
23                         //valid paramters for this command
24                         string AlignArray[] =  {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile", 
25                                                                         "qthreshold", "qaverage", "allfiles", "qtrim", "outputdir","inputdir"};
26                         
27                         vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
28                         
29                         OptionParser parser(option);
30                         map<string,string> parameters = parser.getParameters();
31                         
32                         ValidParameters validParameter;
33                         map<string,string>::iterator it;
34                         
35                         //check to make sure all parameters are valid for command
36                         for (it = parameters.begin(); it != parameters.end(); it++) { 
37                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
38                         }
39                         
40                         //if the user changes the input directory command factory will send this info to us in the output parameter 
41                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
42                         if (inputDir == "not found"){   inputDir = "";          }
43                         else {
44                                 string path;
45                                 it = parameters.find("fasta");
46                                 //user has given a template file
47                                 if(it != parameters.end()){ 
48                                         path = hasPath(it->second);
49                                         //if the user has not given a path then, add inputdir. else leave path alone.
50                                         if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
51                                 }
52                                 
53                                 it = parameters.find("oligos");
54                                 //user has given a template file
55                                 if(it != parameters.end()){ 
56                                         path = hasPath(it->second);
57                                         //if the user has not given a path then, add inputdir. else leave path alone.
58                                         if (path == "") {       parameters["oligos"] = inputDir + it->second;           }
59                                 }
60                                 
61                                 it = parameters.find("qfile");
62                                 //user has given a template file
63                                 if(it != parameters.end()){ 
64                                         path = hasPath(it->second);
65                                         //if the user has not given a path then, add inputdir. else leave path alone.
66                                         if (path == "") {       parameters["qfile"] = inputDir + it->second;            }
67                                 }
68                         }
69
70                         
71                         //check for required parameters
72                         fastaFile = validParameter.validFile(parameters, "fasta", true);
73                         if (fastaFile == "not found") { mothurOut("fasta is a required parameter for the screen.seqs command."); mothurOutEndLine(); abort = true; }
74                         else if (fastaFile == "not open") { abort = true; }     
75                         
76                         //if the user changes the output directory command factory will send this info to us in the output parameter 
77                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
78                                 outputDir = ""; 
79                                 outputDir += hasPath(fastaFile); //if user entered a file with a path then preserve it  
80                         }
81                 
82                         //check for optional parameter and set defaults
83                         // ...at some point should added some additional type checking...
84                         string temp;
85                         temp = validParameter.validFile(parameters, "flip", false);
86                         if (temp == "not found"){       flip = 0;       }
87                         else if(isTrue(temp))   {       flip = 1;       }
88                 
89                         temp = validParameter.validFile(parameters, "oligos", true);
90                         if (temp == "not found"){       oligoFile = "";         }
91                         else if(temp == "not open"){    abort = true;   } 
92                         else                                    {       oligoFile = temp;               }
93                         
94                         temp = validParameter.validFile(parameters, "maxambig", false);         if (temp == "not found") { temp = "-1"; }
95                         convert(temp, maxAmbig);  
96
97                         temp = validParameter.validFile(parameters, "maxhomop", false);         if (temp == "not found") { temp = "0"; }
98                         convert(temp, maxHomoP);  
99
100                         temp = validParameter.validFile(parameters, "minlength", false);        if (temp == "not found") { temp = "0"; }
101                         convert(temp, minLength); 
102                         
103                         temp = validParameter.validFile(parameters, "maxlength", false);        if (temp == "not found") { temp = "0"; }
104                         convert(temp, maxLength);
105                         
106                         temp = validParameter.validFile(parameters, "qfile", true);     
107                         if (temp == "not found")        {       qFileName = "";         }
108                         else if(temp == "not open")     {       abort = 0;              }
109                         else                                            {       qFileName = temp;       }
110                         
111                         temp = validParameter.validFile(parameters, "qthreshold", false);       if (temp == "not found") { temp = "0"; }
112                         convert(temp, qThreshold);
113                         
114                         temp = validParameter.validFile(parameters, "qtrim", false);    if (temp == "not found") { temp = "F"; }
115                         qtrim = isTrue(temp);
116
117                         temp = validParameter.validFile(parameters, "qaverage", false);         if (temp == "not found") { temp = "0"; }
118                         convert(temp, qAverage);
119                         
120                         temp = validParameter.validFile(parameters, "allfiles", false);         if (temp == "not found") { temp = "F"; }
121                         allFiles = isTrue(temp);
122                         
123                         if(allFiles && oligoFile == ""){
124                                 mothurOut("You selected allfiles, but didn't enter an oligos file.  Ignoring the allfiles request."); mothurOutEndLine();
125                         }
126                         if((qAverage != 0 && qThreshold != 0) && qFileName == ""){
127                                 mothurOut("You didn't provide a quality file name, quality criteria will be ignored."); mothurOutEndLine();
128                                 qAverage=0;
129                                 qThreshold=0;
130                         }
131                         if(!flip && oligoFile=="" && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP && qFileName == ""){               
132                                 mothurOut("You didn't set any options... quiting command."); mothurOutEndLine();
133                                 abort = true;
134                         }
135                 }
136
137         }
138         catch(exception& e) {
139                 errorOut(e, "TrimSeqsCommand", "TrimSeqsCommand");
140                 exit(1);
141         }
142 }
143 //**********************************************************************************************************************
144
145 void TrimSeqsCommand::help(){
146         try {
147                 mothurOut("The trim.seqs command reads a fastaFile and creates .....\n");
148                 mothurOut("The trim.seqs command parameters are fasta, flip, oligos, maxambig, maxhomop, minlength, maxlength, qfile, qthreshold, qaverage, qtrim and allfiles.\n");
149                 mothurOut("The fasta parameter is required.\n");
150                 mothurOut("The flip parameter .... The default is 0.\n");
151                 mothurOut("The oligos parameter .... The default is "".\n");
152                 mothurOut("The maxambig parameter .... The default is -1.\n");
153                 mothurOut("The maxhomop parameter .... The default is 0.\n");
154                 mothurOut("The minlength parameter .... The default is 0.\n");
155                 mothurOut("The maxlength parameter .... The default is 0.\n");
156                 mothurOut("The qfile parameter .....\n");
157                 mothurOut("The qthreshold parameter .... The default is 0.\n");
158                 mothurOut("The qaverage parameter .... The default is 0.\n");
159                 mothurOut("The allfiles parameter .... The default is F.\n");
160                 mothurOut("The qtrim parameter .... The default is F.\n");
161                 mothurOut("The trim.seqs command should be in the following format: \n");
162                 mothurOut("trim.seqs(fasta=yourFastaFile, flip=yourFlip, oligos=yourOligos, maxambig=yourMaxambig,  \n");
163                 mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength)  \n");       
164                 mothurOut("Example trim.seqs(fasta=abrecovery.fasta, flip=..., oligos=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n");
165                 mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n");
166                 mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/Trim.seqs .\n\n");
167
168         }
169         catch(exception& e) {
170                 errorOut(e, "TrimSeqsCommand", "help");
171                 exit(1);
172         }
173 }
174
175
176 //***************************************************************************************************************
177
178 TrimSeqsCommand::~TrimSeqsCommand(){    /*      do nothing      */      }
179
180 //***************************************************************************************************************
181
182 int TrimSeqsCommand::execute(){
183         try{
184         
185                 if (abort == true) { return 0; }
186
187                 ifstream inFASTA;
188                 openInputFile(fastaFile, inFASTA);
189                 
190                 ofstream outFASTA;
191                 string trimSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "trim.fasta";
192                 openOutputFile(trimSeqFile, outFASTA);
193                 
194                 ofstream outGroups;
195                 vector<ofstream*> fastaFileNames;
196                 if(oligoFile != ""){
197                         string groupFile = outputDir + getRootName(getSimpleName(fastaFile)) + "groups"; 
198                         openOutputFile(groupFile, outGroups);
199                         getOligos(fastaFileNames);
200                 }
201                 
202                 ofstream scrapFASTA;
203                 string scrapSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "scrap.fasta";
204                 openOutputFile(scrapSeqFile, scrapFASTA);
205                 
206                 ifstream qFile;
207                 if(qFileName != "")     {       openInputFile(qFileName, qFile);        }
208                 
209                 bool success;
210                         
211                 while(!inFASTA.eof()){
212                         Sequence currSeq(inFASTA);
213                         string origSeq = currSeq.getUnaligned();
214                         if (origSeq != "") {
215                                 int group;
216                                 string trashCode = "";
217                                 
218                                 if(qFileName != ""){
219                                         if(qThreshold != 0)             {       success = stripQualThreshold(currSeq, qFile);   }
220                                         else if(qAverage != 0)  {       success = cullQualAverage(currSeq, qFile);              }
221                                         if ((!qtrim) && (origSeq.length() != currSeq.getUnaligned().length())) { 
222                                                 success = 0; //if you don't want to trim and the sequence does not meet quality requirements, move to scrap
223                                         }
224                                         if(!success)                    {       trashCode += 'q';                                                               }
225                                 }
226                                 
227                                 if(barcodes.size() != 0){
228                                         success = stripBarcode(currSeq, group);
229                                         if(!success){   trashCode += 'b';       }
230                                 }
231                                 
232                                 if(numFPrimers != 0){
233                                         success = stripForward(currSeq);
234                                         if(!success){   trashCode += 'f';       }
235                                 }
236                                 
237                                 if(numRPrimers != 0){
238                                         success = stripReverse(currSeq);
239                                         if(!success){   trashCode += 'r';       }
240                                 }
241                                 if(minLength > 0 || maxLength > 0){
242                                         success = cullLength(currSeq);
243                                         if(!success){   trashCode += 'l'; }
244                                 }
245                                 if(maxHomoP > 0){
246                                         success = cullHomoP(currSeq);
247                                         if(!success){   trashCode += 'h';       }
248                                 }
249                                 if(maxAmbig != -1){
250                                         success = cullAmbigs(currSeq);
251                                         if(!success){   trashCode += 'n';       }
252                                 }
253                                 
254                                 if(flip){       currSeq.reverseComplement();    }               // should go last                       
255                                 
256                                 if(trashCode.length() == 0){
257                                         currSeq.setAligned(currSeq.getUnaligned());  //this is because of a modification we made to the sequence class to fix a bug.  all seqs have an aligned version, which is the version that gets printed.
258                                         currSeq.printSequence(outFASTA);
259                                         if(barcodes.size() != 0){
260                                                 outGroups << currSeq.getName() << '\t' << groupVector[group] << endl;
261                                                 
262                                                 if(allFiles){
263                                                         currSeq.printSequence(*fastaFileNames[group]);                                  
264                                                 }
265                                         }
266                                 }
267                                 else{
268                                         currSeq.setName(currSeq.getName() + '|' + trashCode);
269                                         currSeq.setUnaligned(origSeq);
270                                         currSeq.printSequence(scrapFASTA);
271                                 }
272                         }
273                         gobble(inFASTA);
274                 }
275                 inFASTA.close();
276                 outFASTA.close();
277                 scrapFASTA.close();
278                 outGroups.close();
279                 if(qFileName != "")     {       qFile.close();  }
280                 
281                 for(int i=0;i<fastaFileNames.size();i++){
282                         fastaFileNames[i]->close();
283                         delete fastaFileNames[i];
284                 }               
285                 
286                 for(int i=0;i<fastaFileNames.size();i++){
287                         string seqName;
288                         openInputFile(getRootName(fastaFile) + groupVector[i] + ".fasta", inFASTA);
289                         ofstream outGroups;
290                         openOutputFile(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups", outGroups);
291                         
292                         while(!inFASTA.eof()){
293                                 if(inFASTA.get() == '>'){
294                                         inFASTA >> seqName;
295                                         outGroups << seqName << '\t' << groupVector[i] << endl;
296                                 }
297                                 while (!inFASTA.eof())  {       char c = inFASTA.get(); if (c == 10 || c == 13){        break;  }       }
298                         }
299                         outGroups.close();
300                         inFASTA.close();
301                 }
302                 
303                 
304                 return 0;               
305         }
306         catch(exception& e) {
307                 errorOut(e, "TrimSeqsCommand", "execute");
308                 exit(1);
309         }
310 }
311
312 //***************************************************************************************************************
313
314 void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec){
315         try {
316                 ifstream inOligos;
317                 openInputFile(oligoFile, inOligos);
318                 
319                 ofstream test;
320                 
321                 string type, oligo, group;
322                 int index=0;
323                 
324                 while(!inOligos.eof()){
325                         inOligos >> type;
326                         
327                         if(type[0] == '#'){
328                                 while (!inOligos.eof()) {       char c = inOligos.get(); if (c == 10 || c == 13){       break;  }       } // get rest of line if there's any crap there
329                         }
330                         else{
331                                 inOligos >> oligo;
332                                 
333                                 for(int i=0;i<oligo.length();i++){
334                                         oligo[i] = toupper(oligo[i]);
335                                         if(oligo[i] == 'U')     {       oligo[i] = 'T'; }
336                                 }
337                                 
338                                 if(type == "forward"){
339                                         forPrimer.push_back(oligo);
340                                 }
341                                 else if(type == "reverse"){
342                                         Sequence oligoRC("reverse", oligo);
343                                         oligoRC.reverseComplement();
344                                         revPrimer.push_back(oligoRC.getUnaligned());
345                                 }
346                                 else if(type == "barcode"){
347                                         inOligos >> group;
348                                         barcodes[oligo]=index++;
349                                         groupVector.push_back(group);
350                                         
351                                         if(allFiles){
352                                                 outFASTAVec.push_back(new ofstream((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta").c_str(), ios::ate));
353                                         }
354                                 }
355                         }
356                 }
357                 
358                 inOligos.close();
359                 
360                 numFPrimers = forPrimer.size();
361                 numRPrimers = revPrimer.size();
362                 
363         }
364         catch(exception& e) {
365                 errorOut(e, "TrimSeqsCommand", "getOligos");
366                 exit(1);
367         }
368
369 }
370
371 //***************************************************************************************************************
372
373 bool TrimSeqsCommand::stripBarcode(Sequence& seq, int& group){
374         try {
375                 string rawSequence = seq.getUnaligned();
376                 bool success = 0;       //guilty until proven innocent
377                 
378                 for(map<string,int>::iterator it=barcodes.begin();it!=barcodes.end();it++){
379                         string oligo = it->first;
380                         if(rawSequence.length() < oligo.length()){      //let's just assume that the barcodes are the same length
381                                 success = 0;
382                                 break;
383                         }
384                         
385                         if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
386                                 group = it->second;
387                                 seq.setUnaligned(rawSequence.substr(oligo.length()));
388                                 success = 1;
389                                 break;
390                         }
391                 }
392                 return success;
393                 
394         }
395         catch(exception& e) {
396                 errorOut(e, "TrimSeqsCommand", "stripBarcode");
397                 exit(1);
398         }
399
400 }
401
402 //***************************************************************************************************************
403
404 bool TrimSeqsCommand::stripForward(Sequence& seq){
405         try {
406                 string rawSequence = seq.getUnaligned();
407                 bool success = 0;       //guilty until proven innocent
408                 
409                 for(int i=0;i<numFPrimers;i++){
410                         string oligo = forPrimer[i];
411                         
412                         if(rawSequence.length() < oligo.length()){
413                                 success = 0;
414                                 break;
415                         }
416                         
417                         if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
418                                 seq.setUnaligned(rawSequence.substr(oligo.length()));
419                                 success = 1;
420                                 break;
421                         }
422                 }
423                 
424                 return success;
425                 
426         }
427         catch(exception& e) {
428                 errorOut(e, "TrimSeqsCommand", "stripForward");
429                 exit(1);
430         }
431 }
432
433 //***************************************************************************************************************
434
435 bool TrimSeqsCommand::stripReverse(Sequence& seq){
436         try {
437                 string rawSequence = seq.getUnaligned();
438                 bool success = 0;       //guilty until proven innocent
439                 
440                 for(int i=0;i<numRPrimers;i++){
441                         string oligo = revPrimer[i];
442                         
443                         if(rawSequence.length() < oligo.length()){
444                                 success = 0;
445                                 break;
446                         }
447                         
448                         if(compareDNASeq(oligo, rawSequence.substr(rawSequence.length()-oligo.length(),oligo.length()))){
449                                 seq.setUnaligned(rawSequence.substr(0,rawSequence.length()-oligo.length()));
450                                 success = 1;
451                                 break;
452                         }
453                 }       
454                 return success;
455                 
456         }
457         catch(exception& e) {
458                 errorOut(e, "TrimSeqsCommand", "stripReverse");
459                 exit(1);
460         }
461 }
462
463 //***************************************************************************************************************
464
465 bool TrimSeqsCommand::cullLength(Sequence& seq){
466         try {
467         
468                 int length = seq.getNumBases();
469                 bool success = 0;       //guilty until proven innocent
470                 
471                 if(length >= minLength && maxLength == 0)                       {       success = 1;    }
472                 else if(length >= minLength && length <= maxLength)     {       success = 1;    }
473                 else                                                                                            {       success = 0;    }
474                 
475                 return success;
476         
477         }
478         catch(exception& e) {
479                 errorOut(e, "TrimSeqsCommand", "cullLength");
480                 exit(1);
481         }
482         
483 }
484
485 //***************************************************************************************************************
486
487 bool TrimSeqsCommand::cullHomoP(Sequence& seq){
488         try {
489                 int longHomoP = seq.getLongHomoPolymer();
490                 bool success = 0;       //guilty until proven innocent
491                 
492                 if(longHomoP <= maxHomoP){      success = 1;    }
493                 else                                    {       success = 0;    }
494                 
495                 return success;
496         }
497         catch(exception& e) {
498                 errorOut(e, "TrimSeqsCommand", "cullHomoP");
499                 exit(1);
500         }
501         
502 }
503
504 //***************************************************************************************************************
505
506 bool TrimSeqsCommand::cullAmbigs(Sequence& seq){
507         try {
508                 int numNs = seq.getAmbigBases();
509                 bool success = 0;       //guilty until proven innocent
510                 
511                 if(numNs <= maxAmbig)   {       success = 1;    }
512                 else                                    {       success = 0;    }
513                 
514                 return success;
515         }
516         catch(exception& e) {
517                 errorOut(e, "TrimSeqsCommand", "cullAmbigs");
518                 exit(1);
519         }
520         
521 }
522
523 //***************************************************************************************************************
524
525 bool TrimSeqsCommand::compareDNASeq(string oligo, string seq){
526         try {
527                 bool success = 1;
528                 int length = oligo.length();
529                 
530                 for(int i=0;i<length;i++){
531                         
532                         if(oligo[i] != seq[i]){
533                                 if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C')    {       success = 0;    }
534                                 else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N'))                                {       success = 0;    }
535                                 else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G'))                                    {       success = 0;    }
536                                 else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T'))                                    {       success = 0;    }
537                                 else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A'))                                    {       success = 0;    }
538                                 else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G'))                                    {       success = 0;    }
539                                 else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A'))                                    {       success = 0;    }
540                                 else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G'))                                    {       success = 0;    }
541                                 else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G'))   {       success = 0;    }
542                                 else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G'))   {       success = 0;    }
543                                 else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C'))   {       success = 0;    }
544                                 else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G'))   {       success = 0;    }                       
545                                 
546                                 if(success == 0)        {       break;  }
547                         }
548                         else{
549                                 success = 1;
550                         }
551                 }
552                 
553                 return success;
554         }
555         catch(exception& e) {
556                 errorOut(e, "TrimSeqsCommand", "compareDNASeq");
557                 exit(1);
558         }
559
560 }
561
562 //***************************************************************************************************************
563
564 bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){
565         try {
566                 string rawSequence = seq.getUnaligned();
567                 int seqLength = rawSequence.length();
568                 string name;
569                 
570                 qFile >> name;
571                 if (name.length() != 0) {  if(name.substr(1) != seq.getName())  {       mothurOut("sequence name mismatch btwn fasta and qual file"); mothurOutEndLine();       }  } 
572                 while (!qFile.eof())    {       char c = qFile.get(); if (c == 10 || c == 13){  break;  }       }
573                 
574                 int score;
575                 int end = seqLength;
576                 
577                 for(int i=0;i<seqLength;i++){
578                         qFile >> score;
579                         
580                         if(score <= qThreshold){
581                                 end = i;
582                                 break;
583                         }
584                 }
585                 for(int i=end+1;i<seqLength;i++){
586                         qFile >> score;
587                 }
588                 
589                 seq.setUnaligned(rawSequence.substr(0,end));
590                 
591                 return 1;
592         }
593         catch(exception& e) {
594                 errorOut(e, "TrimSeqsCommand", "stripQualThreshold");
595                 exit(1);
596         }
597 }
598
599 //***************************************************************************************************************
600
601 bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
602         try {
603                 string rawSequence = seq.getUnaligned();
604                 int seqLength = seq.getNumBases();
605                 bool success = 0;       //guilty until proven innocent
606                 string name;
607                 
608                 qFile >> name;
609                 if (name[0] == '>') {  if(name.substr(1) != seq.getName())      {       mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); mothurOutEndLine();       } }
610                 
611                 while (!qFile.eof())    {       char c = qFile.get(); if (c == 10 || c == 13){  break;  }       }
612                 
613                 float score;    
614                 float average = 0;
615                 
616                 for(int i=0;i<seqLength;i++){
617                         qFile >> score;
618                         average += score;
619                 }
620                 average /= seqLength;
621
622                 if(average >= qAverage) {       success = 1;    }
623                 else                                    {       success = 0;    }
624                 
625                 return success;
626         }
627         catch(exception& e) {
628                 errorOut(e, "TrimSeqsCommand", "cullQualAverage");
629                 exit(1);
630         }
631 }
632
633 //***************************************************************************************************************