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

Add HTSFile.seek(..., whence) parameter & clarify libc. vs io.SEEK_SET #1212

Closed jmarshall closed 1 year ago

jmarshall commented 1 year ago

DEF is deprecated in Cython 3, so we revisit the SEEK_* definitions in libchtslib.pyx. In fact pysam should not be defining these at all:

Hence remove the DEFs and clarify which functions use libc.SEEK* and which use io.SEEK*. Convert between the two where necessary.

While we're here, add an optional whence parameter to HTSFile.seek(). Note that some of the underlying APIs may not accept any value other than SEEK_SET. Fixes #1185.

Also fix buglet in HFile.close(): hclose() reports any error encountered in errno, as there's no longer an hFILE to call herrno() on (moreover here self.fp is already NULL).