sam: keep otherTags when adding a duplicate reference on BAM read #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where the BAM reader (via
bam.DecodeBinary
) did not preserve additional tags for reference entries in the header. If, for example, a reference had aDS:foo
tag, it would not be preserved in the final header after decoding.This occurred because the BAM format lists the references in two places: the "text" portion and a binary-encoded list of references. The reading of the binary-encoded list (in
bam.DecodeBinary
) overrode some parts of the references read via the text portion and did not preserve theotherTags
field of references that had already been read in the text portion of the header.The fix is in
sam.Header.AddReference
: when adding a reference that has already been seen, if the reference being added has a nilotherTags
, use the existing tags. This follows the pattern already used inAddReference
for themd5
,assemID
, etc. fields.