X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Futils%2Fbamtools_utilities.h;h=9c1f7c9f0ac664fe63e9d791a8634ed1312310ba;hb=c80f364f4fcca3e585cbaadbe89ad1c42326669c;hp=73604fbff5f4812800e280450be967d8a4f74b3d;hpb=ced2983817b0efe2c4ea08ff1479937ea9131017;p=bamtools.git diff --git a/src/utils/bamtools_utilities.h b/src/utils/bamtools_utilities.h index 73604fb..9c1f7c9 100644 --- a/src/utils/bamtools_utilities.h +++ b/src/utils/bamtools_utilities.h @@ -1,9 +1,8 @@ // *************************************************************************** // bamtools_utilities.h (c) 2010 Derek Barnett, Erik Garrison // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 19 November 2010 +// Last modified: 7 October 2011 // --------------------------------------------------------------------------- // Provides general utilities used by BamTools sub-tools. // *************************************************************************** @@ -13,12 +12,11 @@ #include #include -#include -#include #include +#include -#define BAMTOOLS_ASSERT_UNREACHABLE assert( false ) -#define BAMTOOLS_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message ); +#define BAMTOOLS_ASSERT_UNREACHABLE BT_ASSERT_UNREACHABLE +#define BAMTOOLS_ASSERT_MESSAGE( condition, message ) BT_ASSERT_X( condition, message ) namespace BamTools { @@ -28,18 +26,38 @@ class BamMultiReader; class UTILS_EXPORT Utilities { public: + // returns true if 'source' contains 'pattern' or 'c' + static bool Contains(const std::string& source, const std::string& pattern); + static bool Contains(const std::string& source, const char c); + + // returns true if 'source' ends with 'pattern' or 'c' + static bool EndsWith(const std::string& source, const std::string& pattern); + static bool EndsWith(const std::string& source, const char c); + // check if a file exists static bool FileExists(const std::string& fname); // Parses a region string, uses reader to do validation (valid ID's, positions), stores in Region struct // Returns success (true/false) - static bool ParseRegionString(const std::string& regionString, const BamReader& reader, BamRegion& region); + static bool ParseRegionString(const std::string& regionString, + const BamReader& reader, + BamRegion& region); // Same as above, but accepts a BamMultiReader - static bool ParseRegionString(const std::string& regionString, const BamMultiReader& reader, BamRegion& region); + static bool ParseRegionString(const std::string& regionString, + const BamMultiReader& reader, + BamRegion& region); // sequence utilities static void Reverse(std::string& sequence); static void ReverseComplement(std::string& sequence); + + // split string on delimiter character (or string of allowed delimiters) + static std::vector Split(const std::string& source, const char delim); + static std::vector Split(const std::string& source, const std::string& delims); + + // returns true if 'source' starts with 'pattern' or 'c' + static bool StartsWith(const std::string& source, const std::string& pattern); + static bool StartsWith(const std::string &source, const char c); }; } // namespace BamTools