# set BamTools library properties
set_target_properties( BamTools-utils PROPERTIES
- SOVERSION 1.0.0
+ SOVERSION 1.0.2
OUTPUT_NAME bamtools-utils
)
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 19 November 2010
+// Last modified: 11 June 2011
// ---------------------------------------------------------------------------
// Parses command line arguments and creates a help menu
// ---------------------------------------------------------------------------
string Options::m_exampleArguments; // the example arguments
vector<OptionGroup> Options::m_optionGroups; // stores the option groups
map<string, OptionValue> Options::m_optionsMap; // stores the options in a map
-string Options::m_stdin = "stdin"; // string representation of stdin
-string Options::m_stdout = "stdout"; // string representation of stdout
+const string Options::m_stdin = "stdin"; // string representation of stdin
+const string Options::m_stdout = "stdout"; // string representation of stdout
// adds a simple option to the parser
-void Options::AddOption(const string& argument, const string& optionDescription, bool& foundArgument, OptionGroup* group) {
-
+void Options::AddOption(const string& argument,
+ const string& optionDescription,
+ bool& foundArgument,
+ OptionGroup* group)
+{
Option o;
o.Argument = argument;
o.Description = optionDescription;
const std::string stringValue = optionIter->DefaultValue;
sb << stringValue;
} else {
- printf("ERROR: Found an unsupported data type for argument %s when casting the default value.\n", optionIter->Argument.c_str());
+ printf("ERROR: Found an unsupported data type for argument %s when casting the default value.\n",
+ optionIter->Argument.c_str());
exit(1);
}
vector<string>* pVectorValue = (vector<string>*)ovMapIter->second.pValue;
pVectorValue->push_back(val);
} else {
- printf("ERROR: Found an unsupported data type for argument %s when parsing the arguments.\n", argument.c_str());
+ printf("ERROR: Found an unsupported data type for argument %s when parsing the arguments.\n",
+ argument.c_str());
exit(1);
}
} else {
- errorBuilder << ERROR_SPACER << "The argument (" << argument << ") expects a value, but none was found." << endl;
+ errorBuilder << ERROR_SPACER << "The argument (" << argument
+ << ") expects a value, but none was found." << endl;
foundError = true;
}
} else {
- errorBuilder << ERROR_SPACER << "The argument (" << argument << ") expects a value, but none was found." << endl;
+ errorBuilder << ERROR_SPACER << "The argument (" << argument
+ << ") expects a value, but none was found." << endl;
foundError = true;
}
}
// check if we missed any required parameters
for (ovMapIter = m_optionsMap.begin(); ovMapIter != m_optionsMap.end(); ++ovMapIter) {
if (ovMapIter->second.IsRequired && !*ovMapIter->second.pFoundArgument) {
- errorBuilder << ERROR_SPACER << ovMapIter->second.ValueTypeDescription << " was not specified. Please use the " << ovMapIter->first << " parameter." << endl;
+ errorBuilder << ERROR_SPACER << ovMapIter->second.ValueTypeDescription
+ << " was not specified. Please use the " << ovMapIter->first << " parameter." << endl;
foundError = true;
}
}
}
// sets the program info
-void Options::SetProgramInfo(const string& programName, const string& description, const string& arguments) {
+void Options::SetProgramInfo(const string& programName,
+ const string& description,
+ const string& arguments)
+{
m_programName = programName;
m_description = description;
m_exampleArguments = arguments;
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 19 November 2010
+// Last modified: 11 June 2011
// ---------------------------------------------------------------------------
// Parses command line arguments and creates a help menu
// ---------------------------------------------------------------------------
namespace BamTools {
#define ARGUMENT_LENGTH 35
-#define DESC_LENGTH_FIRST_ROW 50
-#define DESC_LENGTH 39
+#define DESC_LENGTH_FIRST_ROW 30
+#define DESC_LENGTH 42
#define MAX_LINE_LENGTH 78
#ifdef WIN32
// parses the command line
static void Parse(int argc, char* argv[], int offset = 0);
// sets the program info
- static void SetProgramInfo(const std::string& programName, const std::string& description, const std::string& arguments);
+ static void SetProgramInfo(const std::string& programName,
+ const std::string& description,
+ const std::string& arguments);
// returns string representation of stdin
static const std::string& StandardIn(void);
// returns string representation of stdout
// stores the options in a map
static std::map<std::string, OptionValue> m_optionsMap;
// string representation of stdin
- static std::string m_stdin;
+ static const std::string m_stdin;
// string representation of stdout
- static std::string m_stdout;
+ static const std::string m_stdout;
};
// adds a value option to the parser
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 26 January 2011
+// Last modified: 9 June 2011
// ---------------------------------------------------------------------------
// Provides general utilities used by BamTools sub-tools.
// ***************************************************************************
#include <algorithm>
#include <cstdlib>
+#include <cstring>
#include <fstream>
#include <iostream>
+#include <sstream>
using namespace std;
namespace BamTools {
} // namespace BamTools
+// returns true if 'source' contains 'pattern'
+bool Utilities::Contains(const string& source, const string& pattern) {
+ return ( source.find(pattern) != string::npos );
+}
+
+// returns true if 'source' contains 'c'
+bool Utilities::Contains(const std::string &source, const char c) {
+ return ( source.find(c) != string::npos );
+}
+
+// returns true if 'source' ends with 'pattern'
+bool Utilities::EndsWith(const string& source, const string& pattern) {
+ return ( source.find(pattern) == (source.length() - pattern.length()) );
+}
+
+// returns true if 'source' ends with 'c'
+bool Utilities::EndsWith(const std::string& source, const char c) {
+ return ( source.find(c) == (source.length() - 1) );
+}
+
// check if a file exists
bool Utilities::FileExists(const string& filename) {
ifstream f(filename.c_str(), ifstream::in);
// reverse it
Reverse(sequence);
}
+
+vector<string> Utilities::Split(const string& source, const char delim) {
+
+ stringstream ss(source);
+ string field;
+ vector<string> fields;
+
+ while ( getline(ss, field, delim) )
+ fields.push_back(field);
+ return fields;
+}
+
+vector<string> Utilities::Split(const string& source, const string& delims) {
+
+ vector<string> fields;
+
+ char* tok;
+ char cchars [source.size()+1];
+ char* cstr = &cchars[0];
+ strcpy(cstr, source.c_str());
+ tok = strtok(cstr, delims.c_str());
+ while (tok != NULL) {
+ fields.push_back(tok);
+ tok = strtok(NULL, delims.c_str());
+ }
+
+ return fields;
+}
+
+// returns true if 'source' starts with 'pattern'
+bool Utilities::StartsWith(const string& source, const string& pattern) {
+ return ( source.find(pattern) == 0 );
+}
+
+// returns true if 'source' starts with 'c'
+bool Utilities::StartsWith(const std::string &source, const char c) {
+ return ( source.find(c) == 0 );
+}
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 26 January 2011
+// Last modified: 9 June 2011
// ---------------------------------------------------------------------------
// Provides general utilities used by BamTools sub-tools.
// ***************************************************************************
#include <cassert>
#include <stdexcept>
#include <string>
+#include <vector>
#define BAMTOOLS_ASSERT_UNREACHABLE assert( false )
#define BAMTOOLS_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message );
class UTILS_EXPORT Utilities {
public:
+ // returns true if 'source' contains 'pattern' or 'c'
+ static bool Contains(const std::string& source, const std::string& pattern);
+ static bool Contains(const std::string& source, const char c);
+
+ // returns true if 'source' ends with 'pattern' or 'c'
+ static bool EndsWith(const std::string& source, const std::string& pattern);
+ static bool EndsWith(const std::string& source, const char c);
+
// check if a file exists
static bool FileExists(const std::string& fname);
// sequence utilities
static void Reverse(std::string& sequence);
static void ReverseComplement(std::string& sequence);
+
+ // split string on delimiter character (or string of allowed delimiters)
+ static std::vector<std::string> Split(const std::string& source, const char delim);
+ static std::vector<std::string> Split(const std::string& source, const std::string& delims);
+
+ // returns true if 'source' starts with 'pattern' or 'c'
+ static bool StartsWith(const std::string& source, const std::string& pattern);
+ static bool StartsWith(const std::string &source, const char c);
};
} // namespace BamTools