Skip to content

set_tags() can't handle byte-array auxiliary tags #406

@dpryan79

Description

@dpryan79

This is originally from biostars. If you try to set_tags() using a byte array then the following error is produced:

Traceback (most recent call last):
  File "./foo.py", line 9, in <module>
    read.set_tags(tags)
  File "pysam/libcalignedsegment.pyx", line 2113, in pysam.libcalignedsegment.AlignedSegment.set_tags (pysam/libcalignedsegment.c:23066)
  File "pysam/libcalignedsegment.pyx", line 295, in pysam.libcalignedsegment.packTags (pysam/libcalignedsegment.c:6217)
ValueError: invalid value type 'B' (<type 'str'>)

I'm attaching a very very small BAM file (it and the index are in the zip file) that can produce this error with the following code:

#!/usr/bin/env python
import pysam

bam = pysam.AlignmentFile("small.bam")
for read in bam.fetch():
    tags = read.get_tags(with_value_type=True)
    read.set_tags(tags)

I've tried earlier version (back to 0.8.4) and none of these are able to handle this sort of situation.

example.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions