1 // ***************************************************************************
2 // bamtools_index.cpp (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 7 July 2010
7 // ---------------------------------------------------------------------------
8 // Creates a BAM index (".bai") file for the provided BAM file.
9 // ***************************************************************************
14 #include "bamtools_index.h"
15 #include "bamtools_options.h"
16 #include "BamReader.h"
19 using namespace BamTools;
21 // ---------------------------------------------
22 // IndexSettings implementation
24 struct IndexTool::IndexSettings {
27 bool HasInputBamFilename;
28 bool IsUsingBamtoolsIndex;
31 string InputBamFilename;
35 : HasInputBamFilename(false)
36 , IsUsingBamtoolsIndex(false)
37 , InputBamFilename(Options::StandardIn())
41 // ---------------------------------------------
42 // IndexTool implementation
44 IndexTool::IndexTool(void)
46 , m_settings(new IndexSettings)
48 // set program details
49 Options::SetProgramInfo("bamtools index", "creates index for BAM file", "[-in <filename>] [-bti]");
52 OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output");
53 Options::AddValueOption("-in", "BAM filename", "the input BAM file", "", m_settings->HasInputBamFilename, m_settings->InputBamFilename, IO_Opts, Options::StandardIn());
54 Options::AddOption("-bti", "use (non-standard) BamTools indexing scheme", m_settings->IsUsingBamtoolsIndex, IO_Opts);
57 IndexTool::~IndexTool(void) {
62 int IndexTool::Help(void) {
63 Options::DisplayHelp();
67 int IndexTool::Run(int argc, char* argv[]) {
69 // parse command line arguments
70 Options::Parse(argc, argv, 1);
72 // open our BAM reader
74 reader.Open(m_settings->InputBamFilename);
76 // create index for BAM file
77 bool useDefaultIndex = !m_settings->IsUsingBamtoolsIndex;
78 reader.CreateIndex(useDefaultIndex);