X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2FSamFormatPrinter_p.cpp;h=f9a118e5c9d5f6eb8e8beb96000e715c38b9c153;hb=8b4c010999a8d0c482d84bbf17c98dc4bbae02b7;hp=dcde46e23c3cfee0457cc22f4ac0a2f0ce56697d;hpb=ff5f2ec7c437660185a406d01739f42534105412;p=bamtools.git diff --git a/src/api/internal/SamFormatPrinter_p.cpp b/src/api/internal/SamFormatPrinter_p.cpp index dcde46e..f9a118e 100644 --- a/src/api/internal/SamFormatPrinter_p.cpp +++ b/src/api/internal/SamFormatPrinter_p.cpp @@ -1,16 +1,15 @@ // *************************************************************************** // SamFormatPrinter.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 23 December 2010 (DB) +// Last modified: 14 October 2011 (DB) // --------------------------------------------------------------------------- // Provides functionality for printing formatted SAM header to string // *************************************************************************** -#include -#include -#include +#include "api/SamConstants.h" +#include "api/SamHeader.h" +#include "api/internal/SamFormatPrinter_p.h" using namespace BamTools; using namespace BamTools::Internal; @@ -19,16 +18,25 @@ using namespace BamTools::Internal; #include using namespace std; +// ------------------------ +// static utility methods +// ------------------------ + +static inline +const string FormatTag(const string& tag, const string& value) { + return string(Constants::SAM_TAB + tag + Constants::SAM_COLON + value); +} + +// --------------------------------- +// SamFormatPrinter implementation +// --------------------------------- + SamFormatPrinter::SamFormatPrinter(const SamHeader& header) : m_header(header) { } SamFormatPrinter::~SamFormatPrinter(void) { } -const string SamFormatPrinter::FormatTag(const string &tag, const string &value) const { - return string(Constants::SAM_TAB + tag + Constants::SAM_COLON + value); -} - const string SamFormatPrinter::ToString(void) const { // clear out stream @@ -88,14 +96,14 @@ void SamFormatPrinter::PrintSQ(std::stringstream& out) const { if ( seq.HasChecksum() ) out << FormatTag(Constants::SAM_SQ_CHECKSUM_TAG, seq.Checksum); - // UR: - if ( seq.HasURI() ) - out << FormatTag(Constants::SAM_SQ_URI_TAG, seq.URI); - // SP: if ( seq.HasSpecies() ) out << FormatTag(Constants::SAM_SQ_SPECIES_TAG, seq.Species); + // UR: + if ( seq.HasURI() ) + out << FormatTag(Constants::SAM_SQ_URI_TAG, seq.URI); + // newline out << endl; } @@ -109,39 +117,54 @@ void SamFormatPrinter::PrintRG(std::stringstream& out) const { for ( ; rgIter != rgEnd; ++rgIter ) { const SamReadGroup& rg = (*rgIter); - // @RG ID: SM: + // @RG ID: out << Constants::SAM_RG_BEGIN_TOKEN - << FormatTag(Constants::SAM_RG_ID_TAG, rg.ID) - << FormatTag(Constants::SAM_RG_SAMPLE_TAG, rg.Sample); + << FormatTag(Constants::SAM_RG_ID_TAG, rg.ID); - // LB: - if ( rg.HasLibrary() ) - out << FormatTag(Constants::SAM_RG_LIBRARY_TAG, rg.Library); + // CN: + if ( rg.HasSequencingCenter() ) + out << FormatTag(Constants::SAM_RG_SEQCENTER_TAG, rg.SequencingCenter); // DS: if ( rg.HasDescription() ) out << FormatTag(Constants::SAM_RG_DESCRIPTION_TAG, rg.Description); - // PU: - if ( rg.HasPlatformUnit() ) - out << FormatTag(Constants::SAM_RG_PLATFORMUNIT_TAG, rg.PlatformUnit); + // DT: + if ( rg.HasProductionDate() ) + out << FormatTag(Constants::SAM_RG_PRODUCTIONDATE_TAG, rg.ProductionDate); + + // FO: + if ( rg.HasFlowOrder() ) + out << FormatTag(Constants::SAM_RG_FLOWORDER_TAG, rg.FlowOrder); + + // KS: + if ( rg.HasKeySequence() ) + out << FormatTag(Constants::SAM_RG_KEYSEQUENCE_TAG, rg.KeySequence); + + // LB: + if ( rg.HasLibrary() ) + out << FormatTag(Constants::SAM_RG_LIBRARY_TAG, rg.Library); + + // PG: + if ( rg.HasProgram() ) + out << FormatTag(Constants::SAM_RG_PROGRAM_TAG, rg.Program); // PI: if ( rg.HasPredictedInsertSize() ) out << FormatTag(Constants::SAM_RG_PREDICTEDINSERTSIZE_TAG, rg.PredictedInsertSize); - // CN: - if ( rg.HasSequencingCenter() ) - out << FormatTag(Constants::SAM_RG_SEQCENTER_TAG, rg.SequencingCenter); - - // DT: - if ( rg.HasProductionDate() ) - out << FormatTag(Constants::SAM_RG_PRODUCTIONDATE_TAG, rg.ProductionDate); - // PL: if ( rg.HasSequencingTechnology() ) out << FormatTag(Constants::SAM_RG_SEQTECHNOLOGY_TAG, rg.SequencingTechnology); + // PU: + if ( rg.HasPlatformUnit() ) + out << FormatTag(Constants::SAM_RG_PLATFORMUNIT_TAG, rg.PlatformUnit); + + // SM: + if ( rg.HasSample() ) + out << FormatTag(Constants::SAM_RG_SAMPLE_TAG, rg.Sample); + // newline out << endl; } @@ -149,20 +172,31 @@ void SamFormatPrinter::PrintRG(std::stringstream& out) const { void SamFormatPrinter::PrintPG(std::stringstream& out) const { - // if header has @PG data - if ( m_header.HasProgramName() ) { + // iterate over program record entries + SamProgramConstIterator pgIter = m_header.Programs.ConstBegin(); + SamProgramConstIterator pgEnd = m_header.Programs.ConstEnd(); + for ( ; pgIter != pgEnd; ++pgIter ) { + const SamProgram& pg = (*pgIter); - // @PG ID: + // @PG ID: out << Constants::SAM_PG_BEGIN_TOKEN - << FormatTag(Constants::SAM_PG_NAME_TAG, m_header.ProgramName); + << FormatTag(Constants::SAM_PG_ID_TAG, pg.ID); + + // PN: + if ( pg.HasName() ) + out << FormatTag(Constants::SAM_PG_NAME_TAG, pg.Name); + + // CL: + if ( pg.HasCommandLine() ) + out << FormatTag(Constants::SAM_PG_COMMANDLINE_TAG, pg.CommandLine); - // VN: - if ( m_header.HasProgramVersion() ) - out << FormatTag(Constants::SAM_PG_VERSION_TAG, m_header.ProgramVersion); + // PP: + if ( pg.HasPreviousProgramID() ) + out << FormatTag(Constants::SAM_PG_PREVIOUSPROGRAM_TAG, pg.PreviousProgramID); - // CL: - if ( m_header.HasProgramCommandLine() ) - out << FormatTag(Constants::SAM_PG_COMMANDLINE_TAG, m_header.ProgramCommandLine); + // VN: + if ( pg.HasVersion() ) + out << FormatTag(Constants::SAM_PG_VERSION_TAG, pg.Version); // newline out << endl;