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

HTSlib warnings can't be suppressed? #1303

Open ohickl opened 1 month ago

ohickl commented 1 month ago

Description:

Hi,

I'm encountering a persistent warning message when working with SAM/BAM files using pysam, and I'm seeking your advice on how to suppress or resolve it.

Issue Description

When processing my SAM/BAM files with pysam, I frequently receive the following warning message:

    [W::sam_hrecs_update_hashes] PG line with multiple ID tags. The first encountered was preferred ...

I understand that this warning is generated when pysam (or the underlying htslib library) encounters multiple PG (Program) lines in the file header with the same ID tag, and that the software defaults to using the first ID it encounters. I know the reason for this in this instance and want to ignore it.

Steps I’ve Tried to Suppress the Warning

I’ve attempted several common methods to suppress or redirect this warning, including:

This approach did not suppress the warning, possibly because it's not using Python’s standard warning system.

My Questions

Any advice or guidance you can provide would be greatly appreciated. Thank you for your time and for maintaining this incredibly useful library!

Environment:

pysam version: 0.22.1
Python version: 3.12.4
Operating System: Nobara Linux 40 (KDE Plasma)

Best,

Oskar