]> git.donarmstrong.com Git - mothur.git/blobdiff - sffinfocommand.cpp
fixed a trimming bug in sffinfo which occurs when the right trim point is smaller...
[mothur.git] / sffinfocommand.cpp
index cb5f87410e64583afa710ba034448e15cffb8fd1..4e53f69cb3e7dd51c3d4b30c10a09d76339b6f2c 100644 (file)
@@ -405,6 +405,7 @@ int SffInfoCommand::readHeader(ifstream& in, Header& header){
                        char buffer4 [2];
                        in.read(buffer4, 2);
                        header.clipQualLeft =  be_int2(*(unsigned short *)(&buffer4));
+                       header.clipQualLeft = 5; 
                        
                        //read clip qual right
                        char buffer5 [2];
@@ -561,6 +562,7 @@ int SffInfoCommand::printSffTxtSeqData(ofstream& out, seqRead& read, Header& hea
                for (int i = 0; i < read.flowIndex.size(); i++) {  sum +=  read.flowIndex[i];  out << sum << '\t'; }
                
                //make the bases you want to clip lowercase and the bases you want to keep upper case
+               if(header.clipQualRight == 0){  header.clipQualRight = read.bases.length();     }
                for (int i = 0; i < (header.clipQualLeft-1); i++) { read.bases[i] = tolower(read.bases[i]); }
                for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) {   read.bases[i] = toupper(read.bases[i]);  }
                for (int i = (header.clipQualRight-1); i < read.bases.length(); i++) {   read.bases[i] = tolower(read.bases[i]);  }
@@ -585,22 +587,23 @@ int SffInfoCommand::printFastaSeqData(ofstream& out, seqRead& read, Header& head
                string seq = read.bases;
                
                if (trim) {
-                       if(header.clipQualRight != 0){
-                               seq = seq.substr((header.clipQualLeft-1), (header.clipQualRight-header.clipQualLeft+1));
+                       if(header.clipQualRight < header.clipQualLeft){
+                               seq = "NNNN";
                        }
-                       else{
+                       else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
+                               seq = seq.substr((header.clipQualLeft-1), (header.clipQualRight-header.clipQualLeft));
+                       }
+                       else {
                                seq = seq.substr(header.clipQualLeft-1);
                        }
                }else{
                        //if you wanted the sfftxt then you already converted the bases to the right case
                        if (!sfftxt) {
                                //make the bases you want to clip lowercase and the bases you want to keep upper case
+                               if(header.clipQualRight == 0){  header.clipQualRight = seq.length();    }
                                for (int i = 0; i < (header.clipQualLeft-1); i++) { seq[i] = tolower(seq[i]);  }
                                for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++)  {   seq[i] = toupper(seq[i]);  }
-                               
-                               if(header.clipQualRight != 0){
-                                       for (int i = (header.clipQualRight-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
-                               }
+                               for (int i = (header.clipQualRight-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
                        }
                }
                
@@ -620,8 +623,17 @@ int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& heade
        try {
                
                if (trim) {
-                       out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft+1) << endl;
-                       for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) {   out << read.qualScores[i] << '\t';  }
+                       if(header.clipQualRight < header.clipQualLeft){
+                               out << "0\t0\t0\t0";
+                       }
+                       else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
+                               out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
+                               for (int i = (header.clipQualLeft-1); i < (header.clipQualRight-1); i++) {   out << read.qualScores[i] << '\t'; }
+                       }
+                       else{
+                               out << ">" << header.name << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
+                               for (int i = (header.clipQualLeft-1); i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';   }                       
+                       }
                }else{
                        out << ">" << header.name << " length=" << read.qualScores.size() << endl;
                        for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }