]> git.donarmstrong.com Git - bamtools.git/blob - src/utils/bamtools_utilities.h
3320e33351ceca803fed906d4af9c883ecce2120
[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: 9 June 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 <cassert>
17 #include <stdexcept>
18 #include <string>
19 #include <vector>
20
21 #define BAMTOOLS_ASSERT_UNREACHABLE assert( false )
22 #define BAMTOOLS_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message );
23
24 namespace BamTools {
25
26 class BamReader;
27 class BamMultiReader;
28
29 class UTILS_EXPORT Utilities {
30   
31     public: 
32         // returns true if 'source' contains 'pattern' or 'c'
33         static bool Contains(const std::string& source, const std::string& pattern);
34         static bool Contains(const std::string& source, const char c);
35
36         // returns true if 'source' ends with 'pattern' or 'c'
37         static bool EndsWith(const std::string& source, const std::string& pattern);
38         static bool EndsWith(const std::string& source, const char c);
39
40         // check if a file exists
41         static bool FileExists(const std::string& fname);
42         
43         // Parses a region string, uses reader to do validation (valid ID's, positions), stores in Region struct
44         // Returns success (true/false)
45         static bool ParseRegionString(const std::string& regionString,
46                                       const BamReader& reader,
47                                       BamRegion& region);
48         // Same as above, but accepts a BamMultiReader
49         static bool ParseRegionString(const std::string& regionString,
50                                       const BamMultiReader& reader,
51                                       BamRegion& region);
52
53         // sequence utilities
54         static void Reverse(std::string& sequence);
55         static void ReverseComplement(std::string& sequence);
56
57         // split string on delimiter character (or string of allowed delimiters)
58         static std::vector<std::string> Split(const std::string& source, const char delim);
59         static std::vector<std::string> Split(const std::string& source, const std::string& delims);
60
61         // returns true if 'source' starts with 'pattern' or 'c'
62         static bool StartsWith(const std::string& source, const std::string& pattern);
63         static bool StartsWith(const std::string &source, const char c);
64 };
65
66 } // namespace BamTools
67   
68 #endif // BAMTOOLS_UTILITIES_H