PROG= bamtools\r
API= BGZF.o BamReader.o BamWriter.o BamMultiReader.o
UTILS= bamtools_options.o bamtools_utilities.o
-TOOLKIT= bamtools_count.o bamtools_coverage.o bamtools_filter.o bamtools_header.o bamtools_index.o bamtools_merge.o bamtools_sam.o bamtools_sort.o bamtools_stats.o
+TOOLKIT= bamtools_convert.o bamtools_count.o bamtools_coverage.o bamtools_filter.o bamtools_header.o bamtools_index.o bamtools_merge.o bamtools_sam.o bamtools_sort.o bamtools_stats.o
MAIN= bamtools.o
OBJS= $(API) $(UTILS) $(TOOLKIT) $(MAIN)
LIBS= -lz
usage: bamtools [--help] COMMAND [ARGS]
Available bamtools commands:
- count Prints number of alignments in BAM file
- coverage Prints coverage statistics from the input BAM file
- filter Filters BAM file(s) by user-specified criteria
- header Prints BAM header information
- index Generates index for BAM file
- merge Merge multiple BAM files into single file
- sam Prints the BAM file in SAM (text) format
- sort Sorts the BAM file according to some criteria
- stats Prints some basic statistics from the input BAM file
+ convert Converts between BAM and a number of other formats
+ count Prints number of alignments in BAM file
+ coverage Prints coverage statistics from the input BAM file
+ filter Filters BAM file(s) by user-specified criteria
+ header Prints BAM header information
+ index Generates index for BAM file
+ merge Merge multiple BAM files into single file
+ sam Prints the BAM file in SAM (text) format
+ sort Sorts the BAM file according to some criteria
+ stats Prints some basic statistics from the input BAM file
See 'bamtools help COMMAND' for more information on a specific command.
#include <iostream>
// BamTools includes
+#include "bamtools_convert.h"
#include "bamtools_count.h"
#include "bamtools_coverage.h"
#include "bamtools_filter.h"
// ------------------------------------------
// bamtools subtool names
+static const string CONVERT = "convert";
static const string COUNT = "count";
static const string COVERAGE = "coverage";
static const string FILTER = "filter";
if (argc > 2) {
AbstractTool* tool(0);
+ if ( argv[2] == CONVERT ) tool = new ConvertTool;
if ( argv[2] == COUNT ) tool = new CountTool;
if ( argv[2] == COVERAGE ) tool = new CoverageTool;
if ( argv[2] == FILTER ) tool = new FilterTool;
cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl;
cerr << endl;
cerr << "Available bamtools commands:" << endl;
+ cerr << "\tconvert Converts between BAM and a number of other formats" << endl;
cerr << "\tcount Prints number of alignments in BAM file" << endl;
cerr << "\tcoverage Prints coverage statistics from the input BAM file" << endl;
cerr << "\tfilter Filters BAM file(s) by user-specified criteria" << endl;
// determine desired sub-tool
AbstractTool* tool(0);
+ if ( argv[1] == CONVERT ) tool = new ConvertTool;
if ( argv[1] == COUNT ) tool = new CountTool;
if ( argv[1] == COVERAGE ) tool = new CoverageTool;
if ( argv[1] == FILTER ) tool = new FilterTool;
--- /dev/null
+// ***************************************************************************
+// bamtools_convert.cpp (c) 2010 Derek Barnett, Erik Garrison
+// Marth Lab, Department of Biology, Boston College
+// All rights reserved.
+// ---------------------------------------------------------------------------
+// Last modified: 2 June 2010
+// ---------------------------------------------------------------------------
+// Converts between BAM and a number of other formats
+// ***************************************************************************
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "bamtools_convert.h"
+#include "bamtools_options.h"
+#include "BamReader.h"
+#include "BamMultiReader.h"
+
+using namespace std;
+using namespace BamTools;
+
+// ---------------------------------------------
+// ConvertSettings implementation
+
+struct ConvertTool::ConvertSettings {
+
+ // flags
+ bool HasInputBamFilename;
+ bool HasOutputBamFilename;
+ bool HasFormat;
+
+ // filenames
+ string InputFilename;
+ string OutputFilename;
+ string Format;
+
+ // constructor
+ ConvertSettings(void)
+ : HasInputBamFilename(false)
+ , HasOutputBamFilename(false)
+ , OutputFilename(Options::StandardOut())
+ { }
+};
+
+// ---------------------------------------------
+// ConvertTool implementation
+
+ConvertTool::ConvertTool(void)
+ : AbstractTool()
+ , m_settings(new ConvertSettings)
+{
+ // set program details
+ Options::SetProgramInfo("bamtools convert", "converts between BAM and a number of other formats)", "-in <filename> [-in <filename> ... ] -out <filename> -format FORMAT");
+
+ // set up options
+ OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output");
+ Options::AddValueOption("-in", "BAM filename", "the input BAM file(s)", "", m_settings->HasInputBamFilename, m_settings->InputFilename, IO_Opts, Options::StandardIn());
+ Options::AddValueOption("-out", "BAM filename", "the output BAM file", "", m_settings->HasOutputBamFilename, m_settings->OutputFilename, IO_Opts, Options::StandardOut());
+ Options::AddValueOption("-format", "FORMAT", "the output file format - see README for recognized formats", "", m_settings->HasFormat, m_settings->Format, IO_Opts);
+}
+
+ConvertTool::~ConvertTool(void) {
+ delete m_settings;
+ m_settings = 0;
+}
+
+int ConvertTool::Help(void) {
+ Options::DisplayHelp();
+ return 0;
+}
+
+int ConvertTool::Run(int argc, char* argv[]) {
+
+ // parse command line arguments
+ Options::Parse(argc, argv, 1);
+
+ // open files
+ BamReader reader;
+ reader.Open(m_settings->InputFilename, false);
+
+ // do conversion
+
+ // clean up & exit
+ reader.Close();
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+// ***************************************************************************
+// bamtools_convert.h (c) 2010 Derek Barnett, Erik Garrison
+// Marth Lab, Department of Biology, Boston College
+// All rights reserved.
+// ---------------------------------------------------------------------------
+// Last modified: 2 June 2010
+// ---------------------------------------------------------------------------
+// Converts between BAM and a number of other formats
+// ***************************************************************************
+
+#ifndef BAMTOOLS_CONVERT_H
+#define BAMTOOLS_CONVERT_H
+
+#include "bamtools_tool.h"
+
+namespace BamTools {
+
+class ConvertTool : public AbstractTool {
+
+ public:
+ ConvertTool(void);
+ ~ConvertTool(void);
+
+ public:
+ int Help(void);
+ int Run(int argc, char* argv[]);
+
+ private:
+ struct ConvertSettings;
+ ConvertSettings* m_settings;
+};
+
+} // namespace BamTools
+
+#endif // BAMTOOLS_CONVERT_H
\ No newline at end of file