From 068dde7671416b6b1bf7bffaf93a60691e23e8f9 Mon Sep 17 00:00:00 2001 From: mgymrek Date: Sun, 10 Apr 2016 14:52:56 -0400 Subject: [PATCH] Adding filename to stored read group ID --- src/ReadContainer.cpp | 2 ++ src/api/internal/BamMultiReader_p.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ReadContainer.cpp b/src/ReadContainer.cpp index 8490b38..dff855f 100644 --- a/src/ReadContainer.cpp +++ b/src/ReadContainer.cpp @@ -205,6 +205,8 @@ bool ReadContainer::ParseRead(const BamTools::BamAlignment& aln, msg << aln.Name << " Could not get read group."; PrintMessageDieOnError(msg.str(), ERROR); } + dummy_aligned_read.read_group += "-" + aln.Filename; // Keep track of read group as - + // *** Alignment filters (these don't depend on which STR aligned to) *** // if (dummy_aligned_read.mapq > max_mapq) { filter_counter.increment(FilterCounter::MAPPING_QUALITY); diff --git a/src/api/internal/BamMultiReader_p.cpp b/src/api/internal/BamMultiReader_p.cpp index 55ae615..c62d04c 100644 --- a/src/api/internal/BamMultiReader_p.cpp +++ b/src/api/internal/BamMultiReader_p.cpp @@ -228,6 +228,13 @@ string BamMultiReaderPrivate::GetHeaderText(void) const { if ( reader == 0 ) return string(); SamHeader mergedHeader = reader->GetHeader(); + // Add filename to read ID name so we know + // which file it came from + for (SamReadGroupIterator it = mergedHeader.ReadGroups.Begin(); + it != mergedHeader.ReadGroups.End(); it++) { + it->ID = it->ID + "-" + reader->GetFilename(); + } + // iterate over any remaining readers (skipping the first) for ( size_t i = 1; i < numReaders; ++i ) { const MergeItem& item = m_readers.at(i); @@ -235,7 +242,14 @@ string BamMultiReaderPrivate::GetHeaderText(void) const { if ( reader == 0 ) continue; // retrieve current reader's header - const SamHeader currentHeader = reader->GetHeader(); + SamHeader currentHeader = reader->GetHeader(); + + // Add filename to read ID name so we know + // which file it came from + for (SamReadGroupIterator it = currentHeader.ReadGroups.Begin(); + it != currentHeader.ReadGroups.End(); it++) { + it->ID = it->ID + "-" + reader->GetFilename(); + } // append current reader's RG entries to merged header // N.B. - SamReadGroupDictionary handles duplicate-checking