Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AlignedSegment.__repr__ #1267

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

marcelm
Copy link
Contributor

@marcelm marcelm commented Feb 13, 2024

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.

…am-developers#1267)

Example output:
<AlignedSegment('name', flags=16=0x10, ref='chr1', zpos=1170070, mapq=255, cigar='50M', ...)>

[Use an f-string; write flags in hex too; and use 'zpos' label to emphasis
this field is shown 0-based. -- JM]
@jmarshall jmarshall force-pushed the alignedsegment-repr branch from 231604d to 9a694d0 Compare October 10, 2024 10:50
@jmarshall
Copy link
Member

Thanks, I like it. I've reworked it a little to use f-strings (now that we assume Py3.6, they're available!) and label the position as zpos=… to emphasise that this field is shown 0-based.

@jmarshall jmarshall merged commit 9a694d0 into pysam-developers:master Oct 10, 2024
12 checks passed
@marcelm marcelm deleted the alignedsegment-repr branch October 10, 2024 11:14
@marcelm
Copy link
Contributor Author

marcelm commented Oct 10, 2024

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants