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

Test for equality of FastxRecord #1243

Open clintval opened 9 months ago

clintval commented 9 months ago

I'd like to be able to test for equality of FastxRecord in unit tests. But it appears whatever equality function is implemented currently doesn't work and may be testing for identity instead?

>>> from pysam import FastxRecord
>>> FastxRecord(name="test") == FastxRecord(name="test")
False

If this was not an intentional design decision, would you be open to a PR to fix this?

jmarshall commented 9 months ago

There is no __eq__ method defined, so we just get the default object equivalence which is just is.

I think adding one would be a worthwhile addition. (OTOH defining an ordering on FastxRecords wouldn't be particularly meaningful so __lt__ etc probably wouldn't be as good an idea.)

clintval commented 9 months ago

Got i! I also noticed copy.copy() and copy.deepcopy() may not be working as expected on these objects despite dunder methods. And a few typos in the docs too for FastxFile such as a reference to "samfile" and an entry for FastqProxy but not FastxRecord. I'll try to send up a few PRs when I get a chance!

jmarshall commented 9 months ago

Thanks, that'd be great. I recently discovered that missing class documentation entries are due to missing autoclass entries (see #407 comments).