diff --git a/Makefile b/Makefile index b5e85913e21af79124dc51cb719e717e17fea7e5..9f4ba8e6a2a50e17921fb564b2e1f8b1d9173ee2 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 588e8c41751a37943e3fe9101729c0d8d90a1aff..7205ff28dcd2fb151ed33283c67a5048e5ad6bd2 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.