]> git.donarmstrong.com Git - bamtools.git/blobdiff - bamtools_convert.cpp
further cleanup of duplicate @RG tag warning reporting
[bamtools.git] / bamtools_convert.cpp
index de86599288242a749e544d60abc5dd58ef8d92f0..655c25a623013d9c95714cb954d087184aaa62ce 100644 (file)
@@ -187,7 +187,7 @@ void BamTools::PrintJSON(ostream& out, const BamAlignment& a) {
         for ( ; cigarIter != cigarEnd; ++cigarIter ) {
             const CigarOp& op = (*cigarIter);
             if (cigarIter != cigarBegin) out << ",";
-            out << "[\"" << op.Length << ",\"" << op.Type << "\"]";
+            out << "\"" << op.Length << op.Type << "\"";
         }
         out << "],";
     }
@@ -238,12 +238,12 @@ void BamTools::PrintJSON(ostream& out, const BamAlignment& a) {
                     break;
                 
                 case('C') : 
-                    out << atoi(&tagData[index])
+                    out << (int)tagData[index]
                     ++index; 
                     break;
                 
                 case('c') : 
-                    out << atoi(&tagData[index]);
+                    out << (int)tagData[index];
                     ++index; 
                     break;
                 
@@ -288,6 +288,8 @@ void BamTools::PrintJSON(ostream& out, const BamAlignment& a) {
                     ++index; 
                     break;      
             }
+            
+            if ( tagData[index] == '\0') break;
         }
 
         out << "}";
@@ -345,12 +347,11 @@ void BamTools::PrintSAM(ostream& out, const BamAlignment& a) {
     // write tag data
     const char* tagData = a.TagData.c_str();
     const size_t tagDataLength = a.TagData.length();
+    
     size_t index = 0;
     while ( index < tagDataLength ) {
 
-        cerr << tagDataLength << " " << index << endl;
-        
-        // write tag name
+        // write tag name        
         out << "\t" << a.TagData.substr(index, 2) << ":";
         index += 2;
         
@@ -365,12 +366,12 @@ void BamTools::PrintSAM(ostream& out, const BamAlignment& a) {
                 break;
             
             case('C') : 
-                out << "i:" << atoi(&tagData[index])
+                out << "i:" << (int)tagData[index]
                 ++index; 
                 break;
             
             case('c') : 
-                out << "i:" << atoi(&tagData[index]);
+                out << "i:" << (int)tagData[index];
                 ++index; 
                 break;
             
@@ -384,7 +385,7 @@ void BamTools::PrintSAM(ostream& out, const BamAlignment& a) {
                 index += 2; 
                 break;
             
-            case('I') : 
+            case('I') :
                 out << "i:" << BgzfData::UnpackUnsignedInt(&tagData[index]);
                 index += 4; 
                 break;
@@ -414,8 +415,9 @@ void BamTools::PrintSAM(ostream& out, const BamAlignment& a) {
                 ++index; 
                 break;      
         }
+
+        if ( tagData[index] == '\0') break;
     }
 
     out << endl;
-    
 }