5 * Created by Pat Schloss on 6/6/09.
6 * Copyright 2009 Patrick D. Schloss. All rights reserved.
10 #include "trimseqscommand.h"
12 //***************************************************************************************************************
14 TrimSeqsCommand::TrimSeqsCommand(string option) {
19 //allow user to run help
20 if(option == "help") { help(); abort = true; }
23 //valid paramters for this command
24 string AlignArray[] = {"fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile",
25 "qthreshold", "qaverage", "allfiles", "qtrim", "processors", "outputdir","inputdir"};
27 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
29 OptionParser parser(option);
30 map<string,string> parameters = parser.getParameters();
32 ValidParameters validParameter;
33 map<string,string>::iterator it;
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; }
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 = ""; }
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; }
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; }
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; }
71 //check for required parameters
72 fastaFile = validParameter.validFile(parameters, "fasta", true);
73 if (fastaFile == "not found") { m->mothurOut("fasta is a required parameter for the screen.seqs command."); m->mothurOutEndLine(); abort = true; }
74 else if (fastaFile == "not open") { abort = true; }
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"){
79 outputDir += hasPath(fastaFile); //if user entered a file with a path then preserve it
82 //check for optional parameter and set defaults
83 // ...at some point should added some additional type checking...
85 temp = validParameter.validFile(parameters, "flip", false);
86 if (temp == "not found"){ flip = 0; }
87 else if(isTrue(temp)) { flip = 1; }
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; }
94 temp = validParameter.validFile(parameters, "maxambig", false); if (temp == "not found") { temp = "-1"; }
95 convert(temp, maxAmbig);
97 temp = validParameter.validFile(parameters, "maxhomop", false); if (temp == "not found") { temp = "0"; }
98 convert(temp, maxHomoP);
100 temp = validParameter.validFile(parameters, "minlength", false); if (temp == "not found") { temp = "0"; }
101 convert(temp, minLength);
103 temp = validParameter.validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "0"; }
104 convert(temp, maxLength);
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; }
111 temp = validParameter.validFile(parameters, "qthreshold", false); if (temp == "not found") { temp = "0"; }
112 convert(temp, qThreshold);
114 temp = validParameter.validFile(parameters, "qtrim", false); if (temp == "not found") { temp = "F"; }
115 qtrim = isTrue(temp);
117 temp = validParameter.validFile(parameters, "qaverage", false); if (temp == "not found") { temp = "0"; }
118 convert(temp, qAverage);
120 temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found") { temp = "F"; }
121 allFiles = isTrue(temp);
123 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; }
124 convert(temp, processors);
126 if(allFiles && oligoFile == ""){
127 m->mothurOut("You selected allfiles, but didn't enter an oligos file. Ignoring the allfiles request."); m->mothurOutEndLine();
129 if((qAverage != 0 && qThreshold != 0) && qFileName == ""){
130 m->mothurOut("You didn't provide a quality file name, quality criteria will be ignored."); m->mothurOutEndLine();
134 if(!flip && oligoFile=="" && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP && qFileName == ""){
135 m->mothurOut("You didn't set any options... quiting command."); m->mothurOutEndLine();
141 catch(exception& e) {
142 m->errorOut(e, "TrimSeqsCommand", "TrimSeqsCommand");
146 //**********************************************************************************************************************
148 void TrimSeqsCommand::help(){
150 m->mothurOut("The trim.seqs command reads a fastaFile and creates .....\n");
151 m->mothurOut("The trim.seqs command parameters are fasta, flip, oligos, maxambig, maxhomop, minlength, maxlength, qfile, qthreshold, qaverage, qtrim and allfiles.\n");
152 m->mothurOut("The fasta parameter is required.\n");
153 m->mothurOut("The flip parameter .... The default is 0.\n");
154 m->mothurOut("The oligos parameter .... The default is "".\n");
155 m->mothurOut("The maxambig parameter .... The default is -1.\n");
156 m->mothurOut("The maxhomop parameter .... The default is 0.\n");
157 m->mothurOut("The minlength parameter .... The default is 0.\n");
158 m->mothurOut("The maxlength parameter .... The default is 0.\n");
159 m->mothurOut("The qfile parameter .....\n");
160 m->mothurOut("The qthreshold parameter .... The default is 0.\n");
161 m->mothurOut("The qaverage parameter .... The default is 0.\n");
162 m->mothurOut("The allfiles parameter .... The default is F.\n");
163 m->mothurOut("The qtrim parameter .... The default is F.\n");
164 m->mothurOut("The trim.seqs command should be in the following format: \n");
165 m->mothurOut("trim.seqs(fasta=yourFastaFile, flip=yourFlip, oligos=yourOligos, maxambig=yourMaxambig, \n");
166 m->mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n");
167 m->mothurOut("Example trim.seqs(fasta=abrecovery.fasta, flip=..., oligos=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n");
168 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n");
169 m->mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/Trim.seqs .\n\n");
172 catch(exception& e) {
173 m->errorOut(e, "TrimSeqsCommand", "help");
179 //***************************************************************************************************************
181 TrimSeqsCommand::~TrimSeqsCommand(){ /* do nothing */ }
183 //***************************************************************************************************************
185 int TrimSeqsCommand::execute(){
188 if (abort == true) { return 0; }
190 numFPrimers = 0; //this needs to be initialized
193 string trimSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "trim.fasta";
194 outputNames.push_back(trimSeqFile);
195 string scrapSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "scrap.fasta";
196 outputNames.push_back(scrapSeqFile);
197 string groupFile = outputDir + getRootName(getSimpleName(fastaFile)) + "groups";
199 vector<string> fastaFileNames;
201 outputNames.push_back(groupFile);
202 getOligos(fastaFileNames);
205 if(qFileName != "") { setLines(qFileName, qLines); }
208 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
211 openInputFile(fastaFile, inFASTA);
212 int numSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
215 lines.push_back(new linePair(0, numSeqs));
217 driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, groupFile, fastaFileNames, lines[0], lines[0]);
219 for (int j = 0; j < fastaFileNames.size(); j++) {
220 rename((fastaFileNames[j] + toString(getpid()) + ".temp").c_str(), fastaFileNames[j].c_str());
224 setLines(fastaFile, lines);
225 if(qFileName == "") { qLines = lines; }
227 createProcessesCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, groupFile, fastaFileNames);
229 rename((trimSeqFile + toString(processIDS[0]) + ".temp").c_str(), trimSeqFile.c_str());
230 rename((scrapSeqFile + toString(processIDS[0]) + ".temp").c_str(), scrapSeqFile.c_str());
231 rename((groupFile + toString(processIDS[0]) + ".temp").c_str(), groupFile.c_str());
232 for (int j = 0; j < fastaFileNames.size(); j++) {
233 rename((fastaFileNames[j] + toString(processIDS[0]) + ".temp").c_str(), fastaFileNames[j].c_str());
236 for(int i=1;i<processors;i++){
237 appendFiles((trimSeqFile + toString(processIDS[i]) + ".temp"), trimSeqFile);
238 remove((trimSeqFile + toString(processIDS[i]) + ".temp").c_str());
239 appendFiles((scrapSeqFile + toString(processIDS[i]) + ".temp"), scrapSeqFile);
240 remove((scrapSeqFile + toString(processIDS[i]) + ".temp").c_str());
241 appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile);
242 remove((groupFile + toString(processIDS[i]) + ".temp").c_str());
243 for (int j = 0; j < fastaFileNames.size(); j++) {
244 appendFiles((fastaFileNames[j] + toString(processIDS[i]) + ".temp"), fastaFileNames[j]);
245 remove((fastaFileNames[j] + toString(processIDS[i]) + ".temp").c_str());
250 if (m->control_pressed) { return 0; }
253 openInputFile(fastafileNames[s], inFASTA);
254 numSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
257 lines.push_back(new linePair(0, numSeqs));
259 driverCreateSummary(fastafile, qFileName, trimSeqFile, scrapSeqFile, groupFile, fastaFileNames, lines[0], lines[0]);
261 if (m->control_pressed) { return 0; }
265 for(int i=0;i<fastaFileNames.size();i++){
268 openInputFile(getRootName(fastaFile) + groupVector[i] + ".fasta", inFASTA);
270 openOutputFile(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups", outGroups);
271 outputNames.push_back(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups");
273 while(!inFASTA.eof()){
274 if(inFASTA.get() == '>'){
276 outGroups << seqName << '\t' << groupVector[i] << endl;
278 while (!inFASTA.eof()) { char c = inFASTA.get(); if (c == 10 || c == 13){ break; } }
284 if (m->control_pressed) {
285 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
289 m->mothurOutEndLine();
290 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
291 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
292 m->mothurOutEndLine();
297 catch(exception& e) {
298 m->errorOut(e, "TrimSeqsCommand", "execute");
303 /**************************************************************************************/
304 int TrimSeqsCommand::driverCreateTrim(string filename, string qFileName, string trimFile, string scrapFile, string groupFile, vector<string> fastaNames, linePair* line, linePair* qline) {
308 int able = openOutputFile(trimFile, outFASTA);
311 openOutputFile(scrapFile, scrapFASTA);
314 vector<ofstream*> fastaFileNames;
315 if (oligoFile != "") {
316 openOutputFile(groupFile, outGroups);
317 for (int i = 0; i < fastaNames.size(); i++) {
318 fastaFileNames.push_back(new ofstream((fastaNames[i] + toString(getpid()) + ".temp").c_str(), ios::ate));
323 openInputFile(filename, inFASTA);
326 if(qFileName != "") { openInputFile(qFileName, qFile); }
328 qFile.seekg(qline->start);
329 inFASTA.seekg(line->start);
331 for(int i=0;i<line->num;i++){
333 if (m->control_pressed) {
337 if (oligoFile != "") { outGroups.close(); }
338 if(qFileName != "") { qFile.close(); }
339 for(int i=0;i<fastaFileNames.size();i++){
340 fastaFileNames[i]->close();
341 delete fastaFileNames[i];
343 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
349 Sequence currSeq(inFASTA);
351 string origSeq = currSeq.getUnaligned();
354 string trashCode = "";
357 if(qThreshold != 0) { success = stripQualThreshold(currSeq, qFile); }
358 else if(qAverage != 0) { success = cullQualAverage(currSeq, qFile); }
359 if ((!qtrim) && (origSeq.length() != currSeq.getUnaligned().length())) {
360 success = 0; //if you don't want to trim and the sequence does not meet quality requirements, move to scrap
362 if(!success) { trashCode += 'q'; }
365 if(barcodes.size() != 0){
366 success = stripBarcode(currSeq, group);
367 if(!success){ trashCode += 'b'; }
370 if(numFPrimers != 0){
371 success = stripForward(currSeq);
372 if(!success){ trashCode += 'f'; }
375 if(numRPrimers != 0){
376 success = stripReverse(currSeq);
377 if(!success){ trashCode += 'r'; }
380 if(minLength > 0 || maxLength > 0){
381 success = cullLength(currSeq);
382 if(!success){ trashCode += 'l'; }
385 success = cullHomoP(currSeq);
386 if(!success){ trashCode += 'h'; }
389 success = cullAmbigs(currSeq);
390 if(!success){ trashCode += 'n'; }
393 if(flip){ currSeq.reverseComplement(); } // should go last
395 if(trashCode.length() == 0){
396 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.
397 currSeq.printSequence(outFASTA);
398 if(barcodes.size() != 0){
399 outGroups << currSeq.getName() << '\t' << groupVector[group] << endl;
402 currSeq.printSequence(*fastaFileNames[group]);
407 currSeq.setName(currSeq.getName() + '|' + trashCode);
408 currSeq.setUnaligned(origSeq);
409 currSeq.printSequence(scrapFASTA);
418 if (oligoFile != "") { outGroups.close(); }
419 if(qFileName != "") { qFile.close(); }
421 for(int i=0;i<fastaFileNames.size();i++){
422 fastaFileNames[i]->close();
423 delete fastaFileNames[i];
428 catch(exception& e) {
429 m->errorOut(e, "TrimSeqsCommand", "driverCreateTrim");
433 /**************************************************************************************************/
434 int TrimSeqsCommand::createProcessesCreateTrim(string filename, string qFileName, string trimFile, string scrapFile, string groupFile, vector<string> fastaNames) {
436 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
441 //loop through and create all the processes you want
442 while (process != processors) {
446 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
449 driverCreateTrim(filename, qFileName, (trimFile + toString(getpid()) + ".temp"), (scrapFile + toString(getpid()) + ".temp"), (groupFile + toString(getpid()) + ".temp"), fastaNames, lines[process], qLines[process]);
451 }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
454 //force parent to wait until all the processes are done
455 for (int i=0;i<processors;i++) {
456 int temp = processIDS[i];
463 catch(exception& e) {
464 m->errorOut(e, "TrimSeqsCommand", "createProcessesCreateTrim");
468 /**************************************************************************************************/
470 int TrimSeqsCommand::setLines(string filename, vector<linePair*>& lines) {
475 vector<long int> positions;
478 openInputFile(filename, inFASTA);
481 while(!inFASTA.eof()){
482 input = getline(inFASTA);
484 if (input.length() != 0) {
485 if(input[0] == '>'){ long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
490 int numFastaSeqs = positions.size();
495 //get num bytes in file
496 pFile = fopen (filename.c_str(),"rb");
497 if (pFile==NULL) perror ("Error opening file");
499 fseek (pFile, 0, SEEK_END);
504 int numSeqsPerProcessor = numFastaSeqs / processors;
506 for (int i = 0; i < processors; i++) {
508 long int startPos = positions[ i * numSeqsPerProcessor ];
509 if(i == processors - 1){
510 numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
512 long int myEnd = positions[ (i+1) * numSeqsPerProcessor ];
514 lines.push_back(new linePair(startPos, numSeqsPerProcessor));
519 catch(exception& e) {
520 m->errorOut(e, "TrimSeqsCommand", "setLines");
524 //***************************************************************************************************************
526 void TrimSeqsCommand::getOligos(vector<string>& outFASTAVec){ //vector<ofstream*>& outFASTAVec
529 openInputFile(oligoFile, inOligos);
533 string type, oligo, group;
536 while(!inOligos.eof()){
540 while (!inOligos.eof()) { char c = inOligos.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there
545 for(int i=0;i<oligo.length();i++){
546 oligo[i] = toupper(oligo[i]);
547 if(oligo[i] == 'U') { oligo[i] = 'T'; }
550 if(type == "forward"){
551 forPrimer.push_back(oligo);
553 else if(type == "reverse"){
554 Sequence oligoRC("reverse", oligo);
555 oligoRC.reverseComplement();
556 revPrimer.push_back(oligoRC.getUnaligned());
558 else if(type == "barcode"){
560 barcodes[oligo]=index++;
561 groupVector.push_back(group);
564 //outFASTAVec.push_back(new ofstream((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta").c_str(), ios::ate));
565 outputNames.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta"));
566 outFASTAVec.push_back((outputDir + getRootName(getSimpleName(fastaFile)) + group + ".fasta"));
574 numFPrimers = forPrimer.size();
575 numRPrimers = revPrimer.size();
578 catch(exception& e) {
579 m->errorOut(e, "TrimSeqsCommand", "getOligos");
585 //***************************************************************************************************************
587 bool TrimSeqsCommand::stripBarcode(Sequence& seq, int& group){
589 string rawSequence = seq.getUnaligned();
590 bool success = 0; //guilty until proven innocent
592 for(map<string,int>::iterator it=barcodes.begin();it!=barcodes.end();it++){
593 string oligo = it->first;
594 if(rawSequence.length() < oligo.length()){ //let's just assume that the barcodes are the same length
599 if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
601 seq.setUnaligned(rawSequence.substr(oligo.length()));
609 catch(exception& e) {
610 m->errorOut(e, "TrimSeqsCommand", "stripBarcode");
616 //***************************************************************************************************************
618 bool TrimSeqsCommand::stripForward(Sequence& seq){
620 string rawSequence = seq.getUnaligned();
621 bool success = 0; //guilty until proven innocent
623 for(int i=0;i<numFPrimers;i++){
624 string oligo = forPrimer[i];
626 if(rawSequence.length() < oligo.length()){
631 if(compareDNASeq(oligo, rawSequence.substr(0,oligo.length()))){
632 seq.setUnaligned(rawSequence.substr(oligo.length()));
641 catch(exception& e) {
642 m->errorOut(e, "TrimSeqsCommand", "stripForward");
647 //***************************************************************************************************************
649 bool TrimSeqsCommand::stripReverse(Sequence& seq){
651 string rawSequence = seq.getUnaligned();
652 bool success = 0; //guilty until proven innocent
654 for(int i=0;i<numRPrimers;i++){
655 string oligo = revPrimer[i];
657 if(rawSequence.length() < oligo.length()){
662 if(compareDNASeq(oligo, rawSequence.substr(rawSequence.length()-oligo.length(),oligo.length()))){
663 seq.setUnaligned(rawSequence.substr(0,rawSequence.length()-oligo.length()));
671 catch(exception& e) {
672 m->errorOut(e, "TrimSeqsCommand", "stripReverse");
677 //***************************************************************************************************************
679 bool TrimSeqsCommand::cullLength(Sequence& seq){
682 int length = seq.getNumBases();
683 bool success = 0; //guilty until proven innocent
685 if(length >= minLength && maxLength == 0) { success = 1; }
686 else if(length >= minLength && length <= maxLength) { success = 1; }
687 else { success = 0; }
692 catch(exception& e) {
693 m->errorOut(e, "TrimSeqsCommand", "cullLength");
699 //***************************************************************************************************************
701 bool TrimSeqsCommand::cullHomoP(Sequence& seq){
703 int longHomoP = seq.getLongHomoPolymer();
704 bool success = 0; //guilty until proven innocent
706 if(longHomoP <= maxHomoP){ success = 1; }
707 else { success = 0; }
711 catch(exception& e) {
712 m->errorOut(e, "TrimSeqsCommand", "cullHomoP");
718 //***************************************************************************************************************
720 bool TrimSeqsCommand::cullAmbigs(Sequence& seq){
722 int numNs = seq.getAmbigBases();
723 bool success = 0; //guilty until proven innocent
725 if(numNs <= maxAmbig) { success = 1; }
726 else { success = 0; }
730 catch(exception& e) {
731 m->errorOut(e, "TrimSeqsCommand", "cullAmbigs");
737 //***************************************************************************************************************
739 bool TrimSeqsCommand::compareDNASeq(string oligo, string seq){
742 int length = oligo.length();
744 for(int i=0;i<length;i++){
746 if(oligo[i] != seq[i]){
747 if(oligo[i] == 'A' || oligo[i] == 'T' || oligo[i] == 'G' || oligo[i] == 'C') { success = 0; }
748 else if((oligo[i] == 'N' || oligo[i] == 'I') && (seq[i] == 'N')) { success = 0; }
749 else if(oligo[i] == 'R' && (seq[i] != 'A' && seq[i] != 'G')) { success = 0; }
750 else if(oligo[i] == 'Y' && (seq[i] != 'C' && seq[i] != 'T')) { success = 0; }
751 else if(oligo[i] == 'M' && (seq[i] != 'C' && seq[i] != 'A')) { success = 0; }
752 else if(oligo[i] == 'K' && (seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
753 else if(oligo[i] == 'W' && (seq[i] != 'T' && seq[i] != 'A')) { success = 0; }
754 else if(oligo[i] == 'S' && (seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
755 else if(oligo[i] == 'B' && (seq[i] != 'C' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
756 else if(oligo[i] == 'D' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'G')) { success = 0; }
757 else if(oligo[i] == 'H' && (seq[i] != 'A' && seq[i] != 'T' && seq[i] != 'C')) { success = 0; }
758 else if(oligo[i] == 'V' && (seq[i] != 'A' && seq[i] != 'C' && seq[i] != 'G')) { success = 0; }
760 if(success == 0) { break; }
769 catch(exception& e) {
770 m->errorOut(e, "TrimSeqsCommand", "compareDNASeq");
776 //***************************************************************************************************************
778 bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){
780 string rawSequence = seq.getUnaligned();
781 int seqLength; // = rawSequence.length();
782 string name, temp, temp2;
784 qFile >> name >> temp;
786 splitAtEquals(temp2, temp); //separates length=242, temp=length, temp2=242
787 convert(temp, seqLength); //converts string to int
789 if (name.length() != 0) { if(name.substr(1) != seq.getName()) { m->mothurOut("sequence name mismatch btwn fasta and qual file"); m->mothurOutEndLine(); } }
790 while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } }
795 for(int i=0;i<seqLength;i++){
798 if(score <= qThreshold){
803 for(int i=end+1;i<seqLength;i++){
807 seq.setUnaligned(rawSequence.substr(0,end));
811 catch(exception& e) {
812 m->errorOut(e, "TrimSeqsCommand", "stripQualThreshold");
817 //***************************************************************************************************************
819 bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){
821 string rawSequence = seq.getUnaligned();
822 int seqLength = seq.getNumBases();
823 bool success = 0; //guilty until proven innocent
827 if (name[0] == '>') { if(name.substr(1) != seq.getName()) { m->mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); m->mothurOutEndLine(); } }
829 while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } }
834 for(int i=0;i<seqLength;i++){
838 average /= seqLength;
840 if(average >= qAverage) { success = 1; }
841 else { success = 0; }
845 catch(exception& e) {
846 m->errorOut(e, "TrimSeqsCommand", "cullQualAverage");
851 //***************************************************************************************************************