// Marth Lab, Department of Biology, Boston College\r
// All rights reserved.\r
// ---------------------------------------------------------------------------\r
-// Last modified: 21 July 2010 (DB)\r
+// Last modified: 22 July 2010 (DB)\r
// ---------------------------------------------------------------------------\r
// Provides the basic constants, data structures, etc. for using BAM files\r
// ***************************************************************************\r
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 20 July 2010
+// Last modified: 22 July 2010
// ---------------------------------------------------------------------------
// Integrates a number of BamTools functionalities into a single executable.
// ***************************************************************************
#include "bamtools_index.h"
#include "bamtools_merge.h"
#include "bamtools_random.h"
-// #include "bamtools_sam.h"
#include "bamtools_sort.h"
#include "bamtools_stats.h"
static const string INDEX = "index";
static const string MERGE = "merge";
static const string RANDOM = "random";
-// static const string SAM = "sam";
static const string SORT = "sort";
static const string STATS = "stats";
if ( argv[2] == INDEX ) tool = new IndexTool;
if ( argv[2] == MERGE ) tool = new MergeTool;
if ( argv[2] == RANDOM ) tool = new RandomTool;
-// if ( argv[2] == SAM ) tool = new SamTool;
if ( argv[2] == SORT ) tool = new SortTool;
if ( argv[2] == STATS ) tool = new StatsTool;
cerr << "\tindex Generates index for BAM file" << endl;
cerr << "\tmerge Merge multiple BAM files into single file" << endl;
cerr << "\trandom Grab a random subset of alignments" << endl;
-// cerr << "\tsam Prints the BAM file in SAM (text) format" << endl;
cerr << "\tsort Sorts the BAM file according to some criteria" << endl;
cerr << "\tstats Prints some basic statistics from the input BAM file" << endl;
cerr << endl;
if ( argv[1] == INDEX ) tool = new IndexTool;
if ( argv[1] == MERGE ) tool = new MergeTool;
if ( argv[1] == RANDOM ) tool = new RandomTool;
-// if ( argv[1] == SAM ) tool = new SamTool;
if ( argv[1] == SORT ) tool = new SortTool;
if ( argv[1] == STATS ) tool = new StatsTool;
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 9 July 2010
+// Last modified: 22 July 2010
// ---------------------------------------------------------------------------
// Converts between BAM and a number of other formats
// ***************************************************************************
// pileup flags
bool HasFastaFilename;
+ bool IsOmittingSamHeader;
bool IsPrintingPileupMapQualities;
// options
, HasFormat(false)
, HasRegion(false)
, HasFastaFilename(false)
+ , IsOmittingSamHeader(false)
, IsPrintingPileupMapQualities(false)
, OutputFilename(Options::StandardOut())
{ }
OptionGroup* PileupOpts = Options::CreateOptionGroup("Pileup Options");
Options::AddValueOption("-fasta", "FASTA filename", "FASTA reference file", "", m_settings->HasFastaFilename, m_settings->FastaFilename, PileupOpts, "");
Options::AddOption("-mapqual", "print the mapping qualities", m_settings->IsPrintingPileupMapQualities, PileupOpts);
+
+ OptionGroup* SamOpts = Options::CreateOptionGroup("SAM Options");
+ Options::AddOption("-noheader", "omit the SAM header from output", m_settings->IsOmittingSamHeader, SamOpts);
}
ConvertTool::~ConvertTool(void) {
// open input files
BamMultiReader reader;
- reader.Open(m_settings->InputFiles);
+ reader.Open(m_settings->InputFiles, false);
m_references = reader.GetReferenceData();
// set region if specified
convertedOk = false;
}
+ // if SAM format & not omitting header, print SAM header
+ if ( (m_settings->Format == FORMAT_SAM) && !m_settings->IsOmittingSamHeader ) {
+ string headerText = reader.GetHeaderText();
+ m_out << headerText;
+ }
+
// ------------------------
// do conversion
if ( !formatError ) {
size_t index = 0;
while ( index < tagDataLength ) {
- // write tag name
- m_out << "\t" << a.TagData.substr(index, 2) << ":";
+ // write tag name
+ string tagName = a.TagData.substr(index, 2);
+ m_out << "\t" << tagName << ":";
index += 2;
// get data type
char type = a.TagData.at(index);
++index;
-
switch (type) {
case('A') :
m_out << "A:" << tagData[index];
break;
case('S') :
- m_out << "i:" << BgzfData::UnpackUnsignedShort(&tagData[index]);
+ m_out << "i:" << BgzfData::UnpackUnsignedShort(&tagData[index]);
index += 2;
break;
case('Z') :
case('H') :
- m_out << type << ":";
+ m_out << type << ":";
while (tagData[index]) {
m_out << tagData[index];
++index;