From: Derek Date: Thu, 3 Jun 2010 20:02:51 +0000 (-0400) Subject: Added ConvertTool.h/cpp. Not yet implemented. X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ab184573bd40b8358cc3f6b306423c187f1a24a4;p=bamtools.git Added ConvertTool.h/cpp. Not yet implemented. --- diff --git a/Makefile b/Makefile index 996dc9d..ee9be97 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CXXFLAGS= -Wall -O3 PROG= bamtools 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 diff --git a/README b/README index d71ac8e..b3bc1ea 100644 --- a/README +++ b/README @@ -47,15 +47,16 @@ of features we hope you find useful. 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. diff --git a/bamtools.cpp b/bamtools.cpp index 7bd8b20..1dc16d1 100644 --- a/bamtools.cpp +++ b/bamtools.cpp @@ -12,6 +12,7 @@ #include // BamTools includes +#include "bamtools_convert.h" #include "bamtools_count.h" #include "bamtools_coverage.h" #include "bamtools_filter.h" @@ -27,6 +28,7 @@ using namespace BamTools; // ------------------------------------------ // bamtools subtool names +static const string CONVERT = "convert"; static const string COUNT = "count"; static const string COVERAGE = "coverage"; static const string FILTER = "filter"; @@ -55,6 +57,7 @@ int Help(int argc, char* argv[]) { 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; @@ -74,6 +77,7 @@ int Help(int argc, char* argv[]) { 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; @@ -116,6 +120,7 @@ int main(int argc, char* argv[]) { // 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; diff --git a/bamtools_convert.cpp b/bamtools_convert.cpp new file mode 100644 index 0000000..5c0ec03 --- /dev/null +++ b/bamtools_convert.cpp @@ -0,0 +1,87 @@ +// *************************************************************************** +// 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 +#include +#include + +#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 [-in ... ] -out -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 diff --git a/bamtools_convert.h b/bamtools_convert.h new file mode 100644 index 0000000..8595dab --- /dev/null +++ b/bamtools_convert.h @@ -0,0 +1,35 @@ +// *************************************************************************** +// 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