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
773 stars 274 forks source link

Add AlignedSegment.__repr__ #1267

Open marcelm opened 6 months ago

marcelm commented 6 months ago

Before:

<pysam.libcalignedsegment.AlignedSegment object at 0x7fd74c3ae2c0>

After:

<AlignedSegment('name', flags=16, ref='chr1', pos=1170070, mapq=255, cigar='50M', ...)>

I’ve used pysam with this patch for a while and find it very valuable when looking at AlignedSegments in a debugger or the REPL.

I’ve chosen to include only the (from my perspective) most important attributes so that the output doesn’t become too long, in particular when there’s a list with AlignedSegments.

The angle brackets are supposed to convey that the string cannot be passed to eval() to recreate the object. I’d be fine with removing them.