-/*! \fn bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const std::string& value)
- \brief Adds a field with string data to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param type 1-character tag type (must be "Z" or "H")
- \param value string data to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const std::string& value) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // validate tag/type size & that type is OK for string value
- if ( !IsValidSize(tag, type) ) return false;
- if ( type.at(0) != Constants::BAM_TAG_TYPE_STRING &&
- type.at(0) != Constants::BAM_TAG_TYPE_HEX
- )
- {
- return false;
- }
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // otherwise, copy tag data to temp buffer
- string newTag = tag + type + value;
- const int newTagDataLength = tagDataLength + newTag.size() + 1; // leave room for null-term
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength + 1); // '+1' for TagData null-term
-
- // append newTag
- strcat(originalTagData + tagDataLength, newTag.data()); // removes original null-term, appends newTag + null-term
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const uint32_t& value)
- \brief Adds a field with unsigned integer data to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param type 1-character tag type (must NOT be "f", "Z", "H", or "B")
- \param value unsigned int data to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const uint32_t& value) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // validate tag/type size & that type is OK for uint32_t value
- if ( !IsValidSize(tag, type) ) return false;
- if ( type.at(0) == Constants::BAM_TAG_TYPE_FLOAT ||
- type.at(0) == Constants::BAM_TAG_TYPE_STRING ||
- type.at(0) == Constants::BAM_TAG_TYPE_HEX ||
- type.at(0) == Constants::BAM_TAG_TYPE_ARRAY
- )
- {
- return false;
- }
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // otherwise, convert value to string
- union { uint32_t value; char valueBuffer[sizeof(uint32_t)]; } un;
- un.value = value;
-
- // copy original tag data to temp buffer
- string newTag = tag + type;
- const int newTagDataLength = tagDataLength + newTag.size() + 4; // leave room for new integer
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength + 1); // '+1' for TagData null-term
-
- // append newTag
- strcat(originalTagData + tagDataLength, newTag.data());
- memcpy(originalTagData + tagDataLength + newTag.size(), un.valueBuffer, sizeof(uint32_t));
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const int32_t& value)
- \brief Adds a field with signed integer data to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param type 1-character tag type (must NOT be "f", "Z", "H", or "B")
- \param value signed int data to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const int32_t& value) {
- return AddTag(tag, type, (const uint32_t&)value);
-}
-
-/*! \fn bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const float& value)
- \brief Adds a field with floating-point data to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param type 1-character tag type (must NOT be "Z", "H", or "B")
- \param value float data to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::string& type, const float& value) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // validate tag/type size & that type is OK for float value
- if ( !IsValidSize(tag, type) ) return false;
- if ( type.at(0) == Constants::BAM_TAG_TYPE_STRING ||
- type.at(0) == Constants::BAM_TAG_TYPE_HEX ||
- type.at(0) == Constants::BAM_TAG_TYPE_ARRAY
- )
- {
- return false;
- }
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // otherwise, convert value to string
- union { float value; char valueBuffer[sizeof(float)]; } un;
- un.value = value;
-
- // copy original tag data to temp buffer
- string newTag = tag + type;
- const int newTagDataLength = tagDataLength + newTag.size() + 4; // leave room for new float
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength + 1); // '+1' for TagData null-term
-
- // append newTag
- strcat(originalTagData + tagDataLength, newTag.data());
- memcpy(originalTagData + tagDataLength + newTag.size(), un.valueBuffer, sizeof(float));
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool AddTag(const std::string& tag, const std::vector<uint8_t>& values);
- \brief Adds a numeric array field to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param values vector of uint8_t values to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint8_t>& values) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // check for valid tag length
- if ( tag.size() != Constants::BAM_TAG_TAGSIZE ) return false;
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // build new tag's base information
- char newTagBase[Constants::BAM_TAG_ARRAYBASE_SIZE];
- memcpy( newTagBase, tag.c_str(), Constants::BAM_TAG_TAGSIZE );
- newTagBase[2] = Constants::BAM_TAG_TYPE_ARRAY;
- newTagBase[3] = Constants::BAM_TAG_TYPE_UINT8;
-
- // add number of array elements to newTagBase
- const int32_t numElements = values.size();
- memcpy(newTagBase + 4, &numElements, sizeof(int32_t));
-
- // copy current TagData string to temp buffer, leaving room for new tag's contents
- const int newTagDataLength = tagDataLength +
- Constants::BAM_TAG_ARRAYBASE_SIZE +
- numElements*sizeof(uint8_t);
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
-
- // write newTagBase (removes old null term)
- strcat(originalTagData + tagDataLength, (const char*)newTagBase);
-
- // add vector elements to tag
- int elementsBeginOffset = tagDataLength + Constants::BAM_TAG_ARRAYBASE_SIZE;
- for ( int i = 0 ; i < numElements; ++i ) {
- const uint8_t value = values.at(i);
- memcpy(originalTagData + elementsBeginOffset + i*sizeof(uint8_t),
- &value, sizeof(uint8_t));
- }
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool AddTag(const std::string& tag, const std::vector<int8_t>& values);
- \brief Adds a numeric array field to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param values vector of int8_t values to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::vector<int8_t>& values) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // check for valid tag length
- if ( tag.size() != Constants::BAM_TAG_TAGSIZE ) return false;
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // build new tag's base information
- char newTagBase[Constants::BAM_TAG_ARRAYBASE_SIZE];
- memcpy( newTagBase, tag.c_str(), Constants::BAM_TAG_TAGSIZE );
- newTagBase[2] = Constants::BAM_TAG_TYPE_ARRAY;
- newTagBase[3] = Constants::BAM_TAG_TYPE_INT8;
-
- // add number of array elements to newTagBase
- const int32_t numElements = values.size();
- memcpy(newTagBase + 4, &numElements, sizeof(int32_t));
-
- // copy current TagData string to temp buffer, leaving room for new tag's contents
- const int newTagDataLength = tagDataLength +
- Constants::BAM_TAG_ARRAYBASE_SIZE +
- numElements*sizeof(int8_t);
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
-
- // write newTagBase (removes old null term)
- strcat(originalTagData + tagDataLength, (const char*)newTagBase);
-
- // add vector elements to tag
- int elementsBeginOffset = tagDataLength + Constants::BAM_TAG_ARRAYBASE_SIZE;
- for ( int i = 0 ; i < numElements; ++i ) {
- const int8_t value = values.at(i);
- memcpy(originalTagData + elementsBeginOffset + i*sizeof(int8_t),
- &value, sizeof(int8_t));
- }
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool AddTag(const std::string& tag, const std::vector<uint16_t>& values);
- \brief Adds a numeric array field to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param values vector of uint16_t values to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint16_t>& values) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // check for valid tag length
- if ( tag.size() != Constants::BAM_TAG_TAGSIZE ) return false;
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // build new tag's base information
- char newTagBase[Constants::BAM_TAG_ARRAYBASE_SIZE];
- memcpy( newTagBase, tag.c_str(), Constants::BAM_TAG_TAGSIZE );
- newTagBase[2] = Constants::BAM_TAG_TYPE_ARRAY;
- newTagBase[3] = Constants::BAM_TAG_TYPE_UINT16;
-
- // add number of array elements to newTagBase
- const int32_t numElements = values.size();
- memcpy(newTagBase + 4, &numElements, sizeof(int32_t));
-
- // copy current TagData string to temp buffer, leaving room for new tag's contents
- const int newTagDataLength = tagDataLength +
- Constants::BAM_TAG_ARRAYBASE_SIZE +
- numElements*sizeof(uint16_t);
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
-
- // write newTagBase (removes old null term)
- strcat(originalTagData + tagDataLength, (const char*)newTagBase);
-
- // add vector elements to tag
- int elementsBeginOffset = tagDataLength + Constants::BAM_TAG_ARRAYBASE_SIZE;
- for ( int i = 0 ; i < numElements; ++i ) {
- const uint16_t value = values.at(i);
- memcpy(originalTagData + elementsBeginOffset + i*sizeof(uint16_t),
- &value, sizeof(uint16_t));
- }
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool AddTag(const std::string& tag, const std::vector<int16_t>& values);
- \brief Adds a numeric array field to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param values vector of int16_t values to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::vector<int16_t>& values) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // check for valid tag length
- if ( tag.size() != Constants::BAM_TAG_TAGSIZE ) return false;
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // build new tag's base information
- char newTagBase[Constants::BAM_TAG_ARRAYBASE_SIZE];
- memcpy( newTagBase, tag.c_str(), Constants::BAM_TAG_TAGSIZE );
- newTagBase[2] = Constants::BAM_TAG_TYPE_ARRAY;
- newTagBase[3] = Constants::BAM_TAG_TYPE_INT16;
-
- // add number of array elements to newTagBase
- const int32_t numElements = values.size();
- memcpy(newTagBase + 4, &numElements, sizeof(int32_t));
-
- // copy current TagData string to temp buffer, leaving room for new tag's contents
- const int newTagDataLength = tagDataLength +
- Constants::BAM_TAG_ARRAYBASE_SIZE +
- numElements*sizeof(int16_t);
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
-
- // write newTagBase (removes old null term)
- strcat(originalTagData + tagDataLength, (const char*)newTagBase);
-
- // add vector elements to tag
- int elementsBeginOffset = tagDataLength + Constants::BAM_TAG_ARRAYBASE_SIZE;
- for ( int i = 0 ; i < numElements; ++i ) {
- const int16_t value = values.at(i);
- memcpy(originalTagData + elementsBeginOffset + i*sizeof(int16_t),
- &value, sizeof(int16_t));
- }
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool AddTag(const std::string& tag, const std::vector<uint32_t>& values);
- \brief Adds a numeric array field to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param values vector of uint32_t values to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::vector<uint32_t>& values) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // check for valid tag length
- if ( tag.size() != Constants::BAM_TAG_TAGSIZE ) return false;
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // build new tag's base information
- char newTagBase[Constants::BAM_TAG_ARRAYBASE_SIZE];
- memcpy( newTagBase, tag.c_str(), Constants::BAM_TAG_TAGSIZE );
- newTagBase[2] = Constants::BAM_TAG_TYPE_ARRAY;
- newTagBase[3] = Constants::BAM_TAG_TYPE_UINT32;
-
- // add number of array elements to newTagBase
- const int32_t numElements = values.size();
- memcpy(newTagBase + 4, &numElements, sizeof(int32_t));
-
- // copy current TagData string to temp buffer, leaving room for new tag's contents
- const int newTagDataLength = tagDataLength +
- Constants::BAM_TAG_ARRAYBASE_SIZE +
- numElements*sizeof(uint32_t);
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
-
- // write newTagBase (removes old null term)
- strcat(originalTagData + tagDataLength, (const char*)newTagBase);
-
- // add vector elements to tag
- int elementsBeginOffset = tagDataLength + Constants::BAM_TAG_ARRAYBASE_SIZE;
- for ( int i = 0 ; i < numElements; ++i ) {
- const uint32_t value = values.at(i);
- memcpy(originalTagData + elementsBeginOffset + i*sizeof(uint32_t),
- &value, sizeof(uint32_t));
- }
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool AddTag(const std::string& tag, const std::vector<int32_t>& values);
- \brief Adds a numeric array field to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param values vector of int32_t values to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::vector<int32_t>& values) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // check for valid tag length
- if ( tag.size() != Constants::BAM_TAG_TAGSIZE ) return false;
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // build new tag's base information
- char newTagBase[Constants::BAM_TAG_ARRAYBASE_SIZE];
- memcpy( newTagBase, tag.c_str(), Constants::BAM_TAG_TAGSIZE );
- newTagBase[2] = Constants::BAM_TAG_TYPE_ARRAY;
- newTagBase[3] = Constants::BAM_TAG_TYPE_INT32;
-
- // add number of array elements to newTagBase
- const int32_t numElements = values.size();
- memcpy(newTagBase + 4, &numElements, sizeof(int32_t));
-
- // copy current TagData string to temp buffer, leaving room for new tag's contents
- const int newTagDataLength = tagDataLength +
- Constants::BAM_TAG_ARRAYBASE_SIZE +
- numElements*sizeof(int32_t);
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
-
- // write newTagBase (removes old null term)
- strcat(originalTagData + tagDataLength, (const char*)newTagBase);
-
- // add vector elements to tag
- int elementsBeginOffset = tagDataLength + Constants::BAM_TAG_ARRAYBASE_SIZE;
- for ( int i = 0 ; i < numElements; ++i ) {
- const int32_t value = values.at(i);
- memcpy(originalTagData + elementsBeginOffset + i*sizeof(int32_t),
- &value, sizeof(int32_t));
- }
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-
-/*! \fn bool AddTag(const std::string& tag, const std::vector<float>& values);
- \brief Adds a numeric array field to the BAM tags.
-
- Does NOT modify an existing tag - use \link BamAlignment::EditTag() \endlink instead.
-
- \param tag 2-character tag name
- \param values vector of float values to store
-
- \return \c true if the \b new tag was added successfully
- \sa \samSpecURL for more details on reserved tag names, supported tag types, etc.
-*/
-bool BamAlignment::AddTag(const std::string& tag, const std::vector<float>& values) {
-
- // skip if core data not parsed
- if ( SupportData.HasCoreOnly ) return false;
-
- // check for valid tag length
- if ( tag.size() != Constants::BAM_TAG_TAGSIZE ) return false;
-
- // localize the tag data
- char* pTagData = (char*)TagData.data();
- const unsigned int tagDataLength = TagData.size();
- unsigned int numBytesParsed = 0;
-
- // if tag already exists, return false
- // use EditTag explicitly instead
- if ( FindTag(tag, pTagData, tagDataLength, numBytesParsed) )
- return false;
-
- // build new tag's base information
- char newTagBase[Constants::BAM_TAG_ARRAYBASE_SIZE];
- memcpy( newTagBase, tag.c_str(), Constants::BAM_TAG_TAGSIZE );
- newTagBase[2] = Constants::BAM_TAG_TYPE_ARRAY;
- newTagBase[3] = Constants::BAM_TAG_TYPE_FLOAT;
-
- // add number of array elements to newTagBase
- const int32_t numElements = values.size();
- memcpy(newTagBase + 4, &numElements, sizeof(int32_t));
-
- // copy current TagData string to temp buffer, leaving room for new tag's contents
- const int newTagDataLength = tagDataLength +
- Constants::BAM_TAG_ARRAYBASE_SIZE +
- numElements*sizeof(float);
- char originalTagData[newTagDataLength];
- memcpy(originalTagData, TagData.c_str(), tagDataLength+1); // '+1' for TagData's null-term
-
- // write newTagBase (removes old null term)
- strcat(originalTagData + tagDataLength, (const char*)newTagBase);
-
- // add vector elements to tag
- int elementsBeginOffset = tagDataLength + Constants::BAM_TAG_ARRAYBASE_SIZE;
- for ( int i = 0 ; i < numElements; ++i ) {
- const float value = values.at(i);
- memcpy(originalTagData + elementsBeginOffset + i*sizeof(float),
- &value, sizeof(float));
- }
-
- // store temp buffer back in TagData
- const char* newTagData = (const char*)originalTagData;
- TagData.assign(newTagData, newTagDataLength);
-
- // return success
- return true;
-}
-