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