1 // ***************************************************************************
2 // bamtools_utilities.h (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 7 October 2011
6 // ---------------------------------------------------------------------------
7 // Provides general utilities used by BamTools sub-tools.
8 // ***************************************************************************
10 #ifndef BAMTOOLS_UTILITIES_H
11 #define BAMTOOLS_UTILITIES_H
13 #include <api/BamAux.h>
14 #include <utils/utils_global.h>
18 #define BAMTOOLS_ASSERT_UNREACHABLE BT_ASSERT_UNREACHABLE
19 #define BAMTOOLS_ASSERT_MESSAGE( condition, message ) BT_ASSERT_X( condition, message )
26 class UTILS_EXPORT Utilities {
29 // returns true if 'source' contains 'pattern' or 'c'
30 static bool Contains(const std::string& source, const std::string& pattern);
31 static bool Contains(const std::string& source, const char c);
33 // returns true if 'source' ends with 'pattern' or 'c'
34 static bool EndsWith(const std::string& source, const std::string& pattern);
35 static bool EndsWith(const std::string& source, const char c);
37 // check if a file exists
38 static bool FileExists(const std::string& fname);
40 // Parses a region string, uses reader to do validation (valid ID's, positions), stores in Region struct
41 // Returns success (true/false)
42 static bool ParseRegionString(const std::string& regionString,
43 const BamReader& reader,
45 // Same as above, but accepts a BamMultiReader
46 static bool ParseRegionString(const std::string& regionString,
47 const BamMultiReader& reader,
51 static void Reverse(std::string& sequence);
52 static void ReverseComplement(std::string& sequence);
54 // split string on delimiter character (or string of allowed delimiters)
55 static std::vector<std::string> Split(const std::string& source, const char delim);
56 static std::vector<std::string> Split(const std::string& source, const std::string& delims);
58 // returns true if 'source' starts with 'pattern' or 'c'
59 static bool StartsWith(const std::string& source, const std::string& pattern);
60 static bool StartsWith(const std::string &source, const char c);
63 } // namespace BamTools
65 #endif // BAMTOOLS_UTILITIES_H