Skip to content

Commit

Permalink
fix: mapped header records should overwrite unmapped in ZipperBams
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Jan 30, 2024
1 parent afa634e commit a7873a0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/scala/com/fulcrumgenomics/bam/ZipperBams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ private[bam] object ZipperBams extends LazyLogging {
// Build a new header using the given sequence dictionary
val header = new SAMFileHeader(dict)


// Copy over comments, RGs and PGs, letting mapped override unmapped if there are conflicts
Iterator(unmapped, mapped).foreach { old =>
old.getComments.iterator().foreach(header.addComment)
old.getReadGroups.iterator().foreach(header.addReadGroup)
old.getProgramRecords.iterator().foreach(header.addProgramRecord)
}
val mappedComments = mapped.getComments.toSet
val mappedReadGroups = mapped.getReadGroups.toSet
val mappedProgramRecords = mapped.getProgramRecords.toSet
unmapped.getComments.filterNot(mappedComments.contains).foreach(header.addComment)
unmapped.getReadGroups.filterNot(mappedReadGroups.contains).foreach(header.addReadGroup)
unmapped.getProgramRecords.filterNot(mappedProgramRecords.contains).foreach(header.addProgramRecord)
mapped.getComments.foreach(header.addComment)
mapped.getReadGroups.foreach(header.addReadGroup)
mapped.getProgramRecords.foreach(header.addProgramRecord)

// Set the sort and group order
header.setSortOrder(unmapped.getSortOrder)
Expand Down

0 comments on commit a7873a0

Please sign in to comment.