]> git.donarmstrong.com Git - bamtools.git/blob - src/utils/bamtools_utilities.h
Minor cleanup
[bamtools.git] / src / utils / bamtools_utilities.h
1 // ***************************************************************************
2 // bamtools_utilities.h (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 9 June 2011
6 // ---------------------------------------------------------------------------
7 // Provides general utilities used by BamTools sub-tools.
8 // ***************************************************************************
9
10 #ifndef BAMTOOLS_UTILITIES_H
11 #define BAMTOOLS_UTILITIES_H
12
13 #include <api/BamAux.h>
14 #include <utils/utils_global.h>
15 #include <cassert>
16 #include <stdexcept>
17 #include <string>
18 #include <vector>
19
20 #define BAMTOOLS_ASSERT_UNREACHABLE assert( false )
21 #define BAMTOOLS_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message );
22
23 namespace BamTools {
24
25 class BamReader;
26 class BamMultiReader;
27
28 class UTILS_EXPORT Utilities {
29   
30     public: 
31         // returns true if 'source' contains 'pattern' or 'c'
32         static bool Contains(const std::string& source, const std::string& pattern);
33         static bool Contains(const std::string& source, const char c);
34
35         // returns true if 'source' ends with 'pattern' or 'c'
36         static bool EndsWith(const std::string& source, const std::string& pattern);
37         static bool EndsWith(const std::string& source, const char c);
38
39         // check if a file exists
40         static bool FileExists(const std::string& fname);
41         
42         // Parses a region string, uses reader to do validation (valid ID's, positions), stores in Region struct
43         // Returns success (true/false)
44         static bool ParseRegionString(const std::string& regionString,
45                                       const BamReader& reader,
46                                       BamRegion& region);
47         // Same as above, but accepts a BamMultiReader
48         static bool ParseRegionString(const std::string& regionString,
49                                       const BamMultiReader& reader,
50                                       BamRegion& region);
51
52         // sequence utilities
53         static void Reverse(std::string& sequence);
54         static void ReverseComplement(std::string& sequence);
55
56         // split string on delimiter character (or string of allowed delimiters)
57         static std::vector<std::string> Split(const std::string& source, const char delim);
58         static std::vector<std::string> Split(const std::string& source, const std::string& delims);
59
60         // returns true if 'source' starts with 'pattern' or 'c'
61         static bool StartsWith(const std::string& source, const std::string& pattern);
62         static bool StartsWith(const std::string &source, const char c);
63 };
64
65 } // namespace BamTools
66   
67 #endif // BAMTOOLS_UTILITIES_H