]> git.donarmstrong.com Git - bamtools.git/blob - src/utils/bamtools_utilities.h
d9a319271c1da6e856325cacc7371e20cc0a978a
[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: 8 September 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 <string>
16 #include <vector>
17
18 #define BAMTOOLS_ASSERT_UNREACHABLE BT_ASSERT_UNREACHABLE
19 #define BAMTOOLS_ASSERT_MESSAGE( condition, message ) BT_ASSERT_X( condition, message )
20
21 namespace BamTools {
22
23 class BamReader;
24 class BamMultiReader;
25
26 class UTILS_EXPORT Utilities {
27   
28     public: 
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);
32
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);
36
37         // check if a file exists
38         static bool FileExists(const std::string& fname);
39         
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,
44                                       BamRegion& region);
45         // Same as above, but accepts a BamMultiReader
46         static bool ParseRegionString(const std::string& regionString,
47                                       const BamMultiReader& reader,
48                                       BamRegion& region);
49
50         // sequence utilities
51         static void Reverse(std::string& sequence);
52         static void ReverseComplement(std::string& sequence);
53
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);
57
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);
61 };
62
63 } // namespace BamTools
64   
65 #endif // BAMTOOLS_UTILITIES_H