AlignedSegment.set_tag(): validate Hex values for tag type 'H' #1366
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.
Added validation for values in Hex format tags, using regular expression defined in the SAM specification.
Currently,
set_tag()does not perform any validation of the tag value for Hex format tags (wherevalue_type(typecode) is'H'). This means thatpysamallows writing reads to a SAM/BAM file that may result in errors when trying to read that same read viapysam.AlignmentFile.fetch().Specifically,
pysam.AlignmentFile.fetch()(via ... viapysam.AlignmentFile.cnext()viasam.c:sam_read1()via ... viasam.c:aux_parse()in htslib) checks that Hex format tag values contain an even number of characters.pysam/htslib/sam.c
Lines 2835 to 2839 in 2f9d50d
Therefore, the proposed patch (which follows the SAM specification) for the write side of the
pysaminterface will be a bit stricter than what the read side checks for. Nonetheless, this helps ensure round-trip compatibility of reads written by pysam.