From f7d86e0fa7161081f69c5c178ee0141bea599f71 Mon Sep 17 00:00:00 2001 From: Derek Barnett Date: Tue, 4 Dec 2012 11:42:50 -0500 Subject: [PATCH] Version 2.2.2 * Added: BamAlignment::GetArrayTagType() --- CMakeLists.txt | 2 +- docs/Doxyfile | 2 +- src/api/BamAlignment.cpp | 68 +++++++++++++++++++++++++++++++++++++- src/api/BamAlignment.h | 5 ++- src/api/CMakeLists.txt | 2 +- src/toolkit/CMakeLists.txt | 2 +- 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27deb55..9e3dc8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ ensure_out_of_source_build( " # set BamTools version information set( BamTools_VERSION_MAJOR 2 ) set( BamTools_VERSION_MINOR 2 ) -set( BamTools_VERSION_BUILD 1 ) +set( BamTools_VERSION_BUILD 2 ) # set our library and executable destination dirs set( EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin" ) diff --git a/docs/Doxyfile b/docs/Doxyfile index af6daab..c2ff078 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -31,7 +31,7 @@ PROJECT_NAME = BamTools # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 2.2.1 +PROJECT_NUMBER = 2.2.2 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. diff --git a/src/api/BamAlignment.cpp b/src/api/BamAlignment.cpp index b8482f6..620ba2e 100644 --- a/src/api/BamAlignment.cpp +++ b/src/api/BamAlignment.cpp @@ -2,7 +2,7 @@ // BamAlignment.cpp (c) 2009 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 18 November 2012 (DB) +// Last modified: 4 December 2012 (DB) // --------------------------------------------------------------------------- // Provides the BamAlignment data structure // *************************************************************************** @@ -394,6 +394,72 @@ bool BamAlignment::FindTag(const std::string& tag, return false; } +/*! \fn bool BamAlignment::GetArrayTagType(const std::string& tag, char& type) const + \brief Retrieves the BAM tag type-code for the array elements associated with requested tag name. + + \param[in] tag 2-character tag name + \param[out] type retrieved (1-character) type-code + + \return \c true if found. False if not found, or if tag is not an array type. + \sa \samSpecURL for more details on reserved tag names, supported tag types, etc. +*/ +bool BamAlignment::GetArrayTagType(const std::string& tag, char& type) const { + + // skip if alignment is core-only + if ( SupportData.HasCoreOnly ) { + // TODO: set error string? + return false; + } + + // skip if no tags present + if ( TagData.empty() ) { + // TODO: set error string? + return false; + } + + // localize the tag data + char* pTagData = (char*)TagData.data(); + const unsigned int tagDataLength = TagData.size(); + unsigned int numBytesParsed = 0; + + // if tag not found, return failure + if ( !FindTag(tag, pTagData, tagDataLength, numBytesParsed) ){ + // TODO: set error string? + return false; + } + + // check that tag type code is array + type = *(pTagData - 1); + if ( type != Constants::BAM_TAG_TYPE_ARRAY ) { + // TODO: set error string + return false; + } + + // fetch element type + const char elementType = *pTagData; + switch ( elementType ) { + + // allowable types + case (Constants::BAM_TAG_TYPE_INT8) : + case (Constants::BAM_TAG_TYPE_UINT8) : + case (Constants::BAM_TAG_TYPE_INT16) : + case (Constants::BAM_TAG_TYPE_UINT16) : + case (Constants::BAM_TAG_TYPE_INT32) : + case (Constants::BAM_TAG_TYPE_UINT32) : + case (Constants::BAM_TAG_TYPE_FLOAT) : + type = elementType; + break; + + default: + //TODO: set error string + return false; + } + + // if we get here, return success + return true; +} + + /*! \fn int BamAlignment::GetEndPosition(bool usePadded = false, bool closedInterval = false) const \brief Calculates alignment end position, based on its starting position and CIGAR data. diff --git a/src/api/BamAlignment.h b/src/api/BamAlignment.h index d18b239..e12aad6 100644 --- a/src/api/BamAlignment.h +++ b/src/api/BamAlignment.h @@ -2,7 +2,7 @@ // BamAlignment.h (c) 2009 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 18 November 2012 (DB) +// Last modified: 4 December 2012 (DB) // --------------------------------------------------------------------------- // Provides the BamAlignment data structure // *************************************************************************** @@ -86,6 +86,9 @@ struct API_EXPORT BamAlignment { // retrieves the SAM/BAM type-code for requested tag name bool GetTagType(const std::string& tag, char& type) const; + // retrieves the SAM/BAM type-code for the data elements in an array tag + bool GetArrayTagType(const std::string& tag, char& type) const; + // returns true if alignment has a record for this tag name bool HasTag(const std::string& tag) const; diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 321be23..be46a7a 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -34,7 +34,7 @@ set( BamToolsAPISources # create main BamTools API shared library add_library( BamTools SHARED ${BamToolsAPISources} ) set_target_properties( BamTools PROPERTIES - SOVERSION "2.2.1" + SOVERSION "2.2.2" OUTPUT_NAME "bamtools" ) # create main BamTools API static library diff --git a/src/toolkit/CMakeLists.txt b/src/toolkit/CMakeLists.txt index d9c92d4..ba5b640 100644 --- a/src/toolkit/CMakeLists.txt +++ b/src/toolkit/CMakeLists.txt @@ -31,7 +31,7 @@ add_executable( bamtools_cmd # set BamTools application properties set_target_properties( bamtools_cmd PROPERTIES - VERSION 2.2.1 + VERSION 2.2.2 OUTPUT_NAME "bamtools" ) # make version info available in application -- 2.39.2