--- /dev/null
+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.
+
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;
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;
}
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"; }
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;
}
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
*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
} // namespace BamTools
-#endif // BAMTOOLS_GETOPT_H
\ No newline at end of file
+#endif // BAMTOOLS_GETOPT_H
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;
}
int BamIndexHelp(void) {
std::cerr << std::endl;
- std::cerr << "usage:\tbamtools index [--nclist] <BAM file>" << 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<BAM file>\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;
}
int BamMergeHelp(void) {
std::cerr << std::endl;
- std::cerr << "usage:\tbamtools merge [--out FILE] --in <BAM file1> [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;
}
GetOpt options(argc, argv, 1);
std::string outputFilename = "";
- options.addOption('o', "out", &outputFilename);
+ options.addOption("out", &outputFilename);
std::vector<std::string> 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
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();
// 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;
}
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);
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()); }
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;
}
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"; }
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;
}
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"; }