From 6e245391fc8edbc9bd529e0d6f04cac4742ac393 Mon Sep 17 00:00:00 2001 From: Thomas Krannich <krannich479@googlemail.com> Date: Tue, 15 Mar 2022 15:17:39 +0100 Subject: [PATCH] initial change to see if SAM/BAM headers are modified --- Makefile | 2 +- src/popins2_merge_and_set_mate.h | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b5e8591..9f4ba8e 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ TOOLS=-DSAMTOOLS=\"$(SAMTOOLS)\" -DBWA=\"$(BWA)\" -DSICKLE=\"$(SICKLE)\" -DVELVE # Date and version number from git DATE := on $(shell git log --pretty=format:"%cd" --date=iso | cut -f 1,2 -d " " | head -n 1) -VERSION := 0.0.4-snake-$(shell git log --pretty=format:"%h" --date=iso | head -n 1) +VERSION := 0.0.5-snake-$(shell git log --pretty=format:"%h" --date=iso | head -n 1) CXXFLAGS += -DDATE=\""$(DATE)"\" -DVERSION=\""$(VERSION)"\" # Compiler flags diff --git a/src/popins2_merge_and_set_mate.h b/src/popins2_merge_and_set_mate.h index 588e8c4..7205ff2 100644 --- a/src/popins2_merge_and_set_mate.h +++ b/src/popins2_merge_and_set_mate.h @@ -101,6 +101,7 @@ inline void readRecordAndCorrectRIds(BamAlignmentRecord & record, BamFileIn & st // ========================================================================== inline void mergeHeaders(BamHeader & header, FormattedFileContext<BamFileOut, Owner<> >::Type & context, BamFileIn & stream1, BamFileIn & stream2){ + StringSet<CharString> contigNames; NameStoreCache<StringSet<CharString> > nameStoreCache; String<int32_t> contigLengths; @@ -109,11 +110,35 @@ inline void mergeHeaders(BamHeader & header, FormattedFileContext<BamFileOut, Ow readHeader(header, stream1); BamHeader header2; readHeader(header2, stream2); - for (unsigned i = 0; i < length(header2); ++i) - { - if (header2[i].type != BAM_HEADER_FIRST) + + std::unordered_set<char*> program_ids; + + for (unsigned i = 0; i < length(header2); ++i){ + + if (header2[i].type != BAM_HEADER_FIRST){ + + if (header2[i].type == BAM_HEADER_PROGRAM){ + CharString PG_ID; + bool keyFound = getTagValue(PG_ID, "ID", header2[i]); + + if ( program_ids.find(toCString(PG_ID)) != program_ids.end() ){ // if PG ID was seen already + BamHeaderRecord hrecord = header2[i]; + CharString suf = ".mH"; // mH = "mergeHeader" to trace in SAM/BAM files + append(PG_ID, suf); + setTagValue("ID", PG_ID, hrecord); + appendValue(header, hrecord); + continue; + } + else{ + program_ids.insert(toCString(PG_ID)); + } + + } + appendValue(header, header2[i]); + } } + std::stable_sort(begin(header, Standard()), end(header, Standard()), BamHeaderRecordTypeLess()); // Fill sequence names into nameStoreCache. -- GitLab