pysam-developers / pysam

Pysam is a Python package for reading, manipulating, and writing genomics data such as SAM/BAM/CRAM and VCF/BCF files. It's a lightweight wrapper of the HTSlib API, the same one that powers samtools, bcftools, and tabix.
https://pysam.readthedocs.io/en/latest/
MIT License
782 stars 274 forks source link

Trying to add tags to an insilico AlignedSegment results in error #1304

Open blex-max opened 2 months ago

blex-max commented 2 months ago

from the doc:

    a = pysam.AlignedSegment()
    ...
    a.tags = (("NM", 1),
              ("RG", "L1"))

my code:

    r = pysam.AlignedSegment()
    ...
    r.tags = (('MC', '10M'))

Type Checker says:

Cannot assign to attribute "tags" for class "AlignedSegment"
Attribute "tags" is unknown

and running the code gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nfs/users/nfs_a/ab63/dev/core-hairpin-py/test_validate_read.py", line 17, in test_validate_read
    r.tags = (('MC', '10M'))
    ^^^^^^
  File "pysam/libcalignedsegment.pyx", line 2874, in pysam.libcalignedsegment.AlignedSegment.tags.__set__
  File "pysam/libcalignedsegment.pyx", line 2678, in pysam.libcalignedsegment.AlignedSegment.set_tags
  File "pysam/libcalignedsegment.pyx", line 411, in pysam.libcalignedsegment.pack_tags
KeyError: 77

pysam==0.22.1

Thanks for any help, and for maintaining pysam!

blex-max commented 2 months ago

r.set_tag(...) works, but it's unfortunate that the documented method does not