]> git.donarmstrong.com Git - bamtools.git/commitdiff
Added FilterTool.h/cpp. Not yet implemented.
authorDerek <derekwbarnett@gmail.com>
Thu, 3 Jun 2010 19:27:02 +0000 (15:27 -0400)
committerDerek <derekwbarnett@gmail.com>
Thu, 3 Jun 2010 19:27:02 +0000 (15:27 -0400)
Makefile
bamtools.cpp
bamtools_filter.cpp [new file with mode: 0644]
bamtools_filter.h [new file with mode: 0644]

index 280ab48895870ce8be5c399142673ceb4177413a..996dc9d4b634f45db18328f48fd97bbeec83f6d8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,14 +3,15 @@ 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_header.o bamtools_index.o bamtools_merge.o bamtools_sam.o bamtools_sort.o bamtools_stats.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
 MAIN=          bamtools.o
+OBJS=          $(API) $(UTILS) $(TOOLKIT) $(MAIN)
 LIBS=          -lz
 \r
 all: $(PROG)\r
 \r
-bamtools: $(API) $(UTILS) $(TOOLKIT) $(MAIN)\r
-       $(CXX) $(CXXFLAGS) -o $@ $(API) $(UTILS) $(TOOLKIT) $(MAIN) $(LIBS)\r
+bamtools: $(OBJS)\r
+       $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS)\r
 \r
 clean:\r
        rm -fr gmon.out *.o *.a a.out *~\r
index b5ba6e0a7b00f083ddd3d3866bdb242e70fd6aa4..7bd8b2054ac11e742a8c1a688fc6684952890904 100644 (file)
@@ -14,6 +14,7 @@
 // BamTools includes
 #include "bamtools_count.h"
 #include "bamtools_coverage.h"
+#include "bamtools_filter.h"
 #include "bamtools_header.h"
 #include "bamtools_index.h"
 #include "bamtools_merge.h"
@@ -28,6 +29,7 @@ using namespace BamTools;
 // bamtools subtool names
 static const string COUNT    = "count";
 static const string COVERAGE = "coverage";
+static const string FILTER   = "filter";
 static const string HEADER   = "header";
 static const string INDEX    = "index";
 static const string MERGE    = "merge";
@@ -55,6 +57,7 @@ int Help(int argc, char* argv[]) {
         AbstractTool* tool(0);
         if ( argv[2] == COUNT )    tool = new CountTool;
         if ( argv[2] == COVERAGE ) tool = new CoverageTool;
+        if ( argv[2] == FILTER )   tool = new FilterTool;
         if ( argv[2] == HEADER )   tool = new HeaderTool;
         if ( argv[2] == INDEX )    tool = new IndexTool;
         if ( argv[2] == MERGE )    tool = new MergeTool;
@@ -73,6 +76,7 @@ int Help(int argc, char* argv[]) {
     cerr << "Available bamtools commands:" << 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;
     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;
@@ -114,6 +118,7 @@ int main(int argc, char* argv[]) {
     AbstractTool* tool(0);
     if ( argv[1] == COUNT )    tool = new CountTool;
     if ( argv[1] == COVERAGE ) tool = new CoverageTool;
+    if ( argv[1] == FILTER )   tool = new FilterTool;
     if ( argv[1] == HEADER )   tool = new HeaderTool;
     if ( argv[1] == INDEX )    tool = new IndexTool;
     if ( argv[1] == MERGE )    tool = new MergeTool;
diff --git a/bamtools_filter.cpp b/bamtools_filter.cpp
new file mode 100644 (file)
index 0000000..2249022
--- /dev/null
@@ -0,0 +1,89 @@
+// ***************************************************************************
+// bamtools_filter.cpp (c) 2010 Derek Barnett, Erik Garrison
+// Marth Lab, Department of Biology, Boston College
+// All rights reserved.
+// ---------------------------------------------------------------------------
+// Last modified: 1 June 2010
+// ---------------------------------------------------------------------------
+// Filters a single BAM file (or filters multiple BAM files and merges) 
+// according to some user-specified criteria.
+// ***************************************************************************
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "bamtools_filter.h"
+#include "bamtools_options.h"
+#include "BamReader.h"
+#include "BamMultiReader.h"
+
+using namespace std;
+using namespace BamTools; 
+  
+// ---------------------------------------------
+// FilterSettings implementation
+
+struct FilterTool::FilterSettings {
+
+    // flags
+    bool HasInputBamFilename;
+    bool HasOutputBamFilename;
+
+    // filenames
+    vector<string> InputFiles;
+    string OutputFilename;
+    
+    // constructor
+    FilterSettings(void)
+        : HasInputBamFilename(false)
+        , HasOutputBamFilename(false)
+        , OutputFilename(Options::StandardOut())
+    { }
+};  
+
+// ---------------------------------------------
+// FilterTool implementation
+
+FilterTool::FilterTool(void)
+    : AbstractTool()
+    , m_settings(new FilterSettings)
+{
+    // set program details
+    Options::SetProgramInfo("bamtools filter", "filters BAM file(s)", "-in <filename> [-in <filename> ... ] -out <filename> ");
+    
+    // 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->InputFiles,     IO_Opts, Options::StandardIn());
+    Options::AddValueOption("-out", "BAM filename", "the output BAM file",   "", m_settings->HasOutputBamFilename, m_settings->OutputFilename, IO_Opts, Options::StandardOut());
+}
+
+FilterTool::~FilterTool(void) {
+    delete m_settings;
+    m_settings = 0;
+}
+
+int FilterTool::Help(void) {
+    Options::DisplayHelp();
+    return 0;
+}
+
+int FilterTool::Run(int argc, char* argv[]) {
+  
+    // parse command line arguments
+    Options::Parse(argc, argv, 1);
+  
+    // set to default input if none provided
+    if ( !m_settings->HasInputBamFilename ) 
+        m_settings->InputFiles.push_back(Options::StandardIn());
+    
+    // open files
+    BamMultiReader reader;
+    reader.Open(m_settings->InputFiles, false);
+        
+    // do filtering
+    
+    // clean up & exit
+    reader.Close();
+    return 0;
+}
\ No newline at end of file
diff --git a/bamtools_filter.h b/bamtools_filter.h
new file mode 100644 (file)
index 0000000..fe8728b
--- /dev/null
@@ -0,0 +1,36 @@
+// ***************************************************************************
+// bamtools_filter.h (c) 2010 Derek Barnett, Erik Garrison
+// Marth Lab, Department of Biology, Boston College
+// All rights reserved.
+// ---------------------------------------------------------------------------
+// Last modified: 2 June 2010
+// ---------------------------------------------------------------------------
+// Filters a single BAM file (or filters multiple BAM files and merges) 
+// according to some user-specified criteria.
+// ***************************************************************************
+
+#ifndef BAMTOOLS_FILTER_H
+#define BAMTOOLS_FILTER_H
+
+#include "bamtools_tool.h"
+
+namespace BamTools {
+  
+class FilterTool : public AbstractTool {
+  
+    public:
+        FilterTool(void);
+        ~FilterTool(void);
+  
+    public:
+        int Help(void);
+        int Run(int argc, char* argv[]); 
+        
+    private:
+        struct FilterSettings;
+        FilterSettings* m_settings;
+};
+  
+} // namespace BamTools
+
+#endif // BAMTOOLS_FILTER_H