From eb97bf5f91acd9a1ce2964e60a79fecffd9f6d72 Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 3 Jun 2010 15:27:02 -0400 Subject: [PATCH] Added FilterTool.h/cpp. Not yet implemented. --- Makefile | 7 ++-- bamtools.cpp | 5 +++ bamtools_filter.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++ bamtools_filter.h | 36 ++++++++++++++++++ 4 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 bamtools_filter.cpp create mode 100644 bamtools_filter.h diff --git a/Makefile b/Makefile index 280ab48..996dc9d 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,15 @@ 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_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 all: $(PROG) -bamtools: $(API) $(UTILS) $(TOOLKIT) $(MAIN) - $(CXX) $(CXXFLAGS) -o $@ $(API) $(UTILS) $(TOOLKIT) $(MAIN) $(LIBS) +bamtools: $(OBJS) + $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) clean: rm -fr gmon.out *.o *.a a.out *~ diff --git a/bamtools.cpp b/bamtools.cpp index b5ba6e0..7bd8b20 100644 --- a/bamtools.cpp +++ b/bamtools.cpp @@ -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 index 0000000..2249022 --- /dev/null +++ b/bamtools_filter.cpp @@ -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 +#include +#include + +#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 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 [-in ... ] -out "); + + // 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 index 0000000..fe8728b --- /dev/null +++ b/bamtools_filter.h @@ -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 -- 2.39.5