]> git.donarmstrong.com Git - bamtools.git/commitdiff
Added ConvertTool.h/cpp. Not yet implemented.
authorDerek <derekwbarnett@gmail.com>
Thu, 3 Jun 2010 20:02:51 +0000 (16:02 -0400)
committerDerek <derekwbarnett@gmail.com>
Thu, 3 Jun 2010 20:02:51 +0000 (16:02 -0400)
Makefile
README
bamtools.cpp
bamtools_convert.cpp [new file with mode: 0644]
bamtools_convert.h [new file with mode: 0644]

index 996dc9d4b634f45db18328f48fd97bbeec83f6d8..ee9be979bc288de3d54a3f6571543ef833bcd51c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ CXXFLAGS=       -Wall -O3
 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
diff --git a/README b/README
index d71ac8e8e3d3f79e2e18937a6e252accc441f594..b3bc1eaa16a01a8e420178772247a200fc92bf1d 100644 (file)
--- 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.
 
index 7bd8b2054ac11e742a8c1a688fc6684952890904..1dc16d1c0c1976a943ebb07a80bc9c9242b46ed3 100644 (file)
@@ -12,6 +12,7 @@
 #include <iostream>
 
 // 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 (file)
index 0000000..5c0ec03
--- /dev/null
@@ -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 <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
diff --git a/bamtools_convert.h b/bamtools_convert.h
new file mode 100644 (file)
index 0000000..8595dab
--- /dev/null
@@ -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