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: 23 September 2010
7 // ---------------------------------------------------------------------------
8 // Converts between BAM and a number of other formats
9 // ***************************************************************************
16 #include "bamtools_convert.h"
17 #include "bamtools_fasta.h"
18 #include "bamtools_options.h"
19 #include "bamtools_pileup_engine.h"
20 #include "bamtools_utilities.h"
22 #include "BamMultiReader.h"
24 using namespace BamTools;
28 // ---------------------------------------------
29 // ConvertTool constants
31 // supported conversion format command-line names
32 static const string FORMAT_BED = "bed";
33 static const string FORMAT_BEDGRAPH = "bedgraph";
34 static const string FORMAT_FASTA = "fasta";
35 static const string FORMAT_FASTQ = "fastq";
36 static const string FORMAT_JSON = "json";
37 static const string FORMAT_YAML = "yaml";
38 static const string FORMAT_SAM = "sam";
39 static const string FORMAT_PILEUP = "pileup";
40 static const string FORMAT_WIGGLE = "wig";
43 static const unsigned int FASTA_LINE_MAX = 50;
45 // ---------------------------------------------
46 // ConvertPileupFormatVisitor declaration
48 class ConvertPileupFormatVisitor : public PileupVisitor {
52 ConvertPileupFormatVisitor(const RefVector& references,
53 const string& fastaFilename,
54 const bool isPrintingMapQualities,
56 ~ConvertPileupFormatVisitor(void);
58 // PileupVisitor interface implementation
60 void Visit(const PileupPosition& pileupData);
66 bool m_isPrintingMapQualities;
68 RefVector m_references;
71 } // namespace BamTools
73 // ---------------------------------------------
74 // ConvertSettings implementation
76 struct ConvertTool::ConvertSettings {
85 bool HasFastaFilename;
86 bool IsOmittingSamHeader;
87 bool IsPrintingPileupMapQualities;
90 vector<string> InputFiles;
91 string OutputFilename;
104 , HasFastaFilename(false)
105 , IsOmittingSamHeader(false)
106 , IsPrintingPileupMapQualities(false)
107 , OutputFilename(Options::StandardOut())
112 // ---------------------------------------------
113 // ConvertToolPrivate implementation
115 struct ConvertTool::ConvertToolPrivate {
119 ConvertToolPrivate(ConvertTool::ConvertSettings* settings);
120 ~ConvertToolPrivate(void);
128 void PrintBed(const BamAlignment& a);
129 void PrintBedGraph(const BamAlignment& a);
130 void PrintFasta(const BamAlignment& a);
131 void PrintFastq(const BamAlignment& a);
132 void PrintJson(const BamAlignment& a);
133 void PrintYaml(const BamAlignment& a);
134 void PrintSam(const BamAlignment& a);
135 void PrintWiggle(const BamAlignment& a);
137 // special case - uses the PileupEngine
138 bool RunPileupConversion(BamMultiReader* reader);
142 ConvertTool::ConvertSettings* m_settings;
143 RefVector m_references;
147 ConvertTool::ConvertToolPrivate::ConvertToolPrivate(ConvertTool::ConvertSettings* settings)
148 : m_settings(settings)
149 , m_out(cout.rdbuf()) // default output to cout
152 ConvertTool::ConvertToolPrivate::~ConvertToolPrivate(void) { }
154 bool ConvertTool::ConvertToolPrivate::Run(void) {
156 // ------------------------------------
157 // initialize conversion input/output
159 // set to default input if none provided
160 if ( !m_settings->HasInput )
161 m_settings->InputFiles.push_back(Options::StandardIn());
164 BamMultiReader reader;
165 reader.Open(m_settings->InputFiles);
166 m_references = reader.GetReferenceData();
168 // set region if specified
170 if ( m_settings->HasRegion ) {
171 if ( Utilities::ParseRegionString(m_settings->Region, reader, region) ) {
172 if ( !reader.SetRegion(region) ) {
173 cerr << "Could not set BamReader region to REGION: " << m_settings->Region << endl;
177 cerr << "Could not parse REGION: " << m_settings->Region << endl;
182 // if output file given
184 if ( m_settings->HasOutput ) {
186 // open output file stream
187 outFile.open(m_settings->OutputFilename.c_str());
189 cerr << "Could not open " << m_settings->OutputFilename << " for output" << endl;
193 // set m_out to file's streambuf
194 m_out.rdbuf(outFile.rdbuf());
197 // -------------------------------------
198 // do conversion based on format
200 bool convertedOk = true;
202 // pileup is special case
203 // conversion not done per alignment, like the other formats
204 if ( m_settings->Format == FORMAT_PILEUP )
205 convertedOk = RunPileupConversion(&reader);
210 bool formatError = false;
212 // set function pointer to proper conversion method
213 void (BamTools::ConvertTool::ConvertToolPrivate::*pFunction)(const BamAlignment&) = 0;
214 if ( m_settings->Format == FORMAT_BED ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintBed;
215 else if ( m_settings->Format == FORMAT_BEDGRAPH ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintBedGraph;
216 else if ( m_settings->Format == FORMAT_FASTA ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintFasta;
217 else if ( m_settings->Format == FORMAT_FASTQ ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintFastq;
218 else if ( m_settings->Format == FORMAT_JSON ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintJson;
219 else if ( m_settings->Format == FORMAT_YAML ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintYaml;
220 else if ( m_settings->Format == FORMAT_SAM ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintSam;
221 else if ( m_settings->Format == FORMAT_WIGGLE ) pFunction = &BamTools::ConvertTool::ConvertToolPrivate::PrintWiggle;
223 cerr << "Unrecognized format: " << m_settings->Format << endl;
224 cerr << "Please see help|README (?) for details on supported formats " << endl;
229 // if format selected ok
230 if ( !formatError ) {
232 // if SAM format & not omitting header, print SAM header first
233 if ( (m_settings->Format == FORMAT_SAM) && !m_settings->IsOmittingSamHeader )
234 m_out << reader.GetHeaderText();
236 // iterate through file, doing conversion
238 while ( reader.GetNextAlignment(a) )
239 (this->*pFunction)(a);
241 // set flag for successful conversion
246 // ------------------------
250 if ( m_settings->HasOutput ) outFile.close();
254 // ----------------------------------------------------------
255 // Conversion/output methods
256 // ----------------------------------------------------------
258 void ConvertTool::ConvertToolPrivate::PrintBed(const BamAlignment& a) {
260 // tab-delimited, 0-based half-open
261 // (e.g. a 50-base read aligned to pos 10 could have BED coordinates (10, 60) instead of BAM coordinates (10, 59) )
262 // <chromName> <chromStart> <chromEnd> <readName> <score> <strand>
264 m_out << m_references.at(a.RefID).RefName << "\t"
265 << a.Position << "\t"
266 << a.GetEndPosition() + 1 << "\t"
268 << a.MapQuality << "\t"
269 << (a.IsReverseStrand() ? "-" : "+") << endl;
272 void ConvertTool::ConvertToolPrivate::PrintBedGraph(const BamAlignment& a) {
276 // print BamAlignment in FASTA format
277 // N.B. - uses QueryBases NOT AlignedBases
278 void ConvertTool::ConvertToolPrivate::PrintFasta(const BamAlignment& a) {
280 // >BamAlignment.Name
281 // BamAlignment.QueryBases (up to FASTA_LINE_MAX bases per line)
284 // N.B. - QueryBases are reverse-complemented if aligned to reverse strand
287 m_out << "> " << a.Name << endl;
289 // handle reverse strand alignment - bases
290 string sequence = a.QueryBases;
291 if ( a.IsReverseStrand() )
292 Utilities::ReverseComplement(sequence);
294 // if sequence fits on single line
295 if ( sequence.length() <= FASTA_LINE_MAX )
296 m_out << sequence << endl;
298 // else split over multiple lines
302 size_t seqLength = sequence.length(); // handle reverse strand alignment - bases & qualitiesth();
304 // write subsequences to each line
305 while ( position < (seqLength - FASTA_LINE_MAX) ) {
306 m_out << sequence.substr(position, FASTA_LINE_MAX) << endl;
307 position += FASTA_LINE_MAX;
310 // write final subsequence
311 m_out << sequence.substr(position) << endl;
315 // print BamAlignment in FASTQ format
316 // N.B. - uses QueryBases NOT AlignedBases
317 void ConvertTool::ConvertToolPrivate::PrintFastq(const BamAlignment& a) {
319 // @BamAlignment.Name
320 // BamAlignment.QueryBases
322 // BamAlignment.Qualities
324 // N.B. - QueryBases are reverse-complemented (& Qualities reversed) if aligned to reverse strand .
325 // Name is appended "/1" or "/2" if paired-end, to reflect which mate this entry is.
327 // handle paired-end alignments
328 string name = a.Name;
330 name.append( (a.IsFirstMate() ? "/1" : "/2") );
332 // handle reverse strand alignment - bases & qualities
333 string qualities = a.Qualities;
334 string sequence = a.QueryBases;
335 if ( a.IsReverseStrand() ) {
336 Utilities::Reverse(qualities);
337 Utilities::ReverseComplement(sequence);
340 // write to output stream
341 m_out << "@" << name << endl
344 << qualities << endl;
347 // print BamAlignment in JSON format
348 void ConvertTool::ConvertToolPrivate::PrintJson(const BamAlignment& a) {
350 // write name & alignment flag
351 m_out << "{\"name\":\"" << a.Name << "\",\"alignmentFlag\":\"" << a.AlignmentFlag << "\",";
353 // write reference name
354 if ( (a.RefID >= 0) && (a.RefID < (int)m_references.size()) )
355 m_out << "\"reference\":\"" << m_references[a.RefID].RefName << "\",";
357 // write position & map quality
358 m_out << "\"position\":" << a.Position+1 << ",\"mapQuality\":" << a.MapQuality << ",";
361 const vector<CigarOp>& cigarData = a.CigarData;
362 if ( !cigarData.empty() ) {
363 m_out << "\"cigar\":[";
364 vector<CigarOp>::const_iterator cigarBegin = cigarData.begin();
365 vector<CigarOp>::const_iterator cigarIter = cigarBegin;
366 vector<CigarOp>::const_iterator cigarEnd = cigarData.end();
367 for ( ; cigarIter != cigarEnd; ++cigarIter ) {
368 const CigarOp& op = (*cigarIter);
369 if (cigarIter != cigarBegin) m_out << ",";
370 m_out << "\"" << op.Length << op.Type << "\"";
375 // write mate reference name, mate position, & insert size
376 if ( a.IsPaired() && (a.MateRefID >= 0) && (a.MateRefID < (int)m_references.size()) ) {
377 m_out << "\"mate\":{"
378 << "\"reference\":\"" << m_references[a.MateRefID].RefName << "\","
379 << "\"position\":" << a.MatePosition+1
380 << ",\"insertSize\":" << a.InsertSize << "},";
384 if ( !a.QueryBases.empty() )
385 m_out << "\"queryBases\":\"" << a.QueryBases << "\",";
388 if ( !a.Qualities.empty() ) {
389 string::const_iterator s = a.Qualities.begin();
390 m_out << "\"qualities\":[" << static_cast<short>(*s) - 33;
392 for (; s != a.Qualities.end(); ++s) {
393 m_out << "," << static_cast<short>(*s) - 33;
399 const char* tagData = a.TagData.c_str();
400 const size_t tagDataLength = a.TagData.length();
402 if (index < tagDataLength) {
404 m_out << "\"tags\":{";
406 while ( index < tagDataLength ) {
412 m_out << "\"" << a.TagData.substr(index, 2) << "\":";
416 char type = a.TagData.at(index);
421 m_out << "\"" << tagData[index] << "\"";
426 m_out << (int)tagData[index];
431 m_out << (int)tagData[index];
436 m_out << BgzfData::UnpackUnsignedShort(&tagData[index]);
441 m_out << BgzfData::UnpackSignedShort(&tagData[index]);
446 m_out << BgzfData::UnpackUnsignedInt(&tagData[index]);
451 m_out << BgzfData::UnpackSignedInt(&tagData[index]);
456 m_out << BgzfData::UnpackFloat(&tagData[index]);
461 m_out << BgzfData::UnpackDouble(&tagData[index]);
468 while (tagData[index]) {
469 m_out << tagData[index];
477 if ( tagData[index] == '\0')
484 m_out << "}" << endl;
488 // Print BamAlignment in YAML format
489 void ConvertTool::ConvertToolPrivate::PrintYaml(const BamAlignment& a) {
492 // write alignment name
493 m_out << "---" << endl;
494 m_out << a.Name << ":" << endl;
496 // write alignment data
497 m_out << " " << "AlndBases: " << a.AlignedBases << endl;
498 m_out << " " << "Qualities: " << a.Qualities << endl;
499 m_out << " " << "Name: " << a.Name << endl;
500 m_out << " " << "Length: " << a.Length << endl;
501 m_out << " " << "TagData: " << a.TagData << endl;
502 m_out << " " << "RefID: " << a.RefID << endl;
503 m_out << " " << "RefName: " << m_references[a.RefID].RefName << endl;
504 m_out << " " << "Position: " << a.Position << endl;
505 m_out << " " << "Bin: " << a.Bin << endl;
506 m_out << " " << "MapQuality: " << a.MapQuality << endl;
507 m_out << " " << "AlignmentFlag: " << a.AlignmentFlag << endl;
508 m_out << " " << "MateRefID: " << a.MateRefID << endl;
509 m_out << " " << "MatePosition: " << a.MatePosition << endl;
510 m_out << " " << "InsertSize: " << a.InsertSize << endl;
513 const vector<CigarOp>& cigarData = a.CigarData;
514 if ( !cigarData.empty() ) {
515 m_out << " " << "Cigar: ";
516 vector<CigarOp>::const_iterator cigarBegin = cigarData.begin();
517 vector<CigarOp>::const_iterator cigarIter = cigarBegin;
518 vector<CigarOp>::const_iterator cigarEnd = cigarData.end();
519 for ( ; cigarIter != cigarEnd; ++cigarIter ) {
520 const CigarOp& op = (*cigarIter);
521 m_out << op.Length << op.Type;
529 // print BamAlignment in SAM format
530 void ConvertTool::ConvertToolPrivate::PrintSam(const BamAlignment& a) {
533 // <QNAME> <FLAG> <RNAME> <POS> <MAPQ> <CIGAR> <MRNM> <MPOS> <ISIZE> <SEQ> <QUAL> [ <TAG>:<VTYPE>:<VALUE> [...] ]
535 // write name & alignment flag
536 m_out << a.Name << "\t" << a.AlignmentFlag << "\t";
538 // write reference name
539 if ( (a.RefID >= 0) && (a.RefID < (int)m_references.size()) )
540 m_out << m_references[a.RefID].RefName << "\t";
544 // write position & map quality
545 m_out << a.Position+1 << "\t" << a.MapQuality << "\t";
548 const vector<CigarOp>& cigarData = a.CigarData;
549 if ( cigarData.empty() ) m_out << "*\t";
551 vector<CigarOp>::const_iterator cigarIter = cigarData.begin();
552 vector<CigarOp>::const_iterator cigarEnd = cigarData.end();
553 for ( ; cigarIter != cigarEnd; ++cigarIter ) {
554 const CigarOp& op = (*cigarIter);
555 m_out << op.Length << op.Type;
560 // write mate reference name, mate position, & insert size
561 if ( a.IsPaired() && (a.MateRefID >= 0) && (a.MateRefID < (int)m_references.size()) ) {
562 if ( a.MateRefID == a.RefID ) m_out << "=\t";
563 else m_out << m_references[a.MateRefID].RefName << "\t";
564 m_out << a.MatePosition+1 << "\t" << a.InsertSize << "\t";
566 else m_out << "*\t0\t0\t";
569 if ( a.QueryBases.empty() ) m_out << "*\t";
570 else m_out << a.QueryBases << "\t";
573 if ( a.Qualities.empty() ) m_out << "*";
574 else m_out << a.Qualities;
577 const char* tagData = a.TagData.c_str();
578 const size_t tagDataLength = a.TagData.length();
581 while ( index < tagDataLength ) {
584 string tagName = a.TagData.substr(index, 2);
585 m_out << "\t" << tagName << ":";
589 char type = a.TagData.at(index);
593 m_out << "A:" << tagData[index];
598 m_out << "i:" << (int)tagData[index];
603 m_out << "i:" << (int)tagData[index];
608 m_out << "i:" << BgzfData::UnpackUnsignedShort(&tagData[index]);
613 m_out << "i:" << BgzfData::UnpackSignedShort(&tagData[index]);
618 m_out << "i:" << BgzfData::UnpackUnsignedInt(&tagData[index]);
623 m_out << "i:" << BgzfData::UnpackSignedInt(&tagData[index]);
628 m_out << "f:" << BgzfData::UnpackFloat(&tagData[index]);
633 m_out << "d:" << BgzfData::UnpackDouble(&tagData[index]);
639 m_out << type << ":";
640 while (tagData[index]) {
641 m_out << tagData[index];
648 if ( tagData[index] == '\0')
655 void ConvertTool::ConvertToolPrivate::PrintWiggle(const BamAlignment& a) {
659 bool ConvertTool::ConvertToolPrivate::RunPileupConversion(BamMultiReader* reader) {
661 // check for valid BamMultiReader
662 if ( reader == 0 ) return false;
664 // set up our pileup format 'visitor'
665 ConvertPileupFormatVisitor* v = new ConvertPileupFormatVisitor(m_references,
666 m_settings->FastaFilename,
667 m_settings->IsPrintingPileupMapQualities,
670 // set up PileupEngine
672 pileup.AddVisitor(v);
674 // iterate through data
676 while ( reader->GetNextAlignment(al) )
677 pileup.AddAlignment(al);
688 // ---------------------------------------------
689 // ConvertTool implementation
691 ConvertTool::ConvertTool(void)
693 , m_settings(new ConvertSettings)
696 // set program details
697 Options::SetProgramInfo("bamtools convert", "converts BAM to a number of other formats", "-format <FORMAT> [-in <filename> -in <filename> ...] [-out <filename>] [other options]");
700 OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output");
701 Options::AddValueOption("-in", "BAM filename", "the input BAM file(s)", "", m_settings->HasInput, m_settings->InputFiles, IO_Opts, Options::StandardIn());
702 Options::AddValueOption("-out", "BAM filename", "the output BAM file", "", m_settings->HasOutput, m_settings->OutputFilename, IO_Opts, Options::StandardOut());
703 Options::AddValueOption("-format", "FORMAT", "the output file format - see README for recognized formats", "", m_settings->HasFormat, m_settings->Format, IO_Opts);
705 OptionGroup* FilterOpts = Options::CreateOptionGroup("Filters");
706 Options::AddValueOption("-region", "REGION", "genomic region. Index file is recommended for better performance, and is read automatically if it exists as <filename>.bai. See \'bamtools help index\' for more details on creating one", "", m_settings->HasRegion, m_settings->Region, FilterOpts);
708 OptionGroup* PileupOpts = Options::CreateOptionGroup("Pileup Options");
709 Options::AddValueOption("-fasta", "FASTA filename", "FASTA reference file", "", m_settings->HasFastaFilename, m_settings->FastaFilename, PileupOpts, "");
710 Options::AddOption("-mapqual", "print the mapping qualities", m_settings->IsPrintingPileupMapQualities, PileupOpts);
712 OptionGroup* SamOpts = Options::CreateOptionGroup("SAM Options");
713 Options::AddOption("-noheader", "omit the SAM header from output", m_settings->IsOmittingSamHeader, SamOpts);
716 ConvertTool::~ConvertTool(void) {
724 int ConvertTool::Help(void) {
725 Options::DisplayHelp();
729 int ConvertTool::Run(int argc, char* argv[]) {
731 // parse command line arguments
732 Options::Parse(argc, argv, 1);
734 // run internal ConvertTool implementation, return success/fail
735 m_impl = new ConvertToolPrivate(m_settings);
743 // ---------------------------------------------
744 // ConvertPileupFormatVisitor implementation
746 ConvertPileupFormatVisitor::ConvertPileupFormatVisitor(const RefVector& references,
747 const string& fastaFilename,
748 const bool isPrintingMapQualities,
752 , m_isPrintingMapQualities(isPrintingMapQualities)
754 , m_references(references)
756 // set up Fasta reader if file is provided
757 if ( !fastaFilename.empty() ) {
759 // check for FASTA index
760 string indexFilename = "";
761 if ( Utilities::FileExists(fastaFilename + ".fai") )
762 indexFilename = fastaFilename + ".fai";
765 if ( m_fasta.Open(fastaFilename, indexFilename) )
770 ConvertPileupFormatVisitor::~ConvertPileupFormatVisitor(void) {
771 // be sure to close Fasta reader
778 void ConvertPileupFormatVisitor::Visit(const PileupPosition& pileupData ) {
780 // skip if no alignments at this position
781 if ( pileupData.PileupAlignments.empty() ) return;
783 // retrieve reference name
784 const string& referenceName = m_references[pileupData.RefId].RefName;
785 const int& position = pileupData.Position;
787 // retrieve reference base from FASTA file, if one provided; otherwise default to 'N'
788 char referenceBase('N');
789 if ( m_hasFasta && (pileupData.Position < m_references[pileupData.RefId].RefLength) ) {
790 if ( !m_fasta.GetBase(pileupData.RefId, pileupData.Position, referenceBase ) ) {
791 cerr << "Pileup error : Could not read reference base from FASTA file" << endl;
796 // get count of alleles at this position
797 const int numberAlleles = pileupData.PileupAlignments.size();
799 // -----------------------------------------------------------
800 // build strings based on alleles at this positionInAlignment
802 stringstream bases("");
803 stringstream baseQualities("");
804 stringstream mapQualities("");
806 // iterate over alignments at this pileup position
807 vector<PileupAlignment>::const_iterator pileupIter = pileupData.PileupAlignments.begin();
808 vector<PileupAlignment>::const_iterator pileupEnd = pileupData.PileupAlignments.end();
809 for ( ; pileupIter != pileupEnd; ++pileupIter ) {
810 const PileupAlignment pa = (*pileupIter);
811 const BamAlignment& ba = pa.Alignment;
813 // if beginning of read segment
814 if ( pa.IsSegmentBegin )
815 bases << '^' << ( ((int)ba.MapQuality > 93) ? (char)126 : (char)((int)ba.MapQuality+33) );
817 // if current base is not a DELETION
818 if ( !pa.IsCurrentDeletion ) {
820 // get base at current position
821 char base = ba.QueryBases.at(pa.PositionInAlignment);
823 // if base matches reference
825 toupper(base) == toupper(referenceBase) ||
826 tolower(base) == tolower(referenceBase) )
828 base = (ba.IsReverseStrand() ? ',' : '.' );
831 // mismatches reference
832 else base = (ba.IsReverseStrand() ? tolower(base) : toupper(base) );
837 // if next position contains insertion
838 if ( pa.IsNextInsertion ) {
839 bases << '+' << pa.InsertionLength;
840 for (int i = 1; i <= pa.InsertionLength; ++i) {
841 char insertedBase = (char)ba.QueryBases.at(pa.PositionInAlignment + i);
842 bases << (ba.IsReverseStrand() ? (char)tolower(insertedBase) : (char)toupper(insertedBase) );
846 // if next position contains DELETION
847 else if ( pa.IsNextDeletion ) {
848 bases << '-' << pa.DeletionLength;
849 for (int i = 1; i <= pa.DeletionLength; ++i) {
850 char deletedBase('N');
851 if ( m_hasFasta && (pileupData.Position+i < m_references[pileupData.RefId].RefLength) ) {
852 if ( !m_fasta.GetBase(pileupData.RefId, pileupData.Position+i, deletedBase ) ) {
853 cerr << "Pileup error : Could not read reference base from FASTA file" << endl;
857 bases << (ba.IsReverseStrand() ? (char)tolower(deletedBase) : (char)toupper(deletedBase) );
862 // otherwise, DELETION
865 // if end of read segment
866 if ( pa.IsSegmentEnd ) bases << '$';
868 // store current base quality
869 baseQualities << ba.Qualities.at(pa.PositionInAlignment);
871 // save alignment map quality if desired
872 if ( m_isPrintingMapQualities )
873 mapQualities << ( ((int)ba.MapQuality > 93) ? (char)126 : (char)((int)ba.MapQuality+33) );
876 // ----------------------
880 // <refName> <1-based pos> <refBase> <numberAlleles> <bases> <qualities> [mapQuals]
882 const string TAB = "\t";
883 *m_out << referenceName << TAB
884 << position + 1 << TAB
885 << referenceBase << TAB
886 << numberAlleles << TAB
887 << bases.str() << TAB
888 << baseQualities.str() << TAB
889 << mapQualities.str() << endl;