]> git.donarmstrong.com Git - mothur.git/blobdiff - sffinfocommand.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / sffinfocommand.cpp
index a1b7066482b973bcbaeebefdc718c5c96d70aae9..3961802804f02c5d60c2a017803b666f43e74047 100644 (file)
@@ -1039,7 +1039,11 @@ int SffInfoCommand::findGroup(Header header, seqRead read, int& barcode, int& pr
         
         if (trim) {
             if(header.clipQualRight < header.clipQualLeft){
-                seq = "NNNN";
+                if (header.clipQualRight == 0) { //don't trim right
+                    seq = seq.substr(header.clipQualLeft-1);
+                }else {
+                    seq = "NNNN";
+                }
             }
             else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
                 seq = seq.substr((header.clipQualLeft-1), (header.clipQualRight-header.clipQualLeft));
@@ -1050,11 +1054,12 @@ int SffInfoCommand::findGroup(Header header, seqRead read, int& barcode, int& pr
         }else{
             //if you wanted the sfftxt then you already converted the bases to the right case
             if (!sfftxt) {
+                int endValue = header.clipQualRight;
                 //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();    }
+                if(endValue == 0){     endValue = 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]);  }
-                for (int i = (header.clipQualRight-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
+                for (int i = (header.clipQualLeft-1); i < (endValue-1); i++)  {   seq[i] = toupper(seq[i]);  }
+                for (int i = (endValue-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
             }
         }
         
@@ -1235,10 +1240,11 @@ 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();     }
+        int endValue = header.clipQualRight;
+               if(endValue == 0){      endValue = 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]);  }
+               for (int i = (header.clipQualLeft-1); i < (endValue-1); i++) {   read.bases[i] = toupper(read.bases[i]);  }
+               for (int i = (endValue-1); i < read.bases.length(); i++) {   read.bases[i] = tolower(read.bases[i]);  }
                
                out << endl <<  "Bases: " << read.bases << endl << "Quality Scores: ";
                for (int i = 0; i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';  }
@@ -1260,7 +1266,11 @@ int SffInfoCommand::printFastaSeqData(ofstream& out, seqRead& read, Header& head
                
         if (trim) {
                        if(header.clipQualRight < header.clipQualLeft){
-                               seq = "NNNN";
+                               if (header.clipQualRight == 0) { //don't trim right
+                    seq = seq.substr(header.clipQualLeft-1);
+                }else {
+                    seq = "NNNN";
+                }
                        }
                        else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
                                seq = seq.substr((header.clipQualLeft-1), (header.clipQualRight-header.clipQualLeft));
@@ -1271,11 +1281,12 @@ int SffInfoCommand::printFastaSeqData(ofstream& out, seqRead& read, Header& head
                }else{
                        //if you wanted the sfftxt then you already converted the bases to the right case
                        if (!sfftxt) {
+                int endValue = header.clipQualRight;
                                //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();    }
+                               if(endValue == 0){      endValue = 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]);  }
-                               for (int i = (header.clipQualRight-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
+                               for (int i = (header.clipQualLeft-1); i < (endValue-1); i++)  {   seq[i] = toupper(seq[i]);  }
+                               for (int i = (endValue-1); i < seq.length(); i++) {   seq[i] = tolower(seq[i]);  }
                        }
                }
                
@@ -1296,8 +1307,13 @@ int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& heade
                
                if (trim) {
                        if(header.clipQualRight < header.clipQualLeft){
-                               out << ">" << header.name << " xy=" << header.xy << endl;
-                               out << "0\t0\t0\t0";
+                if (header.clipQualRight == 0) { //don't trim right
+                    out << ">" << header.name << " xy=" << header.xy << " length=" << (read.qualScores.size()-header.clipQualLeft) << endl;
+                    for (int i = (header.clipQualLeft-1); i < read.qualScores.size(); i++) {   out << read.qualScores[i] << '\t';      }       
+                }else {
+                    out << ">" << header.name << " xy=" << header.xy << endl;
+                    out << "0\t0\t0\t0";
+                }
                        }
                        else if((header.clipQualRight != 0) && ((header.clipQualRight-header.clipQualLeft) >= 0)){
                                out << ">" << header.name << " xy=" << header.xy << " length=" << (header.clipQualRight-header.clipQualLeft) << endl;
@@ -1325,15 +1341,18 @@ int SffInfoCommand::printQualSeqData(ofstream& out, seqRead& read, Header& heade
 //**********************************************************************************************************************
 int SffInfoCommand::printFlowSeqData(ofstream& out, seqRead& read, Header& header) {
        try {
-               if(header.clipQualRight > header.clipQualLeft){
-                       
-                       int rightIndex = 0;
-                       for (int i = 0; i < header.clipQualRight; i++) {  rightIndex +=  read.flowIndex[i];     }
-
-                       out << header.name << ' ' << rightIndex;
-                       for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << ' ' << (read.flowgram[i]/(float)100);  }
-                       out << endl;
-               }
+        
+        int endValue = header.clipQualRight;
+        if (header.clipQualRight == 0) {  endValue = read.flowIndex.size(); }
+        if(endValue > header.clipQualLeft){
+            
+            int rightIndex = 0;
+            for (int i = 0; i < endValue; i++) {  rightIndex +=  read.flowIndex[i];     }
+            
+            out << header.name << ' ' << rightIndex;
+            for (int i = 0; i < read.flowgram.size(); i++) { out << setprecision(2) << ' ' << (read.flowgram[i]/(float)100);  }
+            out << endl;
+        }
                
                
                return 0;
@@ -1641,7 +1660,7 @@ bool SffInfoCommand::readOligos(string oligoFile){
                                        // get rest of line in case there is a primer name
                                        while (!inOligos.eof()) {       
                                                char c = inOligos.get(); 
-                                               if (c == 10 || c == 13){        break;  }
+                                               if (c == 10 || c == 13 || c == -1){     break;  }
                                                else if (c == 32 || c == 9){;} //space or tab
                                                else {  group += c;  }
                                        }