From 3052ce4f428518b5d75fe744d37a7e7946b10ded Mon Sep 17 00:00:00 2001 From: Derek Barnett Date: Sun, 11 Nov 2012 23:11:57 -0500 Subject: [PATCH] Fixed: regression in convert tool - SAM tags contained unreadable chars for int8/uint8 types --- src/toolkit/bamtools_convert.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/toolkit/bamtools_convert.cpp b/src/toolkit/bamtools_convert.cpp index 1de3a31..0e1743f 100644 --- a/src/toolkit/bamtools_convert.cpp +++ b/src/toolkit/bamtools_convert.cpp @@ -2,7 +2,7 @@ // bamtools_convert.cpp (c) 2010 Derek Barnett, Erik Garrison // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 26 September 2012 +// Last modified: 11 November 2012 // --------------------------------------------------------------------------- // Converts between BAM and a number of other formats // *************************************************************************** @@ -435,12 +435,14 @@ void ConvertTool::ConvertToolPrivate::PrintJson(const BamAlignment& a) { break; case (Constants::BAM_TAG_TYPE_INT8) : - m_out << (int8_t)tagData[index]; + // force value into integer-type (instead of char value) + m_out << static_cast(tagData[index]); ++index; break; case (Constants::BAM_TAG_TYPE_UINT8) : - m_out << (uint8_t)tagData[index]; + // force value into integer-type (instead of char value) + m_out << static_cast(tagData[index]); ++index; break; @@ -501,8 +503,8 @@ void ConvertTool::ConvertToolPrivate::PrintSam(const BamAlignment& a) { // [ :: [...] ] // write name & alignment flag - m_out << a.Name << "\t" << a.AlignmentFlag << "\t"; - + m_out << a.Name << "\t" << a.AlignmentFlag << "\t"; + // write reference name if ( (a.RefID >= 0) && (a.RefID < (int)m_references.size()) ) m_out << m_references[a.RefID].RefName << "\t"; @@ -530,7 +532,7 @@ void ConvertTool::ConvertToolPrivate::PrintSam(const BamAlignment& a) { if ( a.MateRefID == a.RefID ) m_out << "=\t"; else - m_out << m_references[a.MateRefID].RefName << "\t"; + m_out << m_references[a.MateRefID].RefName << "\t"; m_out << a.MatePosition+1 << "\t" << a.InsertSize << "\t"; } else @@ -569,13 +571,15 @@ void ConvertTool::ConvertToolPrivate::PrintSam(const BamAlignment& a) { ++index; break; - case (Constants::BAM_TAG_TYPE_INT8) : - m_out << "i:" << (int8_t)tagData[index]; + case (Constants::BAM_TAG_TYPE_INT8) : + // force value into integer-type (instead of char value) + m_out << "i:" << static_cast(tagData[index]); ++index; break; case (Constants::BAM_TAG_TYPE_UINT8) : - m_out << "i:" << (uint8_t)tagData[index]; + // force value into integer-type (instead of char value) + m_out << "i:" << static_cast(tagData[index]); ++index; break; @@ -604,7 +608,7 @@ void ConvertTool::ConvertToolPrivate::PrintSam(const BamAlignment& a) { index += sizeof(float); break; - case (Constants::BAM_TAG_TYPE_HEX) : + case (Constants::BAM_TAG_TYPE_HEX) : // fall-through case (Constants::BAM_TAG_TYPE_STRING) : m_out << type << ":"; while (tagData[index]) { @@ -615,7 +619,7 @@ void ConvertTool::ConvertToolPrivate::PrintSam(const BamAlignment& a) { break; } - if ( tagData[index] == '\0') + if ( tagData[index] == '\0' ) break; } -- 2.39.2