]> git.donarmstrong.com Git - mothur.git/blob - trimseqscommand.cpp
70b1b4ae8a0c931ff3f84a56d4dd68fa1edd537a
[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 = true;           }
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                 numFPrimers = 0;  //this needs to be initialized
188                 numRPrimers = 0;
189                 
190                 ifstream inFASTA;
191                 openInputFile(fastaFile, inFASTA);
192                 
193                 ofstream outFASTA;
194                 string trimSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "trim.fasta";
195                 openOutputFile(trimSeqFile, outFASTA);
196                 
197                 ofstream outGroups;
198                 vector<ofstream*> fastaFileNames;
199                 if(oligoFile != ""){
200                         string groupFile = outputDir + getRootName(getSimpleName(fastaFile)) + "groups"; 
201                         openOutputFile(groupFile, outGroups);
202                         getOligos(fastaFileNames);
203                 }
204                 
205                 ofstream scrapFASTA;
206                 string scrapSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "scrap.fasta";
207                 openOutputFile(scrapSeqFile, scrapFASTA);
208                 
209                 ifstream qFile;
210                 if(qFileName != "")     {       openInputFile(qFileName, qFile);        }
211                 
212                 bool success;
213
214                 while(!inFASTA.eof()){
215                         Sequence currSeq(inFASTA);
216
217                         string origSeq = currSeq.getUnaligned();
218                         if (origSeq != "") {
219                                 int group;
220                                 string trashCode = "";
221                                 
222                                 if(qFileName != ""){
223                                         if(qThreshold != 0)             {       success = stripQualThreshold(currSeq, qFile);   }
224                                         else if(qAverage != 0)  {       success = cullQualAverage(currSeq, qFile);              }
225                                         if ((!qtrim) && (origSeq.length() != currSeq.getUnaligned().length())) { 
226                                                 success = 0; //if you don't want to trim and the sequence does not meet quality requirements, move to scrap
227                                         }
228                                         if(!success)                    {       trashCode += 'q';                                                               }
229                                 }
230                         
231                                 if(barcodes.size() != 0){
232                                         success = stripBarcode(currSeq, group);
233                                         if(!success){   trashCode += 'b';       }
234                                 }
235                         
236                                 if(numFPrimers != 0){
237                                         success = stripForward(currSeq);
238                                         if(!success){   trashCode += 'f';       }
239                                 }
240                                         
241                                 if(numRPrimers != 0){
242                                         success = stripReverse(currSeq);
243                                         if(!success){   trashCode += 'r';       }
244                                 }
245                 
246                                 if(minLength > 0 || maxLength > 0){
247                                         success = cullLength(currSeq);
248                                         if(!success){   trashCode += 'l'; }
249                                 }
250                                 if(maxHomoP > 0){
251                                         success = cullHomoP(currSeq);
252                                         if(!success){   trashCode += 'h';       }
253                                 }
254                                 if(maxAmbig != -1){
255                                         success = cullAmbigs(currSeq);
256                                         if(!success){   trashCode += 'n';       }
257                                 }
258                                 
259                                 if(flip){       currSeq.reverseComplement();    }               // should go last                       
260                                 
261                                 if(trashCode.length() == 0){
262                                         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.
263                                         currSeq.printSequence(outFASTA);
264                                         if(barcodes.size() != 0){
265                                                 outGroups << currSeq.getName() << '\t' << groupVector[group] << endl;
266                                                 
267                                                 if(allFiles){
268                                                         currSeq.printSequence(*fastaFileNames[group]);                                  
269                                                 }
270                                         }
271                                 }
272                                 else{
273                                         currSeq.setName(currSeq.getName() + '|' + trashCode);
274                                         currSeq.setUnaligned(origSeq);
275                                         currSeq.printSequence(scrapFASTA);
276                                 }
277                         }
278                         gobble(inFASTA);
279                 }
280                 inFASTA.close();
281                 outFASTA.close();
282                 scrapFASTA.close();
283                 outGroups.close();
284                 if(qFileName != "")     {       qFile.close();  }
285                 
286                 for(int i=0;i<fastaFileNames.size();i++){
287                         fastaFileNames[i]->close();
288                         delete fastaFileNames[i];
289                 }               
290                 
291                 for(int i=0;i<fastaFileNames.size();i++){
292                         string seqName;
293                         openInputFile(getRootName(fastaFile) + groupVector[i] + ".fasta", inFASTA);
294                         ofstream outGroups;
295                         openOutputFile(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups", outGroups);
296                         
297                         while(!inFASTA.eof()){
298                                 if(inFASTA.get() == '>'){
299                                         inFASTA >> seqName;
300                                         outGroups << seqName << '\t' << groupVector[i] << endl;
301                                 }
302                                 while (!inFASTA.eof())  {       char c = inFASTA.get(); if (c == 10 || c == 13){        break;  }       }
303                         }
304                         outGroups.close();
305                         inFASTA.close();
306                 }
307                         
308                 return 0;               
309         }
310         catch(exception& e) {
311                 errorOut(e, "TrimSeqsCommand", "execute");
312                 exit(1);
313         }
314 }
315
316 //***************************************************************************************************************
317
318 void TrimSeqsCommand::getOligos(vector<ofstream*>& outFASTAVec){
319         try {
320                 ifstream inOligos;
321                 openInputFile(oligoFile, inOligos);
322                 
323                 ofstream test;
324                 
325                 string type, oligo, group;
326                 int index=0;
327                 
328                 while(!inOligos.eof()){
329                         inOligos >> type;
330                         
331                         if(type[0] == '#'){
332                                 while (!inOligos.eof()) {       char c = inOligos.get(); if (c == 10 || c == 13){       break;  }       } // get rest of line if there's any crap there
333                         }
334                         else{
335                                 inOligos >> oligo;
336                                 
337                                 for(int i=0;i<oligo.length();i++){
338                                         oligo[i] = toupper(oligo[i]);
339                                         if(oligo[i] == 'U')     {       oligo[i] = 'T'; }
340                                 }
341                                 
342                                 if(type == "forward"){
343                                         forPrimer.push_back(oligo);
344                                 }
345                                 else if(type == "reverse"){
346                                         Sequence oligoRC("reverse", oligo);
347                                         oligoRC.reverseComplement();
348                                         revPrimer.push_back(oligoRC.getUnaligned());
349                                 }
350                                 else if(type == "barcode"){
351                                         inOligos >> group;
352                                         barcodes[oligo]=index++;
353                                         groupVector.push_back(group);
354                                         
355                                         if(allFiles){
356                                                 outFASTAVec.push_back(new ofstream((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta").c_str(), ios::ate));
357                                         }
358                                 }
359                         }
360                 }
361                 
362                 inOligos.close();
363                 
364                 numFPrimers = forPrimer.size();
365                 numRPrimers = revPrimer.size();
366                 
367         }
368         catch(exception& e) {
369                 errorOut(e, "TrimSeqsCommand", "getOligos");
370                 exit(1);
371         }
372
373 }
374
375 //***************************************************************************************************************
376
377 bool TrimSeqsCommand::stripBarcode(Sequence& seq, int& group){
378         try {
379                 string rawSequence = seq.getUnaligned();
380                 bool success = 0;       //guilty until proven innocent
381                 
382                 for(map<string,int>::iterator it=barcodes.begin();it!=barcodes.end();it++){
383                         string oligo = it->first;
384                         if(rawSequence.length() < oligo.length()){      //let's just assume that the barcodes are the same length
385                                 success = 0;
386                                 break;
387                         }
388                         
389                         if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
390                                 group = it->second;
391                                 seq.setUnaligned(rawSequence.substr(oligo.length()));
392                                 success = 1;
393                                 break;
394                         }
395                 }
396                 return success;
397                 
398         }
399         catch(exception& e) {
400                 errorOut(e, "TrimSeqsCommand", "stripBarcode");
401                 exit(1);
402         }
403
404 }
405
406 //***************************************************************************************************************
407
408 bool TrimSeqsCommand::stripForward(Sequence& seq){
409         try {
410                 string rawSequence = seq.getUnaligned();
411                 bool success = 0;       //guilty until proven innocent
412                 
413                 for(int i=0;i<numFPrimers;i++){
414                         string oligo = forPrimer[i];
415                         
416                         if(rawSequence.length() < oligo.length()){
417                                 success = 0;
418                                 break;
419                         }
420                         
421                         if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
422                                 seq.setUnaligned(rawSequence.substr(oligo.length()));
423                                 success = 1;
424                                 break;
425                         }
426                 }
427                 
428                 return success;
429                 
430         }
431         catch(exception& e) {
432                 errorOut(e, "TrimSeqsCommand", "stripForward");
433                 exit(1);
434         }
435 }
436
437 //***************************************************************************************************************
438
439 bool TrimSeqsCommand::stripReverse(Sequence& seq){
440         try {
441                 string rawSequence = seq.getUnaligned();
442                 bool success = 0;       //guilty until proven innocent
443                 
444                 for(int i=0;i<numRPrimers;i++){
445                         string oligo = revPrimer[i];
446                         
447                         if(rawSequence.length() < oligo.length()){
448                                 success = 0;
449                                 break;
450                         }
451                         
452                         if(compareDNASeq(oligo, rawSequence.substr(rawSequence.length()-oligo.length(),oligo.length()))){
453                                 seq.setUnaligned(rawSequence.substr(0,rawSequence.length()-oligo.length()));
454                                 success = 1;
455                                 break;
456                         }
457                 }       
458                 return success;
459                 
460         }
461         catch(exception& e) {
462                 errorOut(e, "TrimSeqsCommand", "stripReverse");
463                 exit(1);
464         }
465 }
466
467 //***************************************************************************************************************
468
469 bool TrimSeqsCommand::cullLength(Sequence& seq){
470         try {
471         
472                 int length = seq.getNumBases();
473                 bool success = 0;       //guilty until proven innocent
474                 
475                 if(length >= minLength && maxLength == 0)                       {       success = 1;    }
476                 else if(length >= minLength && length <= maxLength)     {       success = 1;    }
477                 else                                                                                            {       success = 0;    }
478                 
479                 return success;
480         
481         }
482         catch(exception& e) {
483                 errorOut(e, "TrimSeqsCommand", "cullLength");
484                 exit(1);
485         }
486         
487 }
488
489 //***************************************************************************************************************
490
491 bool TrimSeqsCommand::cullHomoP(Sequence& seq){
492         try {
493                 int longHomoP = seq.getLongHomoPolymer();
494                 bool success = 0;       //guilty until proven innocent
495                 
496                 if(longHomoP <= maxHomoP){      success = 1;    }
497                 else                                    {       success = 0;    }
498                 
499                 return success;
500         }
501         catch(exception& e) {
502                 errorOut(e, "TrimSeqsCommand", "cullHomoP");
503                 exit(1);
504         }
505         
506 }
507
508 //***************************************************************************************************************
509
510 bool TrimSeqsCommand::cullAmbigs(Sequence& seq){
511         try {
512                 int numNs = seq.getAmbigBases();
513                 bool success = 0;       //guilty until proven innocent
514                 
515                 if(numNs <= maxAmbig)   {       success = 1;    }
516                 else                                    {       success = 0;    }
517                 
518                 return success;
519         }
520         catch(exception& e) {
521                 errorOut(e, "TrimSeqsCommand", "cullAmbigs");
522                 exit(1);
523         }
524         
525 }
526
527 //***************************************************************************************************************
528
529 bool TrimSeqsCommand::compareDNASeq(string oligo, string seq){
530         try {
531                 bool success = 1;
532                 int length = oligo.length();
533                 
534                 for(int i=0;i<length;i++){
535                         
536                         if(oligo[i] != seq[i]){
537                                 if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C')    {       success = 0;    }
538                                 else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N'))                                {       success = 0;    }
539                                 else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G'))                                    {       success = 0;    }
540                                 else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T'))                                    {       success = 0;    }
541                                 else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A'))                                    {       success = 0;    }
542                                 else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G'))                                    {       success = 0;    }
543                                 else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A'))                                    {       success = 0;    }
544                                 else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G'))                                    {       success = 0;    }
545                                 else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G'))   {       success = 0;    }
546                                 else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G'))   {       success = 0;    }
547                                 else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C'))   {       success = 0;    }
548                                 else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G'))   {       success = 0;    }                       
549                                 
550                                 if(success == 0)        {       break;  }
551                         }
552                         else{
553                                 success = 1;
554                         }
555                 }
556                 
557                 return success;
558         }
559         catch(exception& e) {
560                 errorOut(e, "TrimSeqsCommand", "compareDNASeq");
561                 exit(1);
562         }
563
564 }
565
566 //***************************************************************************************************************
567
568 bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){
569         try {
570                 string rawSequence = seq.getUnaligned();
571                 int seqLength = rawSequence.length();
572                 string name;
573                 
574                 qFile >> name;
575                 if (name.length() != 0) {  if(name.substr(1) != seq.getName())  {       mothurOut("sequence name mismatch btwn fasta and qual file"); mothurOutEndLine();       }  } 
576                 while (!qFile.eof())    {       char c = qFile.get(); if (c == 10 || c == 13){  break;  }       }
577                 
578                 int score;
579                 int end = seqLength;
580                 
581                 for(int i=0;i<seqLength;i++){
582                         qFile >> score;
583                         
584                         if(score <= qThreshold){
585                                 end = i;
586                                 break;
587                         }
588                 }
589                 for(int i=end+1;i<seqLength;i++){
590                         qFile >> score;
591                 }
592                 
593                 seq.setUnaligned(rawSequence.substr(0,end));
594                 
595                 return 1;
596         }
597         catch(exception& e) {
598                 errorOut(e, "TrimSeqsCommand", "stripQualThreshold");
599                 exit(1);
600         }
601 }
602
603 //***************************************************************************************************************
604
605 bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
606         try {
607                 string rawSequence = seq.getUnaligned();
608                 int seqLength = seq.getNumBases();
609                 bool success = 0;       //guilty until proven innocent
610                 string name;
611                 
612                 qFile >> name;
613                 if (name[0] == '>') {  if(name.substr(1) != seq.getName())      {       mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); mothurOutEndLine();       } }
614                 
615                 while (!qFile.eof())    {       char c = qFile.get(); if (c == 10 || c == 13){  break;  }       }
616                 
617                 float score;    
618                 float average = 0;
619                 
620                 for(int i=0;i<seqLength;i++){
621                         qFile >> score;
622                         average += score;
623                 }
624                 average /= seqLength;
625
626                 if(average >= qAverage) {       success = 1;    }
627                 else                                    {       success = 0;    }
628                 
629                 return success;
630         }
631         catch(exception& e) {
632                 errorOut(e, "TrimSeqsCommand", "cullQualAverage");
633                 exit(1);
634         }
635 }
636
637 //***************************************************************************************************************