]> git.donarmstrong.com Git - bamtools.git/blob - bamtools_convert.cpp
Fixed typo in settings config.
[bamtools.git] / bamtools_convert.cpp
1 // ***************************************************************************
2 // bamtools_convert.cpp (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 2 June 2010
7 // ---------------------------------------------------------------------------
8 // Converts between BAM and a number of other formats
9 // ***************************************************************************
10
11 #include <iostream>
12 #include <string>
13 #include <vector>
14
15 #include "bamtools_convert.h"
16 #include "bamtools_format.h"
17 #include "bamtools_options.h"
18 #include "BamReader.h"
19 #include "BamMultiReader.h"
20
21 using namespace std;
22 using namespace BamTools;
23   
24 // ---------------------------------------------
25 // ConvertSettings implementation
26
27 struct ConvertTool::ConvertSettings {
28
29     // flags
30     bool HasInputBamFilename;
31     bool HasOutputBamFilename;
32     bool HasFormat;
33
34     // filenames
35     string InputFilename;
36     string OutputFilename;
37     string Format;
38     
39     // constructor
40     ConvertSettings(void)
41         : HasInputBamFilename(false)
42         , HasOutputBamFilename(false)
43         , InputFilename(Options::StandardIn())
44         , OutputFilename(Options::StandardOut())
45     { } 
46 };  
47
48 // ---------------------------------------------
49 // ConvertTool implementation
50
51 ConvertTool::ConvertTool(void)
52     : AbstractTool()
53     , m_settings(new ConvertSettings)
54 {
55     // set program details
56     Options::SetProgramInfo("bamtools convert", "converts between BAM and a number of other formats", "-in <filename> -out <filename> -format <FORMAT>");
57     
58     // set up options 
59     OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output");
60     Options::AddValueOption("-in",     "BAM filename", "the input BAM file(s)", "", m_settings->HasInputBamFilename,  m_settings->InputFilename,  IO_Opts, Options::StandardIn());
61     Options::AddValueOption("-out",    "BAM filename", "the output BAM file",   "", m_settings->HasOutputBamFilename, m_settings->OutputFilename, IO_Opts, Options::StandardOut());
62     Options::AddValueOption("-format", "FORMAT", "the output file format - see README for recognized formats", "", m_settings->HasFormat, m_settings->Format, IO_Opts);
63 }
64
65 ConvertTool::~ConvertTool(void) {
66     delete m_settings;
67     m_settings = 0;
68 }
69
70 int ConvertTool::Help(void) {
71     Options::DisplayHelp();
72     return 0;
73 }
74
75 int ConvertTool::Run(int argc, char* argv[]) {
76   
77     // parse command line arguments
78     Options::Parse(argc, argv, 1);
79     
80     // open files
81     BamReader reader;
82     reader.Open(m_settings->InputFilename);
83         
84     // do conversion
85     
86     
87     
88     
89     // clean up & exit
90     reader.Close();
91     return 0;
92 }