From 81bbce8a213e07867470b8b01d5b2fae0e1cb668 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 26 May 2010 22:25:39 -0400 Subject: [PATCH] Mostly cleaned up help & usage messages. Added MIT license. --- LICENSE | 22 ++++++++++++++++++++++ bamtools.cpp | 16 ++++++++-------- bamtools_coverage.h | 7 ++++--- bamtools_dump.h | 5 +++-- bamtools_getopt.h | 9 ++++++++- bamtools_header.h | 5 +++-- bamtools_index.h | 7 ++++--- bamtools_merge.h | 33 ++++++++++++++++++++++++--------- bamtools_sam.h | 21 +++++++++++---------- bamtools_sort.h | 11 ++++++----- bamtools_stats.h | 7 ++++--- 11 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eaee1fd --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License + +Copyright (c) 2009-2010 Derek Barnett, Erik Garrison, Gabor Marth, Michael Stromberg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/bamtools.cpp b/bamtools.cpp index d80d960..6a43438 100644 --- a/bamtools.cpp +++ b/bamtools.cpp @@ -65,14 +65,14 @@ int Help(int argc, char* argv[]) { cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl; cerr << endl; cerr << "Available bamtools commands:" << endl; - cerr << "\tcoverage\tPrints coverage statistics from the input BAM file" << endl; - cerr << "\tdump\t\tDump BAM file contents to text output" << endl; // keep? - cerr << "\theader\t\tPrints BAM header information" << endl; - cerr << "\tindex\t\tGenerates index for BAM file" << endl; - cerr << "\tmerge\t\tMerge multiple BAM files into single file" << endl; - cerr << "\tsam\t\tPrints the BAM file in SAM (text) format" << endl; - cerr << "\tsort\t\tSorts the BAM file according to some criteria" << endl; - cerr << "\tstats\t\tPrints some basic statistics from the input BAM file" << endl; + cerr << "\tcoverage Prints coverage statistics from the input BAM file" << endl; + cerr << "\tdump Dump BAM file contents to text output" << endl; // keep? + cerr << "\theader Prints BAM header information" << endl; + cerr << "\tindex Generates index for BAM file" << endl; + cerr << "\tmerge Merge multiple BAM files into single file" << endl; + cerr << "\tsam Prints the BAM file in SAM (text) format" << endl; + cerr << "\tsort Sorts the BAM file according to some criteria" << endl; + cerr << "\tstats Prints some basic statistics from the input BAM file" << endl; cerr << endl; cerr << "See 'bamtools help COMMAND' for more information on a specific command." << endl; cerr << endl; diff --git a/bamtools_coverage.h b/bamtools_coverage.h index 083728a..dcb8e23 100644 --- a/bamtools_coverage.h +++ b/bamtools_coverage.h @@ -24,8 +24,9 @@ namespace BamTools { int BamCoverageHelp(void) { std::cerr << std::endl; - std::cerr << "usage:\tbamtools coverage [--in BAM file]" << std::endl; - std::cerr << "\t-i, --in\tInput BAM file to generate coverage stats\t[default=stdin]" << std::endl; + std::cerr << "usage:\tbamtools coverage [--in FILE]" << std::endl; + std::cerr << std::endl; + std::cerr << "\t--in FILE Input BAM file to generate coverage stats [stdin]" << std::endl; std::cerr << std::endl; return 0; } @@ -36,7 +37,7 @@ int RunBamCoverage(int argc, char* argv[]) { GetOpt options(argc, argv, 1); std::string inputFilename; - options.addOption('i', "in", &inputFilename); + options.addOption("in", &inputFilename); if ( !options.parse() ) return BamCoverageHelp(); if ( inputFilename.empty() ) { inputFilename = "stdin"; } diff --git a/bamtools_dump.h b/bamtools_dump.h index 108caf2..aac5ba1 100644 --- a/bamtools_dump.h +++ b/bamtools_dump.h @@ -27,8 +27,9 @@ namespace BamTools { int BamDumpHelp(void) { std::cerr << std::endl; - std::cerr << "usage:\tbamtools dump [BAM file1] [BAM file2] [BAM file3]..." << std::endl; - std::cerr << "\t[BAM file]\tInput file(s) to dump alignment summaries from [default=stdin]" << std::endl; + std::cerr << "usage:\tbamtools dump [--in FILE [FILE] [FILE] ...]" << std::endl; + std::cerr << std::endl; + std::cerr << "\t--in FILE Input file(s) to dump alignment summaries from [stdin]" << std::endl; std::cerr << std::endl; return 0; } diff --git a/bamtools_getopt.h b/bamtools_getopt.h index 99ef6e2..c3ff2d8 100644 --- a/bamtools_getopt.h +++ b/bamtools_getopt.h @@ -48,6 +48,7 @@ class GetOpt { public: // add standard option with arguments ( -Wall, -O2, --type=foo ) void addOption(const char shortName, const std::string& longName, std::string* value); + void addOption(const std::string& longName, std::string* value); // add an option whose argument is optional (eg --log may default to dumping to stderr, unless a file is specified ) // must provide a default string @@ -180,6 +181,12 @@ void GetOpt::addOption(const char shortName, const std::string& longName, std::s *value = std::string(); } +// add standard option with arguments ( -Wall, -O2, --type=foo ) +inline +void GetOpt::addOption(const std::string& longName, std::string* value) { + addOption(0, longName, value); +} + // add an option whose argument is optional (eg --log may default to dumping to stderr, unless a file is specified ) // must provide a default string // short & long name version @@ -548,4 +555,4 @@ void GetOpt::setSwitch(const Option& opt) { } // namespace BamTools -#endif // BAMTOOLS_GETOPT_H \ No newline at end of file +#endif // BAMTOOLS_GETOPT_H diff --git a/bamtools_header.h b/bamtools_header.h index f0544bb..ccace59 100644 --- a/bamtools_header.h +++ b/bamtools_header.h @@ -25,8 +25,9 @@ namespace BamTools { int BamHeaderHelp(void) { std::cerr << std::endl; - std::cerr << "usage:\tbamtools header [BAM file1] [BAM file2] [BAM file3]..." << std::endl; - std::cerr << "\t[BAM file]\tInput file(s) to dump header contents from [default=stdin]" << std::endl; + std::cerr << "usage:\tbamtools header [--in FILE [FILE] [FILE] ...]" << std::endl; + std::cerr << std::endl; + std::cerr << "\t--in FILE Input file(s) to dump header contents from [stdin]" << std::endl; std::cerr << std::endl; return 0; } diff --git a/bamtools_index.h b/bamtools_index.h index 1f9b4c8..5c0a1b2 100644 --- a/bamtools_index.h +++ b/bamtools_index.h @@ -22,9 +22,10 @@ namespace BamTools { int BamIndexHelp(void) { std::cerr << std::endl; - std::cerr << "usage:\tbamtools index [--nclist] " << std::endl; - std::cerr << "\t--nclist\tUse NCList indexing scheme (faster?)\t[default=off] ** JUST HERE AS POSSIBLE SWITCH EXAMPLE FOR NOW **" << std::endl; - std::cerr << "\t\tInput BAM file to generate index from\t[req'd]" << std::endl; + std::cerr << "usage:\tbamtools index [--nclist] FILE" << std::endl; + std::cerr << std::endl; + std::cerr << "\t--nclist Use NCList indexing scheme (faster?) [off] ** JUST HERE AS POSSIBLE SWITCH EXAMPLE FOR NOW **" << std::endl; + std::cerr << "\tFILE Input BAM file to generate index from [REQUIRED]" << std::endl; std::cerr << std::endl; return 0; } diff --git a/bamtools_merge.h b/bamtools_merge.h index 699f2d3..1f9be70 100644 --- a/bamtools_merge.h +++ b/bamtools_merge.h @@ -27,9 +27,12 @@ namespace BamTools { int BamMergeHelp(void) { std::cerr << std::endl; - std::cerr << "usage:\tbamtools merge [--out FILE] --in [BAM file2] [BAM file3]..." << std::endl; - std::cerr << "\t--in\tInput BAM file(s)\t\t[at least 1 req'd]" << std::endl; - std::cerr << "\t--out\tDestination for merge results\t[default=stdout]" << std::endl; + std::cerr << "usage:\tbamtools merge [--out FILE] [--region REGION] [--in FILE [FILE] [FILE] ...] " << std::endl; + std::cerr << std::endl; + std::cerr << "\t--in FILE Input BAM file(s) [stdin]" << std::endl; + std::cerr << "\t--region REGION Only keep alignments from this region. [all alignments]" << std::endl; + std::cerr << "\t REGION format - (eg chr2:1000..2000)" << std::endl; + std::cerr << "\t--out FILE Destination for merge results [stdout]" << std::endl; std::cerr << std::endl; return 0; } @@ -43,12 +46,16 @@ int RunBamMerge(int argc, char* argv[]) { GetOpt options(argc, argv, 1); std::string outputFilename = ""; - options.addOption('o', "out", &outputFilename); + options.addOption("out", &outputFilename); std::vector inputFilenames; options.addVariableLengthOption("in", &inputFilenames); + std::string regionString; + options.addOption("region", ®ionString); + if ( !options.parse() || inputFilenames.empty() ) return BamMergeHelp(); + if ( inputFilenames.empty() ) { inputFilenames.push_back("stdin"); } if ( outputFilename.empty() ) { outputFilename = "stdout"; } // opens the BAM files without checking for indexes @@ -63,12 +70,20 @@ int RunBamMerge(int argc, char* argv[]) { BamWriter writer; writer.Open(outputFilename, mergedHeader, references); - // store alignments to output file - BamAlignment bAlignment; - while (reader.GetNextAlignment(bAlignment)) { - writer.SaveAlignment(bAlignment); + // if desired region provided + if ( !regionString.empty() ) { + // parse region string + // only get alignments from this region + } + + // else get all alignments + else { + // store alignments to output file + BamAlignment bAlignment; + while (reader.GetNextAlignment(bAlignment)) { + writer.SaveAlignment(bAlignment); + } } - // clean & exit reader.Close(); writer.Close(); diff --git a/bamtools_sam.h b/bamtools_sam.h index 6bb3809..b3fd0ef 100644 --- a/bamtools_sam.h +++ b/bamtools_sam.h @@ -27,13 +27,14 @@ int BamSamHelp(void) { // do we want to add a region specifier, eg 'chr2:1000..1500'? In this case, '--num' still makes sense (give me up to N alignments from this region) std::cerr << std::endl; - std::cerr << "usage:\tbamtools sam [--in BAM file] [--num N] [--no_header]" << std::endl; - std::cerr << "\t-i, --in\tInput BAM file to generate SAM-format\t\t\t[default=stdin]" << std::endl; - std::cerr << "\t-n, --num N\tOnly print up to N alignments from beginning of file\t\t[default=50*]" << endl; - std::cerr << "\t--no_header\tOmits SAM header information from output (alignments only)\t[default=off]" << std::endl; + std::cerr << "usage:\tbamtools sam [--in FILE] [--num N] [--no_header]" << std::endl; std::cerr << std::endl; - std::cerr << "* - By default bamtools sam will print all alignments in SAM format." << std::endl; - std::cerr << " However if '-n' or '--num' is included with no N, the default of 50 is used." << std::endl; + std::cerr << "\t--in FILE Input BAM file to generate SAM-format [stdin]" << std::endl; + std::cerr << "\t--num N Only print up to N alignments from beginning of file [50*]" << endl; + std::cerr << "\t--no_header Omits SAM header information from output (alignments only) [off]" << std::endl; + std::cerr << std::endl; + std::cerr << "\t* - By default bamtools sam will print all alignments in SAM format." << std::endl; + std::cerr << "\t However if '--num' is included with no N, the default of 50 is used." << std::endl; std::cerr << std::endl; return 0; } @@ -86,10 +87,10 @@ int RunBamSam(int argc, char* argv[]) { GetOpt options(argc, argv, 1); std::string inputFilename; - options.addOption('i', "in", &inputFilename); + options.addOption("in", &inputFilename); std::string numberString; - options.addOptionalOption('n', "num", &numberString, "50"); + options.addOptionalOption("num", &numberString, "50"); bool isOmittingHeader; options.addSwitch("no_header", &isOmittingHeader); @@ -98,8 +99,8 @@ int RunBamSam(int argc, char* argv[]) { if ( inputFilename.empty() ) { inputFilename = "stdin"; } // maxNumberOfAlignments = all (if nothing specified) - // = 50 (if '-n' or '--num' but no N) - // = N (if '-n N' or '--num N') + // = 50 (if '--num' but no N) + // = N (if '--num N') int maxNumberOfAlignments = -1; if ( !numberString.empty() ) { maxNumberOfAlignments = atoi(numberString.c_str()); } diff --git a/bamtools_sort.h b/bamtools_sort.h index 18e435f..e69a0b9 100644 --- a/bamtools_sort.h +++ b/bamtools_sort.h @@ -21,9 +21,10 @@ namespace BamTools { int BamSortHelp(void) { std::cerr << std::endl; - std::cerr << "usage:\tbamtools sort [--in BAM file] [--out sorted BAM file]" << std::endl; - std::cerr << "\t-i, --in\tInput BAM file to sort\t[default=stdin]" << std::endl; - std::cerr << "\t-o. --out\tDestination of sorted BAM file\t[default=stdout]" << std::endl; + std::cerr << "usage:\tbamtools sort [--in FILE] [--out FILE]" << std::endl; + std::cerr << std::endl; + std::cerr << "\t--in FILE Input BAM file to sort [stdin]" << std::endl; + std::cerr << "\t--out FILE Destination of sorted BAM file [stdout]" << std::endl; std::cerr << std::endl; return 0; } @@ -34,10 +35,10 @@ int RunBamSort(int argc, char* argv[]) { GetOpt options(argc, argv, 1); std::string inputFilename; - options.addOption('i', "in", &inputFilename); + options.addOption("in", &inputFilename); std::string outputFilename; - options.addOption('o', "out", &outputFilename); + options.addOption("out", &outputFilename); if ( !options.parse() ) return BamCoverageHelp(); if ( inputFilename.empty() ) { inputFilename = "stdin"; } diff --git a/bamtools_stats.h b/bamtools_stats.h index fb991a2..4cbfedd 100644 --- a/bamtools_stats.h +++ b/bamtools_stats.h @@ -24,8 +24,9 @@ namespace BamTools { int BamStatsHelp(void) { std::cerr << std::endl; - std::cerr << "usage:\tbamtools stats [--in BAM file]" << std::endl; - std::cerr << "\t-i, --in\tInput BAM file to calculate general stats\t[default=stdin]" << std::endl; + std::cerr << "usage:\tbamtools stats [--in FILE]" << std::endl; + std::cerr << std::endl; + std::cerr << "\t--in FILE Input BAM file to calculate general stats [stdin]" << std::endl; std::cerr << std::endl; return 0; } @@ -36,7 +37,7 @@ int RunBamStats(int argc, char* argv[]) { GetOpt options(argc, argv, 1); std::string inputFilename; - options.addOption('t', "inp", &inputFilename); + options.addOption("in", &inputFilename); if ( !options.parse() ) return BamStatsHelp(); if ( inputFilename.empty() ) { inputFilename = "stdin"; } -- 2.39.2