]> git.donarmstrong.com Git - bamtools.git/blob - bamtools_index.cpp
added warning for duplicate @RG tag in header
[bamtools.git] / bamtools_index.cpp
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: 26 May 2010
7 // ---------------------------------------------------------------------------
8 // Creates a BAM index (".bai") file for the provided BAM file.
9 // ***************************************************************************
10
11 #include <iostream>
12 #include <string>
13
14 #include "bamtools_index.h"
15 #include "bamtools_options.h"
16 #include "BamReader.h"
17
18 using namespace std;
19 using namespace BamTools;
20
21 // ---------------------------------------------
22 // IndexSettings implementation
23
24 struct IndexTool::IndexSettings {
25
26     // flags
27     bool HasInputBamFilename;
28
29     // filenames
30     string InputBamFilename;
31     
32     // constructor
33     IndexSettings(void)
34         : HasInputBamFilename(false)
35         , InputBamFilename(Options::StandardIn())
36     { }
37 };  
38
39 // ---------------------------------------------
40 // IndexTool implementation
41
42 IndexTool::IndexTool(void)
43     : AbstractTool()
44     , m_settings(new IndexSettings)
45 {
46     // set program details
47     Options::SetProgramInfo("bamtools index", "creates index for BAM file", "-in <filename>");
48     
49     // set up options 
50     OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output");
51     Options::AddValueOption("-in", "BAM filename", "the input BAM file", "", m_settings->HasInputBamFilename, m_settings->InputBamFilename, IO_Opts, Options::StandardIn());
52 }
53
54 IndexTool::~IndexTool(void) {
55     delete m_settings;
56     m_settings = 0;
57 }
58
59 int IndexTool::Help(void) {
60     Options::DisplayHelp();
61     return 0;
62 }
63
64 int IndexTool::Run(int argc, char* argv[]) {
65   
66     // parse command line arguments
67     Options::Parse(argc, argv, 1);
68     
69     // open our BAM reader
70     BamReader reader;
71     reader.Open(m_settings->InputBamFilename);
72     
73     // create index for BAM file
74     reader.CreateIndex();
75     
76     // clean & exit
77     reader.Close();
78     return 0;
79 }