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
// 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"
// 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";
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;
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;
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;
--- /dev/null
+// ***************************************************************************
+// 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
--- /dev/null
+// ***************************************************************************
+// 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